123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
-
- namespace App;
-
- use Illuminate\Database\Eloquent\Model;
-
- class Professor extends Model
- {
- public $timestamps = false;
-
- protected $fillable = [
- 'num_prof',
- 'first_name',
- 'last_name',
- 'email',
- 'type',
- 'dept_id'
- ];
-
- public function department() {
- return $this->belongsTo(Department::class);
- }
-
- public function faculty() {
- return $this->department->faculty();
- }
-
- public function sections() {
- return $this->belongsToMany(Section::class)->withPivot('percent', 'schedule', 'eval');
- }
-
- public function semesters() {
- return $this->belongsToMany(Semester::class)->withPivot('admin_load', 'investigative_load', 'other');
- }
-
- public function getFullNameAttribute() {
- return "{$this->first_name} {$this->last_name}";
- }
-
- // public function getSectionLoad(Section $section) {
- // return ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + calcExtraCredits($section->credits, $section->student_count));
- // }
-
- public function getAcademicLoad(Semester $semester) {
- $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
- return $prof_sections->reduce(function ($carry, $section) {
- return $carry + (($section->pivot->percent ?? 100.0) / 100.0) * (($section->credits ?? 0.0) + $section->extra_credits);
- }, 0);
- }
-
- }
|