Aucune description

Criterion.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 function outcomes()
  10. {
  11. // return $this->belongs('Objective')->belongs('Outcome');
  12. // TODO: Changes here
  13. // return $this->belongs('Outcome');
  14. return $this->hasManyThrough('Outcome', 'Objective');
  15. }
  16. public function objectives()
  17. {
  18. return $this->belongsToMany('Objective');
  19. }
  20. public function rubrics()
  21. {
  22. // return $this->belongsToMany('Rubric', 'new_rubric_criterion');
  23. return $this->belongsToMany('Rubric', 'rubric_criterion');
  24. }
  25. /**
  26. * Return the program that the criterion belongs to
  27. *
  28. * @return Illuminate\Database\Eloquent\Model
  29. */
  30. public function program()
  31. {
  32. return $this->belongsTo('Program');
  33. }
  34. // public function activities()
  35. // {
  36. // return $this->hasManyThrough('Activity','activity_criterion');
  37. // }
  38. //
  39. public function subcriteria()
  40. {
  41. return json_decode($this->subcriteria);
  42. }
  43. public static function students_attempted($criterion_id, $activity_id)
  44. {
  45. $students_attempted = 0;
  46. // var_dump($criterion_id);
  47. // var_dump($semester);
  48. // exit();
  49. $activities_criterions = DB::table('activity_criterion')
  50. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  51. ->join('courses', 'activities.course_id', '=', 'courses.id')
  52. ->where('activities.id', '=', $activity_id)
  53. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  54. ->select('activity_criterion.id')
  55. ->distinct()
  56. ->get();
  57. foreach ($activities_criterions as $activity_criterion) {
  58. // $students_attempted+=DB::table('new_assessments')
  59. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  60. // ->where('activity_criterion.id',$activity_criterion->id)
  61. // ->count();
  62. $students_attempted += DB::table('assessments')
  63. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  64. ->where('activity_criterion.id', $activity_criterion->id)
  65. ->count();
  66. }
  67. return $students_attempted;
  68. }
  69. public static function students_achieved($criterion_id, $activity_id)
  70. {
  71. $students_achieved = 0;
  72. // $activities_criterions=DB::table('activity_criterion')
  73. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  74. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  75. // ->where('activities.id','=',$activity_id)
  76. // ->where('activity_criterion.criterion_id','=',$criterion_id)
  77. // ->select('activity_criterion.id','expected_student_score')
  78. // ->distinct()
  79. // ->get();
  80. $activities_criterions = DB::table('activity_criterion')
  81. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  82. ->join('courses', 'activities.course_id', '=', 'courses.id')
  83. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  84. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  85. ->where('activities.id', '=', $activity_id)
  86. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  87. ->select('activity_criterion.id', 'expected_points')
  88. ->distinct()
  89. ->get();
  90. foreach ($activities_criterions as $activity_criterion) {
  91. // $expected_student_score=DB::table('new_criteria')->where('id',$criterion_id)->select('expected_student_score')->get();
  92. // $students_achieved+=DB::table('new_assessments')
  93. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  94. // ->where('activity_criterion.id',$activity_criterion->id)
  95. // ->where('new_assessments.score','>=',$activity_criterion->expected_student_score)
  96. // ->count();
  97. $students_achieved += DB::table('assessments')
  98. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  99. ->where('activity_criterion.id', $activity_criterion->id)
  100. ->where('assessments.score', '>=', $activity_criterion->expected_points)
  101. ->count();
  102. }
  103. return $students_achieved;
  104. }
  105. }