Ei kuvausta

Program.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. } else {
  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. ->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
  147. ->addSelect('program_criterion_objective_outcome.id as pcobo_id')
  148. ->where('program_id', $this->id)
  149. ->get();
  150. }
  151. }
  152. public function templates()
  153. {
  154. return $this->hasMany('Template');
  155. }
  156. public function activities()
  157. {
  158. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
  159. }
  160. public function publishedActivities()
  161. {
  162. return $this->hasManyThrough('Activity', 'Course')
  163. //->whereNotNull('activities.outcomes_attempted')
  164. ->where('activities.draft', 0)
  165. ->where('activities.diagnostic', 0)->whereIn('semester_id', Session::get('semesters_ids'));
  166. }
  167. public function assessesOutcome($outcome_id)
  168. {
  169. foreach ($this->publishedActivities as $activity) {
  170. $assessed = DB::table('activity_criterion')
  171. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  172. ->where('activity_id', $activity->id)
  173. ->first();
  174. if (!$assessed) continue;
  175. $outcomes_attempted = (array)$activity->o_att_array;
  176. if (array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0) {
  177. return true;
  178. }
  179. }
  180. return false;
  181. }
  182. // return the users that are pcoords for a program
  183. public function users()
  184. {
  185. return $this->belongsToMany('User');
  186. }
  187. public function objectives()
  188. {
  189. return $this->hasMany('Objective');
  190. }
  191. // Return learning objectives ordered by outcome
  192. public function objectivesByOutcome()
  193. {
  194. // Objective::
  195. $objectives = DB::table('outcomes')
  196. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  197. ->leftJoin('objectives', function ($join) {
  198. $join
  199. ->on('outcomes.id', '=', 'objectives.outcome_id')
  200. ->where('objectives.program_id', '=', $this->id);
  201. })
  202. ->orderBy('outcome_name', 'ASC')
  203. ->orderBy('objectives.text', 'ASC')
  204. ->get();
  205. return $objectives;
  206. }
  207. public function annualPlan()
  208. {
  209. return $this->hasMany("AnnualPlan");
  210. }
  211. public function hasObjectivesInOutcome($outcome_id)
  212. {
  213. return Objective::where('program_id', $this->id)
  214. ->where('outcome_id', $outcome_id)->count();
  215. }
  216. /**
  217. * Return all the criteria in/for the program, if any
  218. *
  219. * @return Illuminate\Database\Eloquent\Collection
  220. */
  221. /*
  222. public function criteria()
  223. {
  224. Log::info("AQUI");
  225. $lmao = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  226. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  227. ->where('program_id', $this->id)->get();
  228. return $lmao;
  229. $l = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  230. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  231. ->where('program_id', $this->id)->get();
  232. //get();
  233. }*/
  234. // public function attempted_outcome($outcome_id, $semester)
  235. // {
  236. // $conteo= DB::table('activity_criterion')
  237. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  238. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  239. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  240. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  241. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  242. // ->where('programs.id','=',$this->id)
  243. // ->where('courses.semester_id','=',$semester)
  244. // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  245. // ;
  246. // return $conteo;
  247. // }
  248. public function attempted_criteria_by_outcome($outcome_id, $semesters)
  249. {
  250. $semesters_array = [];
  251. foreach ($semesters as $semester) {
  252. $semesters_array[] = $semester->id;
  253. }
  254. $conteo = DB::table('activity_criterion')
  255. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  256. ->join('courses', 'activities.course_id', '=', 'courses.id')
  257. ->join('programs', 'programs.id', '=', 'courses.program_id')
  258. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  259. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  260. ->where('programs.id', '=', $this->id)
  261. ->whereIn('courses.semester_id', $semesters_array)
  262. ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'));
  263. return $conteo;
  264. }
  265. public function attempted_outcome($outcome_id, $semesters)
  266. {
  267. $semesters_array = [];
  268. foreach ($semesters as $semester) {
  269. $semesters_array[] = $semester->id;
  270. }
  271. $conteo = DB::table('activity_criterion')
  272. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  273. ->join('courses', 'activities.course_id', '=', 'courses.id')
  274. ->join('programs', 'programs.id', '=', 'courses.program_id')
  275. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  276. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  277. ->where('programs.id', '=', $this->id)
  278. ->whereIn('courses.semester_id', $semesters_array)
  279. ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'));
  280. Log::info(DB::table('activity_criterion')
  281. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  282. ->join('courses', 'activities.course_id', '=', 'courses.id')
  283. ->join('programs', 'programs.id', '=', 'courses.program_id')
  284. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  285. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  286. ->where('programs.id', '=', $this->id)
  287. ->whereIn('courses.semester_id', $semesters_array)
  288. ->toSql());
  289. return $conteo;
  290. }
  291. public function achieved_criteria_by_outcome($outcome_id, $semesters)
  292. {
  293. $semesters_array = [];
  294. foreach ($semesters as $semester) {
  295. $semesters_array[] = $semester->id;
  296. }
  297. // DB::enableQueryLog();
  298. // dd(DB::getQueryLog());
  299. // $criteria=DB::table('new_criteria')
  300. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  301. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  302. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  303. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  304. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  305. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  306. // ->where('programs.id','=',$this->id)
  307. // ->whereIn('courses.semester_id',$semesters_array)
  308. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  309. // ->distinct()
  310. // ->get()
  311. // ;
  312. $criteria = DB::table('criteria')
  313. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  314. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  315. ->join('courses', 'activities.course_id', '=', 'courses.id')
  316. ->join('programs', 'programs.id', '=', 'courses.program_id')
  317. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  318. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  319. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  320. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  321. ->where('programs.id', '=', $this->id)
  322. ->whereIn('courses.semester_id', $semesters_array)
  323. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  324. ->distinct()
  325. ->get();
  326. // dd(DB::getQueryLog());
  327. $conteo = 0;
  328. $attempted_criteria_per_program_array = [];
  329. // $students_attempted=0;
  330. // $students_achieved=0;
  331. foreach ($criteria as $criterion) {
  332. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  333. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  334. $attempted_criteria_per_program_array[$criterion->id] = 1;
  335. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  336. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  337. }
  338. // var_dump($outcome_id);
  339. // var_dump($this->id);
  340. // if(isset($students_attempted))var_dump($students_attempted);
  341. // else{print "aqui hay algo";}
  342. // print "<br>";
  343. // if(isset($students_achieved))var_dump($students_achieved);
  344. // print "<br>";
  345. // print "<br>";
  346. // exit();
  347. if (isset($students_attempted)) {
  348. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  349. if ($students_attempted_n) {
  350. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  351. } else {
  352. $percentage_students_who_achieved = 0;
  353. }
  354. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  355. $conteo++;
  356. }
  357. }
  358. }
  359. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  360. $achievedProgramOutcome = 0;
  361. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  362. // var_dump($outcome->expected_outcome);
  363. // exit();
  364. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  365. $achievedProgramOutcome = 1;
  366. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  367. }
  368. return $conteo;
  369. }
  370. //get linea outcome
  371. public function getExpectedOutcomeTargetAttribute()
  372. {
  373. //
  374. $linea_undergrad = DB::table('target_outcomes_program')
  375. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  376. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  377. ->where('program_id', $this->id)
  378. ->whereIn("semester_id", Session::get('semesters_ids'))
  379. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  380. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  381. ->groupBy("expected_target")
  382. ->orderBy("expected_target", "DESC")
  383. ->first();
  384. if (!isset($linea_undergrad)) {
  385. $linea_undergrad = null;
  386. } elseif ($linea_undergrad->count_semester_id > 1) {
  387. $linea_undergrad = DB::table('target_outcomes_program')
  388. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  389. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  390. ->where('program_id', $this->id)
  391. ->where('expected_target', $linea_undergrad->expected_target)
  392. ->whereIn("semester_id", Session::get('semesters_ids'))
  393. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  394. //->addSelect("count(semester_id) as count_semester_id")
  395. //->groupBy("expected_target")
  396. ->orderBy("semester_id", "DESC")
  397. ->first();
  398. }
  399. return $linea_undergrad;
  400. }
  401. public function achieved_outcome($outcome_id, $semesters)
  402. {
  403. $semesters_array = [];
  404. foreach ($semesters as $semester) {
  405. $semesters_array[] = $semester->id;
  406. }
  407. // DB::enableQueryLog();
  408. // dd(DB::getQueryLog());
  409. // $criteria=DB::table('new_criteria')
  410. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  411. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  412. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  413. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  414. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  415. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  416. // ->where('programs.id','=',$this->id)
  417. // ->whereIn('courses.semester_id',$semesters_array)
  418. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  419. // ->distinct()
  420. // ->get()
  421. // ;
  422. $criteria = DB::table('criteria')
  423. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  424. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  425. ->join('courses', 'activities.course_id', '=', 'courses.id')
  426. ->join('programs', 'programs.id', '=', 'courses.program_id')
  427. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  428. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  429. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  430. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  431. ->where('programs.id', '=', $this->id)
  432. ->whereIn('courses.semester_id', $semesters_array)
  433. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  434. ->distinct()
  435. ->get();
  436. // dd(DB::getQueryLog());
  437. $conteo = 0;
  438. $attempted_criteria_per_program_array = [];
  439. // $students_attempted=0;
  440. // $students_achieved=0;
  441. foreach ($criteria as $criterion) {
  442. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  443. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  444. $attempted_criteria_per_program_array[$criterion->id] = 1;
  445. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  446. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  447. }
  448. // var_dump($this->id);
  449. // if(isset($students_attempted))var_dump($students_attempted);
  450. // else{print "aqui hay algo";}
  451. // print "<br>";
  452. // if(isset($students_achieved))var_dump($students_achieved);
  453. // print "<br>";
  454. // print "<br>";
  455. // exit();
  456. if (isset($students_attempted)) {
  457. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  458. if ($students_attempted_n) {
  459. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  460. } else {
  461. $percentage_students_who_achieved = 0;
  462. }
  463. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  464. $conteo++;
  465. }
  466. }
  467. }
  468. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  469. $achievedProgramOutcome = 0;
  470. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  471. // var_dump($outcome->expected_outcome);
  472. // exit();
  473. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  474. $achievedProgramOutcome = 1;
  475. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  476. }
  477. return $achievedProgramOutcome;
  478. }
  479. public static function generalComponentPrograms()
  480. {
  481. return self::whereIn('id', array(123, 124, 125, 126, 127, 128, 129))->get();
  482. }
  483. public function assessmentOverview()
  484. {
  485. $assessment_overview = array();
  486. $assessment_overview['program_courses'] = $this->courses;
  487. $outcomeCount = Outcome::all()->count();
  488. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  489. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  490. $assessment_overview['assessed_courses_count'] = 0;
  491. foreach ($assessment_overview['program_courses'] as $course) {
  492. if ($course->outcomes_achieved != NULL) {
  493. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  494. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  495. for ($i = 1; $i <= count($assessment_overview['outcomes_attempted']); $i++) {
  496. $assessment_overview['outcomes_achieved'][$i] += $course_outcomes_achieved[$i];
  497. $assessment_overview['outcomes_attempted'][$i] += $course_outcomes_attempted[$i];
  498. }
  499. $assessment_overview['assessed_courses_count'] += 1;
  500. }
  501. }
  502. /**
  503. * List of grouped courses (grouped sections)
  504. */
  505. $assessment_overview['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  506. ->with('semester')
  507. ->with('program')
  508. ->where('program_id', $this->id)
  509. ->whereIn('semester_id', Session::get('semesters_ids'))
  510. ->groupBy(array('code', 'number', 'semester_id'))
  511. ->orderBy('code')
  512. ->orderBy('number')
  513. ->orderBy('semester_id')
  514. ->get();
  515. Log::info(Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  516. ->with('semester')
  517. ->with('program')
  518. ->where('program_id', $this->id)
  519. ->whereIn('semester_id', Session::get('semesters_ids'))
  520. ->groupBy(array('code', 'number', 'semester_id'))
  521. ->orderBy('code')
  522. ->orderBy('number')
  523. ->orderBy('semester_id')
  524. ->toSql());
  525. return $assessment_overview;
  526. }
  527. }