설명 없음

Activity.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. // cap_array
  28. public function getCapArrayAttribute()
  29. {
  30. $criteria_achieved_percentage = [];
  31. $criterias = DB::table('criteria')
  32. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  33. ->where('activity_criterion.activity_id', '=', $this->id)
  34. ->select(
  35. 'activity_criterion.id as id',
  36. 'activity_criterion.criterion_id as criterion_id',
  37. 'activity_criterion.activity_id as activity_id'
  38. )
  39. ->addSelect('criteria.name', 'criteria.subcriteria')
  40. ->get();
  41. Log::info($criterias);
  42. Log::info($this->rubric);
  43. Log::info("this is rubric");
  44. foreach ($criterias as $index => $single_crit) {
  45. $single_crit->outcome_id = json_encode(DB::table('criterion_objective_outcome')
  46. ->where('criterion_id', '=', $single_crit->criterion_id)
  47. ->lists('outcome_id'));
  48. Log::info(json_decode($single_crit->outcome_id));
  49. $amount_of_students = count(DB::table('assessments')
  50. ->where("activity_criterion_id", '=', $single_crit->id)
  51. ->lists('student_id'));
  52. Log::info($amount_of_students);
  53. Log::info($single_crit->id);
  54. Log::info('lmaoOOOO');
  55. $student_pass = DB::table('assessments')
  56. ->where("activity_criterion_id", '=', $single_crit->id)
  57. ->where('score', '>=', $this->rubric[0]->expected_points)
  58. ->lists('student_id');
  59. Log::info($student_pass);
  60. $amount_of_students_passed = count(DB::table('assessments')
  61. ->where("activity_criterion_id", '=', $single_crit->id)
  62. ->where('score', '>=', $this->rubric[0]->expected_points)
  63. ->lists('student_id'));
  64. Log::info($amount_of_students_passed);
  65. Log::info('es aqui');
  66. $single_crit->score_percentage = ($amount_of_students_passed / $amount_of_students) * 100;
  67. $criteria_achieved_percentage[$single_crit->criterion_id] = $single_crit;
  68. Log::info("?");
  69. }
  70. return $criteria_achieved_percentage;
  71. }
  72. // o_ach_array
  73. public function getOAchArrayAttribute($value)
  74. {
  75. $outcomes_achieved = [];
  76. $all_criterion = DB::table('activity_criterion')
  77. ->where('activity_criterion.activity_id', '=', $this->id)
  78. ->get();
  79. $attempted_criteria = 0;
  80. $passed_criteria = 0;
  81. $all_outcomes = DB::table('outcomes')->get();
  82. foreach ($all_criterion as $index => $activity_crit) {
  83. $amount_of_outcomes_attempted = DB::table('criterion_objective_outcome')
  84. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  85. ->where('criterion_id', '=', $activity_crit->criterion_id)
  86. ->select('criterion_objective_outcome.outcome_id')
  87. ->distinct()
  88. ->orderBy('criterion_objective_outcome.outcome_id')
  89. ->select('outcomes.id', 'outcomes.expected_outcome')
  90. ->get();
  91. $passed_criteria = count(DB::table('assessments')
  92. ->where('activity_criterion_id', '=', $activity_crit->id)
  93. ->where('score', '>=', $this->rubric[0]->expected_points)
  94. ->lists('student_id'));
  95. $attempted_criteria = count(DB::table('assessments')
  96. ->where('activity_criterion_id', '=', $activity_crit->id)
  97. ->lists('student_id'));
  98. Log::info("For activity_crit " . ($activity_crit->id));
  99. $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
  100. Log::info('Percent calculated' . $percent_for_criteria);
  101. $percent_for_criteria = ($passed_criteria / $attempted_criteria) * 100;
  102. foreach ($amount_of_outcomes_attempted as $index2 => $outcome) {
  103. if ($percent_for_criteria >= $this->rubric[0]->expected_percentage) {
  104. if (array_key_exists($outcome->id, $outcomes_achieved)) $outcomes_achieved[$outcome->id] += 1;
  105. else $outcomes_achieved[$outcome->id] = 1;
  106. }
  107. }
  108. }
  109. return $outcomes_achieved;
  110. }
  111. // o_att_array
  112. public function getOAttArrayAttribute($value)
  113. {
  114. $outcomes_attempted = [];
  115. $all_criterion = DB::table('activity_criterion')
  116. ->where('activity_criterion.activity_id', '=', $this->id)
  117. ->lists('criterion_id');
  118. foreach ($all_criterion as $index => $criterion_id) {
  119. $amount_of_outcomes = DB::table('criterion_objective_outcome')
  120. ->where('criterion_id', '=', $criterion_id)
  121. ->select('criterion_objective_outcome.outcome_id')
  122. ->distinct()
  123. ->orderBy('criterion_objective_outcome.outcome_id')
  124. ->lists('outcome_id');
  125. foreach ($amount_of_outcomes as $index2 => $outcome_id) {
  126. if (array_key_exists($outcome_id, $outcomes_attempted)) $outcomes_attempted[$outcome_id] += 1;
  127. else $outcomes_attempted[$outcome_id] = 1;
  128. }
  129. }
  130. //return json_decode($this->outcomes_attempted, true);
  131. return $outcomes_attempted;
  132. }
  133. }