Nenhuma descrição

Criterion.php 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. 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', 'new_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. {
  57. $students_attempted+=DB::table('new_assessments')
  58. ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  59. ->where('activity_criterion.id',$activity_criterion->id)
  60. ->count();
  61. }
  62. return $students_attempted;
  63. }
  64. public static function students_achieved($criterion_id,$activity_id)
  65. {
  66. $students_achieved=0;
  67. $activities_criterions=DB::table('activity_criterion')
  68. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  69. ->join('courses', 'activities.course_id', '=', 'courses.id')
  70. ->where('activities.id','=',$activity_id)
  71. ->where('activity_criterion.criterion_id','=',$criterion_id)
  72. ->select('activity_criterion.id','expected_student_score')
  73. ->distinct()
  74. ->get();
  75. foreach($activities_criterions as $activity_criterion)
  76. {
  77. // $expected_student_score=DB::table('new_criteria')->where('id',$criterion_id)->select('expected_student_score')->get();
  78. $students_achieved+=DB::table('new_assessments')
  79. ->join('activity_criterion', 'new_assessments.activity_criterion_id', '=', 'activity_criterion.id')
  80. ->where('activity_criterion.id',$activity_criterion->id)
  81. ->where('new_assessments.score','>=',$activity_criterion->expected_student_score)
  82. ->count();
  83. }
  84. return $students_achieved;
  85. }
  86. }