Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Professor extends Model
  5. {
  6. public $timestamps = false;
  7. protected $fillable = [
  8. 'num_prof',
  9. 'first_name',
  10. 'last_name',
  11. 'email',
  12. 'type',
  13. 'dept_id'
  14. ];
  15. public function department() {
  16. return $this->belongsTo(Department::class);
  17. }
  18. public function faculty() {
  19. return $this->department->faculty();
  20. }
  21. public function sections() {
  22. return $this->belongsToMany(Section::class)->withPivot('percent', 'schedule', 'eval');
  23. }
  24. public function semesters() {
  25. return $this->belongsToMany(Semester::class)->withPivot('admin_load', 'investigative_load', 'other');
  26. }
  27. public function getFullNameAttribute() {
  28. return "{$this->first_name} {$this->last_name}";
  29. }
  30. // public function getSectionLoad(Section $section) {
  31. // return ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + calcExtraCredits($section->credits, $section->student_count));
  32. // }
  33. public function getAcademicLoad(Semester $semester) {
  34. $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
  35. return $prof_sections->reduce(function ($carry, $section) {
  36. return $carry + (($section->pivot->percent ?? 100.0) / 100.0) * (($section->credits ?? 0.0) + $section->extra_credits);
  37. }, 0);
  38. }
  39. }