Ei kuvausta

Criterion.php 2.8KB

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