Aucune description

Course.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. class Course extends Eloquent
  3. {
  4. protected $fillable = array('name', 'code', 'number', 'section', 'program_id', 'user_id', 'semester_id');
  5. public function program()
  6. {
  7. return $this->belongsTo('Program');
  8. }
  9. public function students()
  10. {
  11. return $this->belongsToMany('Student')->orderBy('name', 'asc')->withTimestamps();
  12. }
  13. public function user()
  14. {
  15. return $this->belongsTo('User')->orderBy('surnames', 'asc')->orderBy('first_name', 'asc');
  16. }
  17. // TODO: Remove
  18. public function activities()
  19. {
  20. return $this->hasMany('Activity')->orderBy('date', 'asc');
  21. }
  22. public function activity()
  23. {
  24. return $this->belongsTo('Activity');
  25. }
  26. public function assessedActivities()
  27. {
  28. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->orderBy('date', 'asc');
  29. }
  30. public function publishedActivities()
  31. {
  32. return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
  33. }
  34. public function outcomes_attempted()
  35. {
  36. return DB::table('courses')
  37. ->join('activities', 'activities.course_id', '=', 'courses.id')
  38. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  39. ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  40. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  41. ->where('courses.id','=',$this->id)
  42. ->select('criterion_objective_outcome.outcome_id')
  43. ->distinct()
  44. ->orderBy('criterion_objective_outcome.outcome_id')
  45. ->get();
  46. // SELECT distinct cr.outcome_id FROM courses c, activities a, activity_criterion ac, criteria cr WHERE c.id=a.course_id and a.id=ac.activity_id and ac.criterion_id=cr.id and c.id=1
  47. // return $this->id;
  48. }
  49. public function outcomes_achieved()
  50. {
  51. $criteria=DB::table('new_criteria')
  52. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  53. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  54. ->join('courses', 'activities.course_id', '=', 'courses.id')
  55. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  56. ->where('courses.id','=',$this->id)
  57. ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  58. ->distinct()
  59. ->get()
  60. ;
  61. $conteo=0;
  62. foreach($criteria as $criterion)
  63. {
  64. $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  65. $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  66. if($students_attempted)
  67. {
  68. $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  69. }
  70. else
  71. {
  72. $percentage_students_who_achieved=0;
  73. }
  74. if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  75. {
  76. $conteo++;
  77. }
  78. }
  79. return $conteo;
  80. }
  81. public function semester()
  82. {
  83. return $this->belongsTo('Semester');
  84. }
  85. public function sectionsWithOutcome($outcome_id)
  86. {
  87. return Course::has('activities')->with(array('activities'=>function($query) use (&$outcome_id){
  88. $query->where('outcomes_attempted', 'not like', '\'%"'.$outcome_id.'":0%\'');
  89. }))->where('code',$this->code)->where('number',$this->number)->get();
  90. }
  91. }