Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_att()
  52. {
  53. $criteria_attempted = DB::table('courses')
  54. ->join('activities', 'activities.course_id', '=', 'courses.id')
  55. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  56. ->select('criterion_id', 'activity_criterion.id as activity_criterion_id')
  57. ->where('courses.id', $this->id)
  58. ->where('draft', 0)
  59. ->get();
  60. // Old data was formed like { "outcome1": cuantity_of_criteria_associated, "outcome2":cuantity_of_criteria}
  61. $outcomes_attempted = [];
  62. foreach ($criteria_attempted as $criterion) {
  63. $outcomes = DB::table('criterion_objective_outcome')
  64. ->where('criterion_id', $criterion->criterion_id)
  65. ->select('outcome_id')
  66. ->distinct()
  67. ->lists('outcome_id');
  68. foreach ($outcomes as $outcome_id) {
  69. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
  70. else $outcomes_attempted[$outcome_id] = 1;
  71. }
  72. }
  73. return $outcomes_attempted;
  74. }
  75. public function outcomes_ach()
  76. {
  77. $criteria = DB::table('criteria')
  78. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  79. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  80. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  81. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  82. ->join('courses', 'activities.course_id', '=', 'courses.id')
  83. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  84. ->where('courses.id', '=', $this->id)
  85. ->where('activities.draft', 0)
  86. ->select(
  87. 'criteria.id',
  88. 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
  89. 'activity_criterion.activity_id'
  90. )
  91. ->distinct()
  92. ->get();
  93. // Old data was formed like { "outcome1": cuantity_of_criteria_associated_passed, "outcome2":cuantity_of_criteria}
  94. $outcomes_achieved = [];
  95. foreach ($criteria as $criterion) {
  96. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  97. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  98. if ($students_attempted) {
  99. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  100. } else {
  101. $percentage_students_who_achieved = 0;
  102. }
  103. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  104. $outcomes = DB::table('criterion_objective_outcome')
  105. ->where('criterion_id', $criterion->id)
  106. ->select('outcome_id')
  107. ->distinct()
  108. ->lists('outcome_id');
  109. foreach ($outcomes as $outcome_id) {
  110. if (array_key_exists($outcome_id, $outcomes_achieved)) $outcomes_achieved[$outcome_id] += 1;
  111. else $outcomes_achieved[$outcome_id] = 1;
  112. }
  113. }
  114. }
  115. return $outcomes_achieved;
  116. }
  117. public function outcomes_achieved()
  118. {
  119. $criteria = DB::table('criteria')
  120. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  121. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  122. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  123. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  124. ->join('courses', 'activities.course_id', '=', 'courses.id')
  125. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  126. ->where('courses.id', '=', $this->id)
  127. ->select(
  128. 'criteria.id',
  129. 'rubrics.expected_percentage as expected_percentage_students_achieving'/*'expected_percentage_students_achieving',*/,
  130. 'activity_criterion.activity_id'
  131. )
  132. ->distinct()
  133. ->get();
  134. $conteo = 0;
  135. foreach ($criteria as $criterion) {
  136. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  137. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  138. if ($students_attempted) {
  139. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  140. } else {
  141. $percentage_students_who_achieved = 0;
  142. }
  143. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  144. $conteo++;
  145. }
  146. }
  147. return $conteo;
  148. }
  149. public function semester()
  150. {
  151. return $this->belongsTo('Semester');
  152. }
  153. public function sectionsWithOutcome($outcome_id)
  154. {
  155. return Course::has('activities')->with(array('activities' => function ($query) use (&$outcome_id) {
  156. $query->where('outcomes_attempted', 'not like', '\'%"' . $outcome_id . '":0%\'');
  157. }))->where('code', $this->code)->where('number', $this->number)->get();
  158. }
  159. }