Нема описа

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. return $this->hasMany('Activity')->where('activities.draft', 0)->orderBy('date', 'asc');
  30. }
  31. public function publishedActivities()
  32. {
  33. //return $this->hasMany('Activity')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->orderBy('date', 'asc');
  34. return $this->hasMany('Activity')->where('activities.draft', 0)->orderBy('date', 'asc');
  35. }
  36. public function outcomes_attempted()
  37. {
  38. return DB::table('courses')
  39. ->join('activities', 'activities.course_id', '=', 'courses.id')
  40. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  41. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  42. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  43. ->where('courses.id', '=', $this->id)
  44. ->select('criterion_objective_outcome.outcome_id')
  45. ->distinct()
  46. ->orderBy('criterion_objective_outcome.outcome_id')
  47. ->get();
  48. // 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
  49. // return $this->id;
  50. }
  51. public function outcomes_achieved()
  52. {
  53. $criteria = DB::table('criteria')
  54. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  55. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  56. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  57. ->join('rubric', 'rubric.id', '=', 'rubric_activity.rubric_id')
  58. ->join('courses', 'activities.course_id', '=', 'courses.id')
  59. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  60. ->where('courses.id', '=', $this->id)
  61. ->select(
  62. 'criteria.id',
  63. 'rubric.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
  64. 'activity_criterion.activity_id'
  65. )
  66. ->distinct()
  67. ->get();
  68. $conteo = 0;
  69. foreach ($criteria as $criterion) {
  70. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  71. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  72. if ($students_attempted) {
  73. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  74. } else {
  75. $percentage_students_who_achieved = 0;
  76. }
  77. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  78. $conteo++;
  79. }
  80. }
  81. return $conteo;
  82. }
  83. public function semester()
  84. {
  85. return $this->belongsTo('Semester');
  86. }
  87. public function sectionsWithOutcome($outcome_id)
  88. {
  89. return Course::has('activities')->with(array('activities' => function ($query) use (&$outcome_id) {
  90. $query->where('outcomes_attempted', 'not like', '\'%"' . $outcome_id . '":0%\'');
  91. }))->where('code', $this->code)->where('number', $this->number)->get();
  92. }
  93. }