Keine Beschreibung

Program.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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 getProgramStudentsPerOutcomeAttribute()
  30. { {
  31. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  32. //if ($this->is_graduate == 1) {
  33. // $outcomes = Outcome::active_by_semesters($semesters, 1);
  34. //} else {
  35. // $outcomes = Outcome::active_by_semesters($semesters, 0);
  36. //}
  37. $outcomes = Outcome::orderBy('name', 'asc')->get();
  38. $outcome_ids = DB::table("outcomes")
  39. ->whereNotNull('new_outcome_id')
  40. ->get();
  41. $combined_outcomes = [];
  42. foreach ($outcome_ids as $outcome) {
  43. $combined_outcomes[$outcome->id] = $outcome->new_outcome_id;
  44. }
  45. $array_to_send = [];
  46. $students =
  47. DB::table('assessments')
  48. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  49. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  50. ->join('courses', 'courses.id', '=', 'activities.course_id')
  51. ->join('students', 'students.id', '=', 'assessments.student_id')
  52. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  53. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  54. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  55. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  56. ->where('students.program_id', $this->id)
  57. ->whereIn('semester_id', Session::get('semesters_ids'))
  58. ->where('semesters.is_visible', '=', 1)
  59. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  60. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  61. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  62. ->groupBy('students.id', 'outcome_id')
  63. ->get();
  64. $array_to_send['program_info'] = [];
  65. $array_to_send['program_info']['outcomes_attempted'] = [];
  66. $out_att = [];
  67. $out_ach = [];
  68. foreach ($outcomes as $outcome) {
  69. $out_att[$outcome->id] = 0;
  70. $out_ach[$outcome->id] = 0;
  71. }
  72. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  73. foreach ($students as $result) {
  74. $crit_att = $result->criteria_attempted;
  75. $crit_ach = $result->criteria_achieved;
  76. $out_att[$result->outcome_id] += 1;
  77. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  78. $out_ach[$result->outcome_id] += 1;
  79. }
  80. }
  81. $array_to_send['program_info']['outcomes_attempted_uncombined'] = $out_att;
  82. $array_to_send['program_info']['outcomes_achieved_uncombined'] = $out_ach;
  83. $the_processed_table = [];
  84. foreach ($students as $result) {
  85. $student_id = $result->student_id;
  86. $outcome_id = $result->outcome_id;
  87. if (isset($combined_outcomes[$outcome_id]))
  88. $outcome_id = $combined_outcomes[$outcome_id];
  89. if (!isset($the_processed_table[$student_id])) {
  90. $the_processed_table[$student_id] = [];
  91. }
  92. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  93. // los criterios, achieved y attempted
  94. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  95. $the_processed_table[$student_id][$outcome_id] = array(
  96. "criteria_attempted" => $result->criteria_attempted,
  97. "criteria_achieved" => $result->criteria_achieved
  98. );
  99. }
  100. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  101. //deprecated outcomes.
  102. else {
  103. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  104. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  105. }
  106. }
  107. //Log::info("ESTOY LOCO POR TI");
  108. //Log::info($the_processed_table);
  109. $out_att = [];
  110. $out_ach = [];
  111. foreach ($outcomes as $outcome) {
  112. $out_att[$outcome->id] = 0;
  113. $out_ach[$outcome->id] = 0;
  114. }
  115. foreach ($the_processed_table as $student_id => $outcome_ids) {
  116. //Log::info("AQUI");
  117. //Log::info($outcome_ids);
  118. foreach ($outcome_ids as $outcome_id => $crit_information) {
  119. Log::info($crit_information);
  120. $crit_att = $crit_information['criteria_attempted'];
  121. $crit_ach = $crit_information['criteria_achieved'];
  122. $out_att[$outcome_id] += 1;
  123. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  124. $out_ach[$outcome_id] += 1;
  125. }
  126. }
  127. }
  128. $array_to_send['program_info']['outcomes_attempted_combined'] = $out_att;
  129. $array_to_send['program_info']['outcomes_achieved_combined'] = $out_ach;
  130. return $array_to_send;
  131. }
  132. }
  133. public function getCriteriaAttribute()
  134. {
  135. if ($this->outcome_id) {
  136. return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
  137. ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
  138. ->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
  139. ->addSelect('program_criterion_objective_outcome.id as pcobo_id')
  140. ->where('program_id', $this->id)
  141. ->where('outcome_id', $this->outcome_id)
  142. ->get();
  143. }
  144. return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
  145. ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
  146. ->where('program_id', $this->id)
  147. ->get();
  148. }
  149. public function templates()
  150. {
  151. return $this->hasMany('Template');
  152. }
  153. public function activities()
  154. {
  155. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
  156. }
  157. public function publishedActivities()
  158. {
  159. return $this->hasManyThrough('Activity', 'Course')
  160. //->whereNotNull('activities.outcomes_attempted')
  161. ->where('activities.draft', 0)
  162. ->where('activities.diagnostic', 0)->whereIn('semester_id', Session::get('semesters_ids'));
  163. }
  164. public function assessesOutcome($outcome_id)
  165. {
  166. foreach ($this->publishedActivities as $activity) {
  167. $assessed = DB::table('activity_criterion')
  168. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  169. ->where('activity_id', $activity->id)
  170. ->first();
  171. if (!$assessed) continue;
  172. $outcomes_attempted = (array)$activity->o_att_array;
  173. if (array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0) {
  174. return true;
  175. }
  176. }
  177. return false;
  178. }
  179. // return the users that are pcoords for a program
  180. public function users()
  181. {
  182. return $this->belongsToMany('User');
  183. }
  184. public function objectives()
  185. {
  186. return $this->hasMany('Objective');
  187. }
  188. // Return learning objectives ordered by outcome
  189. public function objectivesByOutcome()
  190. {
  191. // Objective::
  192. $objectives = DB::table('outcomes')
  193. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  194. ->leftJoin('objectives', function ($join) {
  195. $join
  196. ->on('outcomes.id', '=', 'objectives.outcome_id')
  197. ->where('objectives.program_id', '=', $this->id);
  198. })
  199. ->orderBy('outcome_name', 'ASC')
  200. ->orderBy('objectives.text', 'ASC')
  201. ->get();
  202. return $objectives;
  203. }
  204. public function annualPlan()
  205. {
  206. return $this->hasMany("AnnualPlan");
  207. }
  208. public function hasObjectivesInOutcome($outcome_id)
  209. {
  210. return Objective::where('program_id', $this->id)
  211. ->where('outcome_id', $outcome_id)->count();
  212. }
  213. /**
  214. * Return all the criteria in/for the program, if any
  215. *
  216. * @return Illuminate\Database\Eloquent\Collection
  217. */
  218. public function criteria()
  219. {
  220. Log::info("AQUI");
  221. $lmao = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  222. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  223. ->where('program_id', $this->id);
  224. //->get();
  225. return $lmao;
  226. $l = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  227. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  228. ->where('program_id', $this->id)->get();
  229. //get();
  230. }
  231. // public function attempted_outcome($outcome_id, $semester)
  232. // {
  233. // $conteo= DB::table('activity_criterion')
  234. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  235. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  236. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  237. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  238. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  239. // ->where('programs.id','=',$this->id)
  240. // ->where('courses.semester_id','=',$semester)
  241. // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  242. // ;
  243. // return $conteo;
  244. // }
  245. public function attempted_criteria_by_outcome($outcome_id, $semesters)
  246. {
  247. $semesters_array = [];
  248. foreach ($semesters as $semester) {
  249. $semesters_array[] = $semester->id;
  250. }
  251. $conteo = DB::table('activity_criterion')
  252. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  253. ->join('courses', 'activities.course_id', '=', 'courses.id')
  254. ->join('programs', 'programs.id', '=', 'courses.program_id')
  255. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  256. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  257. ->where('programs.id', '=', $this->id)
  258. ->whereIn('courses.semester_id', $semesters_array)
  259. ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'));
  260. return $conteo;
  261. }
  262. public function attempted_outcome($outcome_id, $semesters)
  263. {
  264. $semesters_array = [];
  265. foreach ($semesters as $semester) {
  266. $semesters_array[] = $semester->id;
  267. }
  268. $conteo = DB::table('activity_criterion')
  269. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  270. ->join('courses', 'activities.course_id', '=', 'courses.id')
  271. ->join('programs', 'programs.id', '=', 'courses.program_id')
  272. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  273. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  274. ->where('programs.id', '=', $this->id)
  275. ->whereIn('courses.semester_id', $semesters_array)
  276. ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'));
  277. Log::info(DB::table('activity_criterion')
  278. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  279. ->join('courses', 'activities.course_id', '=', 'courses.id')
  280. ->join('programs', 'programs.id', '=', 'courses.program_id')
  281. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  282. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  283. ->where('programs.id', '=', $this->id)
  284. ->whereIn('courses.semester_id', $semesters_array)
  285. ->toSql());
  286. return $conteo;
  287. }
  288. public function achieved_criteria_by_outcome($outcome_id, $semesters)
  289. {
  290. $semesters_array = [];
  291. foreach ($semesters as $semester) {
  292. $semesters_array[] = $semester->id;
  293. }
  294. // DB::enableQueryLog();
  295. // dd(DB::getQueryLog());
  296. // $criteria=DB::table('new_criteria')
  297. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  298. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  299. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  300. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  301. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  302. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  303. // ->where('programs.id','=',$this->id)
  304. // ->whereIn('courses.semester_id',$semesters_array)
  305. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  306. // ->distinct()
  307. // ->get()
  308. // ;
  309. $criteria = DB::table('criteria')
  310. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  311. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  312. ->join('courses', 'activities.course_id', '=', 'courses.id')
  313. ->join('programs', 'programs.id', '=', 'courses.program_id')
  314. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  315. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  316. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  317. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  318. ->where('programs.id', '=', $this->id)
  319. ->whereIn('courses.semester_id', $semesters_array)
  320. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  321. ->distinct()
  322. ->get();
  323. // dd(DB::getQueryLog());
  324. $conteo = 0;
  325. $attempted_criteria_per_program_array = [];
  326. // $students_attempted=0;
  327. // $students_achieved=0;
  328. foreach ($criteria as $criterion) {
  329. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  330. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  331. $attempted_criteria_per_program_array[$criterion->id] = 1;
  332. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  333. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  334. }
  335. // var_dump($outcome_id);
  336. // var_dump($this->id);
  337. // if(isset($students_attempted))var_dump($students_attempted);
  338. // else{print "aqui hay algo";}
  339. // print "<br>";
  340. // if(isset($students_achieved))var_dump($students_achieved);
  341. // print "<br>";
  342. // print "<br>";
  343. // exit();
  344. if (isset($students_attempted)) {
  345. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  346. if ($students_attempted_n) {
  347. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  348. } else {
  349. $percentage_students_who_achieved = 0;
  350. }
  351. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  352. $conteo++;
  353. }
  354. }
  355. }
  356. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  357. $achievedProgramOutcome = 0;
  358. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  359. // var_dump($outcome->expected_outcome);
  360. // exit();
  361. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  362. $achievedProgramOutcome = 1;
  363. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  364. }
  365. return $conteo;
  366. }
  367. //get linea outcome
  368. public function getExpectedOutcomeTargetAttribute()
  369. {
  370. //
  371. $linea_undergrad = DB::table('target_outcomes_program')
  372. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  373. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  374. ->where('program_id', $this->id)
  375. ->whereIn("semester_id", Session::get('semesters_ids'))
  376. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  377. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  378. ->groupBy("expected_target")
  379. ->orderBy("expected_target", "DESC")
  380. ->first();
  381. if (!isset($linea_undergrad)) {
  382. $linea_undergrad = null;
  383. } elseif ($linea_undergrad->count_semester_id > 1) {
  384. $linea_undergrad = DB::table('target_outcomes_program')
  385. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  386. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  387. ->where('program_id', $this->id)
  388. ->where('expected_target', $linea_undergrad->expected_target)
  389. ->whereIn("semester_id", Session::get('semesters_ids'))
  390. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  391. //->addSelect("count(semester_id) as count_semester_id")
  392. //->groupBy("expected_target")
  393. ->orderBy("semester_id", "DESC")
  394. ->first();
  395. }
  396. return $linea_undergrad;
  397. }
  398. public function achieved_outcome($outcome_id, $semesters)
  399. {
  400. $semesters_array = [];
  401. foreach ($semesters as $semester) {
  402. $semesters_array[] = $semester->id;
  403. }
  404. // DB::enableQueryLog();
  405. // dd(DB::getQueryLog());
  406. // $criteria=DB::table('new_criteria')
  407. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  408. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  409. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  410. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  411. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  412. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  413. // ->where('programs.id','=',$this->id)
  414. // ->whereIn('courses.semester_id',$semesters_array)
  415. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  416. // ->distinct()
  417. // ->get()
  418. // ;
  419. $criteria = DB::table('criteria')
  420. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  421. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  422. ->join('courses', 'activities.course_id', '=', 'courses.id')
  423. ->join('programs', 'programs.id', '=', 'courses.program_id')
  424. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  425. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  426. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  427. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  428. ->where('programs.id', '=', $this->id)
  429. ->whereIn('courses.semester_id', $semesters_array)
  430. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  431. ->distinct()
  432. ->get();
  433. // dd(DB::getQueryLog());
  434. $conteo = 0;
  435. $attempted_criteria_per_program_array = [];
  436. // $students_attempted=0;
  437. // $students_achieved=0;
  438. foreach ($criteria as $criterion) {
  439. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  440. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  441. $attempted_criteria_per_program_array[$criterion->id] = 1;
  442. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  443. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  444. }
  445. // var_dump($this->id);
  446. // if(isset($students_attempted))var_dump($students_attempted);
  447. // else{print "aqui hay algo";}
  448. // print "<br>";
  449. // if(isset($students_achieved))var_dump($students_achieved);
  450. // print "<br>";
  451. // print "<br>";
  452. // exit();
  453. if (isset($students_attempted)) {
  454. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  455. if ($students_attempted_n) {
  456. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  457. } else {
  458. $percentage_students_who_achieved = 0;
  459. }
  460. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  461. $conteo++;
  462. }
  463. }
  464. }
  465. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  466. $achievedProgramOutcome = 0;
  467. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  468. // var_dump($outcome->expected_outcome);
  469. // exit();
  470. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  471. $achievedProgramOutcome = 1;
  472. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  473. }
  474. return $achievedProgramOutcome;
  475. }
  476. public static function generalComponentPrograms()
  477. {
  478. return self::whereIn('id', array(123, 124, 125, 126, 127, 128, 129))->get();
  479. }
  480. public function assessmentOverview()
  481. {
  482. $assessment_overview = array();
  483. $assessment_overview['program_courses'] = $this->courses;
  484. $outcomeCount = Outcome::all()->count();
  485. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  486. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  487. $assessment_overview['assessed_courses_count'] = 0;
  488. foreach ($assessment_overview['program_courses'] as $course) {
  489. if ($course->outcomes_achieved != NULL) {
  490. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  491. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  492. for ($i = 1; $i <= count($assessment_overview['outcomes_attempted']); $i++) {
  493. $assessment_overview['outcomes_achieved'][$i] += $course_outcomes_achieved[$i];
  494. $assessment_overview['outcomes_attempted'][$i] += $course_outcomes_attempted[$i];
  495. }
  496. $assessment_overview['assessed_courses_count'] += 1;
  497. }
  498. }
  499. /**
  500. * List of grouped courses (grouped sections)
  501. */
  502. $assessment_overview['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  503. ->with('semester')
  504. ->with('program')
  505. ->where('program_id', $this->id)
  506. ->whereIn('semester_id', Session::get('semesters_ids'))
  507. ->groupBy(array('code', 'number', 'semester_id'))
  508. ->orderBy('code')
  509. ->orderBy('number')
  510. ->orderBy('semester_id')
  511. ->get();
  512. Log::info(Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  513. ->with('semester')
  514. ->with('program')
  515. ->where('program_id', $this->id)
  516. ->whereIn('semester_id', Session::get('semesters_ids'))
  517. ->groupBy(array('code', 'number', 'semester_id'))
  518. ->orderBy('code')
  519. ->orderBy('number')
  520. ->orderBy('semester_id')
  521. ->toSql());
  522. return $assessment_overview;
  523. }
  524. }