Нет описания

Program.php 17KB

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