No Description

Program.php 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. $outcomes_attempted = (array)$activity->o_att_array;
  40. if (array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0) {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. // return the users that are pcoords for a program
  47. public function users()
  48. {
  49. return $this->belongsToMany('User');
  50. }
  51. public function objectives()
  52. {
  53. return $this->hasMany('Objective');
  54. }
  55. // Return learning objectives ordered by outcome
  56. public function objectivesByOutcome()
  57. {
  58. // Objective::
  59. $objectives = DB::table('outcomes')
  60. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  61. ->leftJoin('objectives', function ($join) {
  62. $join
  63. ->on('outcomes.id', '=', 'objectives.outcome_id')
  64. ->where('objectives.program_id', '=', $this->id);
  65. })
  66. ->orderBy('outcome_name', 'ASC')
  67. ->orderBy('objectives.text', 'ASC')
  68. ->get();
  69. return $objectives;
  70. }
  71. public function hasObjectivesInOutcome($outcome_id)
  72. {
  73. return Objective::where('program_id', $this->id)
  74. ->where('outcome_id', $outcome_id)->count();
  75. }
  76. /**
  77. * Return all the criteria in/for the program, if any
  78. *
  79. * @return Illuminate\Database\Eloquent\Collection
  80. */
  81. public function criteria()
  82. {
  83. return $this->hasMany('Criterion');
  84. }
  85. // public function attempted_outcome($outcome_id, $semester)
  86. // {
  87. // $conteo= DB::table('activity_criterion')
  88. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  89. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  90. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  91. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  92. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  93. // ->where('programs.id','=',$this->id)
  94. // ->where('courses.semester_id','=',$semester)
  95. // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  96. // ;
  97. // return $conteo;
  98. // }
  99. public function attempted_criteria_by_outcome($outcome_id, $semesters)
  100. {
  101. $semesters_array = [];
  102. foreach ($semesters as $semester) {
  103. $semesters_array[] = $semester->id;
  104. }
  105. $conteo = DB::table('activity_criterion')
  106. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  107. ->join('courses', 'activities.course_id', '=', 'courses.id')
  108. ->join('programs', 'programs.id', '=', 'courses.program_id')
  109. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  110. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  111. ->where('programs.id', '=', $this->id)
  112. ->whereIn('courses.semester_id', $semesters_array)
  113. ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'));
  114. return $conteo;
  115. }
  116. public function attempted_outcome($outcome_id, $semesters)
  117. {
  118. $semesters_array = [];
  119. foreach ($semesters as $semester) {
  120. $semesters_array[] = $semester->id;
  121. }
  122. $conteo = DB::table('activity_criterion')
  123. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  124. ->join('courses', 'activities.course_id', '=', 'courses.id')
  125. ->join('programs', 'programs.id', '=', 'courses.program_id')
  126. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  127. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  128. ->where('programs.id', '=', $this->id)
  129. ->whereIn('courses.semester_id', $semesters_array)
  130. ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'));
  131. return $conteo;
  132. }
  133. public function achieved_criteria_by_outcome($outcome_id, $semesters)
  134. {
  135. $semesters_array = [];
  136. foreach ($semesters as $semester) {
  137. $semesters_array[] = $semester->id;
  138. }
  139. // DB::enableQueryLog();
  140. // dd(DB::getQueryLog());
  141. // $criteria=DB::table('new_criteria')
  142. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  143. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  144. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  145. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  146. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  147. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  148. // ->where('programs.id','=',$this->id)
  149. // ->whereIn('courses.semester_id',$semesters_array)
  150. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  151. // ->distinct()
  152. // ->get()
  153. // ;
  154. $criteria=DB::table('criteria')
  155. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  156. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  157. ->join('courses', 'activities.course_id', '=', 'courses.id')
  158. ->join('programs', 'programs.id', '=', 'courses.program_id')
  159. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  160. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  161. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  162. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  163. ->where('programs.id','=',$this->id)
  164. ->whereIn('courses.semester_id',$semesters_array)
  165. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  166. ->distinct()
  167. ->get()
  168. ;
  169. // dd(DB::getQueryLog());
  170. $conteo=0;
  171. $attempted_criteria_per_program_array=[];
  172. // $students_attempted=0;
  173. // $students_achieved=0;
  174. foreach($criteria as $criterion)
  175. {
  176. if(!isset($students_attempted[$criterion->id]))$students_attempted[$criterion->id]=0;
  177. if(!isset($students_achieved[$criterion->id]))$students_achieved[$criterion->id]=0;
  178. $attempted_criteria_per_program_array[$criterion->id]=1;
  179. $students_attempted[$criterion->id]+=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  180. $students_achieved[$criterion->id]+=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  181. }
  182. // var_dump($outcome_id);
  183. // var_dump($this->id);
  184. // if(isset($students_attempted))var_dump($students_attempted);
  185. // else{print "aqui hay algo";}
  186. // print "<br>";
  187. // if(isset($students_achieved))var_dump($students_achieved);
  188. // print "<br>";
  189. // print "<br>";
  190. // exit();
  191. if (isset($students_attempted)) {
  192. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  193. if ($students_attempted_n) {
  194. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  195. } else {
  196. $percentage_students_who_achieved = 0;
  197. }
  198. else
  199. {
  200. $percentage_students_who_achieved=0;
  201. }
  202. if($percentage_students_who_achieved>=$criterion->expected_percentage)
  203. {
  204. $conteo++;
  205. }
  206. }
  207. }
  208. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  209. $achievedProgramOutcome = 0;
  210. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  211. // var_dump($outcome->expected_outcome);
  212. // exit();
  213. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  214. $achievedProgramOutcome = 1;
  215. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  216. }
  217. return $conteo;
  218. }
  219. public function achieved_outcome($outcome_id, $semesters)
  220. {
  221. $semesters_array = [];
  222. foreach ($semesters as $semester) {
  223. $semesters_array[] = $semester->id;
  224. }
  225. // DB::enableQueryLog();
  226. // dd(DB::getQueryLog());
  227. // $criteria=DB::table('new_criteria')
  228. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  229. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  230. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  231. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  232. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  233. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  234. // ->where('programs.id','=',$this->id)
  235. // ->whereIn('courses.semester_id',$semesters_array)
  236. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  237. // ->distinct()
  238. // ->get()
  239. // ;
  240. $criteria=DB::table('criteria')
  241. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  242. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  243. ->join('courses', 'activities.course_id', '=', 'courses.id')
  244. ->join('programs', 'programs.id', '=', 'courses.program_id')
  245. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  246. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  247. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  248. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  249. ->where('programs.id','=',$this->id)
  250. ->whereIn('courses.semester_id',$semesters_array)
  251. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  252. ->distinct()
  253. ->get()
  254. ;
  255. // dd(DB::getQueryLog());
  256. $conteo=0;
  257. $attempted_criteria_per_program_array=[];
  258. // $students_attempted=0;
  259. // $students_achieved=0;
  260. foreach($criteria as $criterion)
  261. {
  262. if(!isset($students_attempted[$criterion->id]))$students_attempted[$criterion->id]=0;
  263. if(!isset($students_achieved[$criterion->id]))$students_achieved[$criterion->id]=0;
  264. $attempted_criteria_per_program_array[$criterion->id]=1;
  265. $students_attempted[$criterion->id]+=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  266. $students_achieved[$criterion->id]+=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  267. }
  268. // var_dump($this->id);
  269. // if(isset($students_attempted))var_dump($students_attempted);
  270. // else{print "aqui hay algo";}
  271. // print "<br>";
  272. // if(isset($students_achieved))var_dump($students_achieved);
  273. // print "<br>";
  274. // print "<br>";
  275. // exit();
  276. if (isset($students_attempted)) {
  277. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  278. if ($students_attempted_n) {
  279. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  280. } else {
  281. $percentage_students_who_achieved = 0;
  282. }
  283. else
  284. {
  285. $percentage_students_who_achieved=0;
  286. }
  287. if($percentage_students_who_achieved>=$criterion->expected_percentage)
  288. {
  289. $conteo++;
  290. }
  291. }
  292. }
  293. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  294. $achievedProgramOutcome = 0;
  295. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  296. // var_dump($outcome->expected_outcome);
  297. // exit();
  298. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  299. $achievedProgramOutcome = 1;
  300. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  301. }
  302. return $achievedProgramOutcome;
  303. }
  304. public static function generalComponentPrograms()
  305. {
  306. return self::whereIn('id', array(123, 124, 125, 126, 127, 128, 129))->get();
  307. }
  308. public function assessmentOverview()
  309. {
  310. $assessment_overview = array();
  311. $assessment_overview['program_courses'] = $this->courses;
  312. $outcomeCount = Outcome::all()->count();
  313. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  314. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  315. $assessment_overview['assessed_courses_count'] = 0;
  316. foreach ($assessment_overview['program_courses'] as $course) {
  317. if ($course->outcomes_achieved != NULL) {
  318. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  319. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  320. for ($i = 1; $i <= count($assessment_overview['outcomes_attempted']); $i++) {
  321. $assessment_overview['outcomes_achieved'][$i] += $course_outcomes_achieved[$i];
  322. $assessment_overview['outcomes_attempted'][$i] += $course_outcomes_attempted[$i];
  323. }
  324. $assessment_overview['assessed_courses_count'] += 1;
  325. }
  326. }
  327. /**
  328. * List of grouped courses (grouped sections)
  329. */
  330. $assessment_overview['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  331. ->with('semester')
  332. ->with('program')
  333. ->where('program_id', $this->id)
  334. ->whereIn('semester_id', Session::get('semesters_ids'))
  335. ->groupBy(array('code', 'number', 'semester_id'))
  336. ->orderBy('code')
  337. ->orderBy('number')
  338. ->orderBy('semester_id')
  339. ->get();
  340. Log::info(Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  341. ->with('semester')
  342. ->with('program')
  343. ->where('program_id', $this->id)
  344. ->whereIn('semester_id', Session::get('semesters_ids'))
  345. ->groupBy(array('code', 'number', 'semester_id'))
  346. ->orderBy('code')
  347. ->orderBy('number')
  348. ->orderBy('semester_id')
  349. ->toSql());
  350. return $assessment_overview;
  351. }
  352. }