Nav apraksta

Criterion.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ->count();
  88. }
  89. return $students_attempted;
  90. }
  91. public static function students_achieved($criterion_id, $activity_id)
  92. {
  93. $students_achieved = 0;
  94. // $activities_criterions=DB::table('activity_criterion')
  95. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  96. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  97. // ->where('activities.id','=',$activity_id)
  98. // ->where('activity_criterion.criterion_id','=',$criterion_id)
  99. // ->select('activity_criterion.id','expected_student_score')
  100. // ->distinct()
  101. // ->get();
  102. $activities_criterions = DB::table('activity_criterion')
  103. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  104. ->join('courses', 'activities.course_id', '=', 'courses.id')
  105. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  106. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  107. ->where('activities.id', '=', $activity_id)
  108. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  109. ->select('activity_criterion.id', 'expected_points')
  110. ->distinct()
  111. ->get();
  112. foreach ($activities_criterions as $activity_criterion) {
  113. // $expected_student_score=DB::table('new_criteria')->where('id',$criterion_id)->select('expected_student_score')->get();
  114. // $students_achieved+=DB::table('new_assessments')
  115. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  116. // ->where('activity_criterion.id',$activity_criterion->id)
  117. // ->where('new_assessments.score','>=',$activity_criterion->expected_student_score)
  118. // ->count();
  119. $students_achieved += DB::table('assessments')
  120. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  121. ->where('activity_criterion.id', $activity_criterion->id)
  122. ->where('assessments.score', '>=', $activity_criterion->expected_points)
  123. ->count();
  124. }
  125. return $students_achieved;
  126. }
  127. }