Нет описания

Criterion.php 4.4KB

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