No Description

Criterion.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 programs()
  38. {
  39. return $this->belongsToMany('Program','program_criterion');
  40. }
  41. public function program()
  42. {
  43. return $this->belongsTo('Program');
  44. }
  45. // public function activities()
  46. // {
  47. // return $this->hasManyThrough('Activity','activity_criterion');
  48. // }
  49. //
  50. public function subcriteria()
  51. {
  52. return json_decode($this->subcriteria);
  53. }
  54. public static function students_attempted($criterion_id, $activity_id)
  55. {
  56. $students_attempted = 0;
  57. // var_dump($criterion_id);
  58. // var_dump($semester);
  59. // exit();
  60. $activities_criterions = DB::table('activity_criterion')
  61. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  62. ->join('courses', 'activities.course_id', '=', 'courses.id')
  63. ->where('activities.id', '=', $activity_id)
  64. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  65. ->select('activity_criterion.id')
  66. ->distinct()
  67. ->get();
  68. foreach ($activities_criterions as $activity_criterion) {
  69. // $students_attempted+=DB::table('new_assessments')
  70. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  71. // ->where('activity_criterion.id',$activity_criterion->id)
  72. // ->count();
  73. $students_attempted += DB::table('assessments')
  74. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  75. ->where('activity_criterion.id', $activity_criterion->id)
  76. ->count();
  77. }
  78. return $students_attempted;
  79. }
  80. public static function students_achieved($criterion_id, $activity_id)
  81. {
  82. $students_achieved = 0;
  83. // $activities_criterions=DB::table('activity_criterion')
  84. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  85. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  86. // ->where('activities.id','=',$activity_id)
  87. // ->where('activity_criterion.criterion_id','=',$criterion_id)
  88. // ->select('activity_criterion.id','expected_student_score')
  89. // ->distinct()
  90. // ->get();
  91. $activities_criterions = DB::table('activity_criterion')
  92. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  93. ->join('courses', 'activities.course_id', '=', 'courses.id')
  94. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  95. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  96. ->where('activities.id', '=', $activity_id)
  97. ->where('activity_criterion.criterion_id', '=', $criterion_id)
  98. ->select('activity_criterion.id', 'expected_points')
  99. ->distinct()
  100. ->get();
  101. foreach ($activities_criterions as $activity_criterion) {
  102. // $expected_student_score=DB::table('new_criteria')->where('id',$criterion_id)->select('expected_student_score')->get();
  103. // $students_achieved+=DB::table('new_assessments')
  104. // ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  105. // ->where('activity_criterion.id',$activity_criterion->id)
  106. // ->where('new_assessments.score','>=',$activity_criterion->expected_student_score)
  107. // ->count();
  108. $students_achieved += DB::table('assessments')
  109. ->join('activity_criterion', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  110. ->where('activity_criterion.id', $activity_criterion->id)
  111. ->where('assessments.score', '>=', $activity_criterion->expected_points)
  112. ->count();
  113. }
  114. return $students_achieved;
  115. }
  116. }