No Description

Criterion.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. use Illuminate\Database\Eloquent\SoftDeletingTrait;
  3. class Criterion extends Eloquent
  4. {
  5. use SoftDeletingTrait;
  6. protected $dates = ['deleted_at'];
  7. // protected $table = 'new_criteria';
  8. protected $table = 'criteria';
  9. public static function outcomes($criterion_id)
  10. {
  11. // return $this->belongs('Objective')->belongs('Outcome');
  12. // TODO: Changes here
  13. // return $this->belongs('Outcome');
  14. $outcomes = DB::table('criterion_objective_outcome')
  15. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  16. ->where('criterion_id', $criterion_id)
  17. ->select('outcomes.*')
  18. ->distinct()
  19. ->get();
  20. return $outcomes;
  21. //$this->hasManyThrough('Outcome', 'Objective');
  22. }
  23. public function getObjectivesAttribute()
  24. {
  25. return $this->belongsToMany('Objective', 'criterion_objective_outcome');
  26. }
  27. public function rubrics()
  28. {
  29. // return $this->belongsToMany('Rubric', 'new_rubric_criterion');
  30. return $this->belongsToMany('Rubric', 'rubric_criterion');
  31. }
  32. /*public function scopeFromProgram($query, $programs)
  33. {
  34. return $query->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
  35. ->whereIn("program_id", "programs")
  36. ->select('criteria.*');
  37. }*/
  38. /**
  39. * Return the program that the criterion belongs to
  40. *
  41. * @return Illuminate\Database\Eloquent\Model
  42. */
  43. public function programs()
  44. {
  45. return $this->belongsToMany('Program', 'program_criterion');
  46. }
  47. //public getPairedObjectivesAttribute(){
  48. // if(isset($this->from_objective)){
  49. // return DB::table()
  50. // }
  51. //}
  52. public function program()
  53. {
  54. return $this->belongsTo('Program');
  55. }
  56. // public function activities()
  57. // {
  58. // return $this->hasManyThrough('Activity','activity_criterion');
  59. // }
  60. //
  61. public function subcriteria()
  62. {
  63. return json_decode($this->subcriteria);
  64. }
  65. public static function students_attempted($criterion_id, $activity_id)
  66. {
  67. $students_attempted = 0;
  68. // var_dump($criterion_id);
  69. // var_dump($semester);
  70. // exit();
  71. $activities_criterions = DB::table('activity_criterion')
  72. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  73. ->join('courses', 'activities.course_id', '=', 'courses.id')
  74. ->where('activities.id', '=', $activity_id)
  75. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  76. ->select('activity_criterion.id')
  77. ->distinct()
  78. ->get();
  79. foreach ($activities_criterions as $activity_criterion) {
  80. // $students_attempted+=DB::table('new_assessments')
  81. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  82. // ->where('activity_criterion.id',$activity_criterion->id)
  83. // ->count();
  84. $students_attempted += DB::table('assessments')
  85. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  86. ->where('activity_criterion.id', $activity_criterion->id)
  87. ->whereNotNull('score')
  88. ->count();
  89. }
  90. return $students_attempted;
  91. }
  92. public static function students_achieved($criterion_id, $activity_id)
  93. {
  94. $students_achieved = 0;
  95. // $activities_criterions=DB::table('activity_criterion')
  96. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  97. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  98. // ->where('activities.id','=',$activity_id)
  99. // ->where('activity_criterion.criterion_id','=',$criterion_id)
  100. // ->select('activity_criterion.id','expected_student_score')
  101. // ->distinct()
  102. // ->get();
  103. $activities_criterions = DB::table('activity_criterion')
  104. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  105. ->join('courses', 'activities.course_id', '=', 'courses.id')
  106. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  107. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  108. ->where('activities.id', '=', $activity_id)
  109. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  110. ->select('activity_criterion.id', 'expected_points')
  111. ->distinct()
  112. ->get();
  113. foreach ($activities_criterions as $activity_criterion) {
  114. // $expected_student_score=DB::table('new_criteria')->where('id',$criterion_id)->select('expected_student_score')->get();
  115. // $students_achieved+=DB::table('new_assessments')
  116. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  117. // ->where('activity_criterion.id',$activity_criterion->id)
  118. // ->where('new_assessments.score','>=',$activity_criterion->expected_student_score)
  119. // ->count();
  120. $students_achieved += DB::table('assessments')
  121. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  122. ->where('activity_criterion.id', $activity_criterion->id)
  123. ->where('assessments.score', '>=', $activity_criterion->expected_points)
  124. ->count();
  125. }
  126. return $students_achieved;
  127. }
  128. }