Keine Beschreibung

Professor.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 sections() {
  16. return $this->belongsToMany(Section::class)->withPivot('percent', 'schedule', 'eval');
  17. }
  18. public function semesters() {
  19. return $this->belongsToMany(Semester::class)->withPivot('admin_load', 'investigative_load');
  20. }
  21. public function getFullNameAttribute() {
  22. return "{$this->first_name} {$this->last_name}";
  23. }
  24. // public function getSectionLoad(Section $section) {
  25. // return ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + calcExtraCredits($section->credits, $section->student_count));
  26. // }
  27. public function getAcademicLoad(Semester $semester) {
  28. $prof_sections = $this->sections->where('semester_code', '=', $semester->code);
  29. return $prof_sections->reduce(function ($carry, $section) {
  30. return $carry + ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + $section->extra_credits);
  31. }, 0);
  32. }
  33. }