Без опису

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