Keine Beschreibung

Program.php 15KB

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