Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. class Program extends Eloquent
  3. {
  4. public function school()
  5. {
  6. return $this->belongsTo('School');
  7. }
  8. public function courses()
  9. {
  10. return $this->hasMany('Course')->with('semester')->whereIn('semester_id', Session::get('semesters_ids'))->orderBy('code')->orderBy('number')->orderBy('section');
  11. }
  12. public function coordinators()
  13. {
  14. return $this->hasMany('User');
  15. }
  16. public function professors()
  17. {
  18. return $this->hasMany('Professor');
  19. }
  20. public function students()
  21. {
  22. return $this->hasMany('Student');
  23. }
  24. public function templates()
  25. {
  26. return $this->hasMany('Template');
  27. }
  28. public function activities()
  29. {
  30. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
  31. }
  32. public function publishedActivities()
  33. {
  34. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->whereIn('semester_id', Session::get('semesters_ids'));
  35. }
  36. public function assessesOutcome($outcome_id)
  37. {
  38. foreach ($this->publishedActivities as $activity)
  39. {
  40. $outcomes_attempted = (array)$activity->o_att_array;
  41. if(array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0)
  42. {
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. // return the users that are pcoords for a program
  49. public function users()
  50. {
  51. return $this->belongsToMany('User');
  52. }
  53. public function objectives()
  54. {
  55. return $this->hasMany('Objective');
  56. }
  57. // Return learning objectives ordered by outcome
  58. public function objectivesByOutcome()
  59. {
  60. // Objective::
  61. $objectives = DB::table('outcomes')
  62. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  63. ->leftJoin('objectives', function($join)
  64. {
  65. $join
  66. ->on('outcomes.id', '=', 'objectives.outcome_id')
  67. ->where('objectives.program_id', '=', $this->id);
  68. })
  69. ->orderBy('outcome_name', 'ASC')
  70. ->orderBy('objectives.text', 'ASC')
  71. ->get();
  72. return $objectives;
  73. }
  74. public function hasObjectivesInOutcome($outcome_id)
  75. {
  76. return Objective::where('program_id', $this->id)
  77. ->where('outcome_id', $outcome_id)->count();
  78. }
  79. /**
  80. * Return all the criteria in/for the program, if any
  81. *
  82. * @return Illuminate\Database\Eloquent\Collection
  83. */
  84. public function criteria()
  85. {
  86. return $this->hasMany('Criterion');
  87. }
  88. public static function generalComponentPrograms(){
  89. return self::whereIn('id', array(123,124,125,126,127,128,129))->get();
  90. }
  91. public function assessmentOverview(){
  92. $assessment_overview = array();
  93. $assessment_overview['program_courses'] = $this->courses;
  94. $outcomeCount = Outcome::all()->count();
  95. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  96. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  97. $assessment_overview['assessed_courses_count'] = 0;
  98. foreach ($assessment_overview['program_courses'] as $course)
  99. {
  100. if($course->outcomes_achieved!=NULL)
  101. {
  102. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  103. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  104. for($i=1; $i<=count($assessment_overview['outcomes_attempted']); $i++)
  105. {
  106. $assessment_overview['outcomes_achieved'][$i]+=$course_outcomes_achieved[$i];
  107. $assessment_overview['outcomes_attempted'][$i]+=$course_outcomes_attempted[$i];
  108. }
  109. $assessment_overview['assessed_courses_count']+=1;
  110. }
  111. }
  112. /**
  113. * List of grouped courses (grouped sections)
  114. */
  115. $assessment_overview['grouped_courses'] = Course::
  116. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  117. ->with('semester')
  118. ->with('program')
  119. ->where('program_id', $this->id)
  120. ->whereIn('semester_id', Session::get('semesters_ids'))
  121. ->groupBy(array('code', 'number', 'semester_id'))
  122. ->orderBy('code')
  123. ->orderBy('number')
  124. ->orderBy('semester_id')
  125. ->get();
  126. Log::info(Course::
  127. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  128. ->with('semester')
  129. ->with('program')
  130. ->where('program_id', $this->id)
  131. ->whereIn('semester_id', Session::get('semesters_ids'))
  132. ->groupBy(array('code', 'number', 'semester_id'))
  133. ->orderBy('code')
  134. ->orderBy('number')
  135. ->orderBy('semester_id')
  136. ->toSql());
  137. return $assessment_overview;
  138. }
  139. }