No Description

Activity.php 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. class Activity extends Eloquent
  3. {
  4. public function section()
  5. {
  6. return $this->belongsTo('Section');
  7. }
  8. public function rubric()
  9. {
  10. // return $this->belongsTo('Rubric');
  11. return $this->belongsToMany('Rubric', 'rubric_activity');
  12. }
  13. public function course()
  14. {
  15. return $this->belongsTo('Course');
  16. }
  17. public function assessed_students()
  18. {
  19. return $this->belongsToMany('Student', 'assessments')->withPivot('scores', 'percentage')->withTimestamps();
  20. }
  21. public function amount_of_assessed_students()
  22. {
  23. $activity_criterion = DB::table('activity_criterion')->where('activity_id', '=', $this->id)->lists('id');
  24. $amount_of_students = DB::table('assessments')->whereIn('activity_criterion_id', $activity_criterion)->lists('student_id');
  25. return count($amount_of_students);
  26. }
  27. public function criteria_achieved()
  28. {
  29. $activity_criterion = DB::table('activity_criterion')
  30. ->where('activity_id', '=', $this->id)
  31. ->get();
  32. Log::info('activity_criterion');
  33. Log::info($activity_criterion);
  34. $criteria_achieved = [];
  35. foreach ($activity_criterion as $index => $single_ac) {
  36. $assessments_passed = count(DB::table('assessments')
  37. ->where('score', '>=', $this->rubric[0]->expected_points)
  38. ->where('activity_criterion_id', '=', $single_ac->id)
  39. ->lists('student_id'));
  40. $assessments_attempted = count(DB::table('assessments')
  41. ->where('activity_criterion_id', '=', $single_ac->id)
  42. ->lists('student_id'));
  43. if ($assessments_attempted != 0 && (($assessments_passed / $assessments_attempted) * 100) >= $this->rubric[0]->expected_percentage) {
  44. $criteria_achieved[$single_ac->criterion_id] = 1;
  45. } else {
  46. $criteria_achieved[$single_ac->criterion_id] = 0;
  47. }
  48. }
  49. return $criteria_achieved;
  50. }
  51. // cap_array
  52. public function getCapArrayAttribute()
  53. {
  54. $criteria_achieved_percentage = [];
  55. $criterias = DB::table('criteria')
  56. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  57. ->join('assessments', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  58. ->where('activity_criterion.activity_id', '=', $this->id)
  59. ->select(
  60. array(
  61. 'activity_criterion.id as id',
  62. 'activity_criterion.criterion_id as criterion_id',
  63. 'activity_criterion.activity_id as activity_id'
  64. )
  65. )
  66. ->addSelect('criteria.name', 'criteria.subcriteria')
  67. ->get();
  68. Log::info($criterias);
  69. Log::info($this->rubric);
  70. Log::info("this is rubric");
  71. foreach ($criterias as $index => $single_crit) {
  72. $single_crit->outcome_id = json_encode(DB::table('criterion_objective_outcome')
  73. ->where('criterion_id', '=', $single_crit->criterion_id)
  74. ->lists('outcome_id'));
  75. Log::info(json_decode($single_crit->outcome_id));
  76. $amount_of_students = count(DB::table('assessments')
  77. ->where("activity_criterion_id", '=', $single_crit->id)
  78. ->lists('student_id'));
  79. Log::info($amount_of_students);
  80. Log::info($single_crit->id);
  81. Log::info('lmaoOOOO');
  82. $student_pass = DB::table('assessments')
  83. ->where("activity_criterion_id", '=', $single_crit->id)
  84. ->where('score', '>=', $this->rubric[0]->expected_points)
  85. ->lists('student_id');
  86. Log::info($student_pass);
  87. $amount_of_students_passed = count(DB::table('assessments')
  88. ->where("activity_criterion_id", '=', $single_crit->id)
  89. ->where('score', '>=', $this->rubric[0]->expected_points)
  90. ->lists('student_id'));
  91. Log::info($amount_of_students_passed);
  92. Log::info('es aqui');
  93. $single_crit->score_percentage = ($amount_of_students_passed / $amount_of_students) * 100;
  94. $criteria_achieved_percentage[$single_crit->criterion_id] = $single_crit;
  95. Log::info("?");
  96. }
  97. return $criteria_achieved_percentage;
  98. }
  99. // o_ach_array
  100. public function getOAchArrayAttribute($value)
  101. {
  102. /*
  103. $outcomes_achieved = [];
  104. $all_criterion = DB::table('activity_criterion')
  105. ->where('activity_criterion.activity_id', '=', $this->id)
  106. ->get();
  107. $attempted_criteria = 0;
  108. $passed_criteria = 0;
  109. $all_outcomes = DB::table('outcomes')->get();
  110. foreach ($all_criterion as $index => $activity_crit) {
  111. $amount_of_outcomes_attempted = DB::table('criterion_objective_outcome')
  112. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  113. ->where('criterion_id', '=', $activity_crit->criterion_id)
  114. ->select('criterion_objective_outcome.outcome_id')
  115. ->distinct()
  116. ->orderBy('criterion_objective_outcome.outcome_id')
  117. ->select('outcomes.id', 'outcomes.expected_outcome')
  118. ->get();
  119. $passed_criteria = count(DB::table('assessments')
  120. ->where('activity_criterion_id', '=', $activity_crit->id)
  121. ->where('score', '>=', $this->rubric[0]->expected_points)
  122. ->lists('student_id'));
  123. $attempted_criteria = count(DB::table('assessments')
  124. ->where('activity_criterion_id', '=', $activity_crit->id)
  125. ->lists('student_id'));
  126. Log::info("For activity_crit " . ($activity_crit->id));
  127. $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
  128. Log::info('Percent calculated' . $percent_for_criteria);
  129. $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
  130. foreach ($amount_of_outcomes_attempted as $index2 => $outcome) {
  131. if ($percent_for_criteria >= $this->rubric[0]->expected_percentage) {
  132. if (array_key_exists($outcome->id, $outcomes_achieved)) $outcomes_achieved[$outcome->id] += 1;
  133. else $outcomes_achieved[$outcome->id] = 1;
  134. }
  135. }
  136. }
  137. return $outcomes_achieved;*/
  138. $outcomes_achieved = [];
  139. $criteria_achieved = $this->criteria_achieved();
  140. $all_outcomes = DB::table('outcomes')->lists('id');
  141. foreach ($all_outcomes as $outcome_id) {
  142. $outcomes_achieved[$outcome_id] = 0;
  143. }
  144. foreach ($criteria_achieved as $criterion_id => $passed) {
  145. if ($passed == 1) {
  146. $outcomes_related = DB::table('criterion_objective_outcome')
  147. ->where("criterion_id", '=', $criterion_id)
  148. ->select('outcome_id')
  149. ->distinct()
  150. ->lists('outcome_id');
  151. foreach ($outcomes_related as $index => $outcome_id) {
  152. $outcomes_achieved[$outcome_id] += 1;
  153. }
  154. }
  155. }
  156. return $outcomes_achieved;
  157. }
  158. public function is_assessed()
  159. {
  160. $all_criterion = DB::table('activity_criterion')
  161. ->where('activity_criterion.activity_id', '=', $this->id)
  162. ->lists('id');
  163. $assessments = DB::table('assessments')
  164. ->whereIn('activity_criterion_id', $all_criterion)
  165. ->lists('id');
  166. // return boolval(count($assessments));
  167. return (bool)(count($assessments));
  168. }
  169. public function isStudentAssessed($student_id)
  170. {
  171. return DB::table('activities')
  172. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  173. ->join('assessments', 'assessments.activity_criterion_id', '=', 'ac.id')
  174. ->where('activity_id', $this->id)
  175. ->where('student_id', $student_id)
  176. ->count();
  177. }
  178. public function transforming_actions()
  179. {
  180. $transformative_action = DB::table('activities')
  181. ->join('activity_criterion as ac', 'ac.activity_id', '=', 'activities.id')
  182. ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'ac.id')
  183. ->join('transformative_actions as ta', 'ta.id', '=', 'tac.trans_action_id')
  184. ->where('activities.id', $this->id)
  185. ->select('ta.*')
  186. ->first();
  187. if ($transformative_action)
  188. return $transformative_action->description;
  189. else return '';
  190. }
  191. // o_att_array
  192. public function getOAttArrayAttribute()
  193. {
  194. $outcomes_attempted = [];
  195. $all_criterion = DB::table('activity_criterion')
  196. ->where('activity_criterion.activity_id', '=', $this->id)
  197. ->lists('criterion_id');
  198. foreach ($all_criterion as $index => $criterion_id) {
  199. $amount_of_outcomes = DB::table('criterion_objective_outcome')
  200. ->where('criterion_id', '=', $criterion_id)
  201. ->select('criterion_objective_outcome.outcome_id')
  202. ->distinct()
  203. ->orderBy('criterion_objective_outcome.outcome_id')
  204. ->lists('outcome_id');
  205. foreach ($amount_of_outcomes as $index2 => $outcome_id) {
  206. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
  207. else $outcomes_attempted[$outcome_id] = 1;
  208. }
  209. }
  210. //return json_decode($this->outcomes_attempted, true);
  211. return $outcomes_attempted;
  212. }
  213. }