Brak opisu

Program.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. public function getCriteriaAttribute()
  133. {
  134. if ($this->outcome_id) {
  135. return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
  136. ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
  137. ->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
  138. ->addSelect('program_criterion_objective_outcome.id as pcobo_id')
  139. ->where('program_id', $this->id)
  140. ->where('outcome_id', $this->outcome_id)
  141. ->get();
  142. } else {
  143. return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
  144. ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
  145. ->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
  146. ->addSelect('program_criterion_objective_outcome.id as pcobo_id')
  147. ->where('program_id', $this->id)
  148. ->get();
  149. }
  150. }
  151. public function getCoursesWithAssessmentCountAttribute()
  152. {
  153. return DB::table('courses')
  154. ->join(DB::raw("(SELECT distinct courses.* from courses join activities on activities.course_id = courses.id join activity_criterion on activity_criterion.activity_id = activities.id join assessments on activity_criterion.id = assessments.activity_criterion_id) as q"), function ($j) {
  155. $j->on('q.semester_id', '=', 'courses.semester_id')
  156. ->on('q.program_id', '=', 'courses.program_id');
  157. })
  158. ->where('courses.program_id', $this->id)
  159. ->whereIn('courses.semester_id', Session::get('semesters_ids'))
  160. ->select(DB::raw('count(DISTINCT courses.id) as courses_program, count(DISTINCT q.id) as courses_assessed'))
  161. ->first();
  162. }
  163. public function getCoursesStudentsScorePerOutcomeAttribute()
  164. {
  165. $outcomes = Outcome::orderBy('name', 'asc')->get();
  166. $outcome_ids = DB::table("outcomes")
  167. ->whereNotNull('new_outcome_id')
  168. ->get();
  169. $combined_outcomes = [];
  170. foreach ($outcome_ids as $outcome) {
  171. $combined_outcomes[$outcome->id] = $outcome->new_outcome_id;
  172. }
  173. $array_to_send = [];
  174. $students = DB::table('assessments')
  175. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  176. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  177. ->join('courses', 'courses.id', '=', 'activities.course_id')
  178. ->join('students', 'students.id', '=', 'assessments.student_id')
  179. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  180. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  181. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  182. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  183. ->where('courses.program_id', $this->id)
  184. ->whereIn('semester_id', Session::get('semesters_ids'))
  185. ->where('semesters.is_visible', '=', 1)
  186. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  187. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  188. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  189. ->groupBy('students.id', 'outcome_id')
  190. ->get();
  191. $array_to_send['program_info'] = [];
  192. $array_to_send['program_info']['outcomes_attempted'] = [];
  193. $out_att = [];
  194. $out_ach = [];
  195. foreach ($outcomes as $outcome) {
  196. $out_att[$outcome->id] = 0;
  197. $out_ach[$outcome->id] = 0;
  198. }
  199. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  200. foreach ($students as $result) {
  201. $crit_att = $result->criteria_attempted;
  202. $crit_ach = $result->criteria_achieved;
  203. $out_att[$result->outcome_id] += 1;
  204. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  205. $out_ach[$result->outcome_id] += 1;
  206. }
  207. }
  208. $array_to_send['program_info']['outcomes_attempted_uncombined'] = $out_att;
  209. $array_to_send['program_info']['outcomes_achieved_uncombined'] = $out_ach;
  210. $the_processed_table = [];
  211. foreach ($students as $result) {
  212. $student_id = $result->student_id;
  213. $outcome_id = $result->outcome_id;
  214. if (isset($combined_outcomes[$outcome_id]))
  215. $outcome_id = $combined_outcomes[$outcome_id];
  216. if (!isset($the_processed_table[$student_id])) {
  217. $the_processed_table[$student_id] = [];
  218. }
  219. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  220. // los criterios, achieved y attempted
  221. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  222. $the_processed_table[$student_id][$outcome_id] = array(
  223. "criteria_attempted" => $result->criteria_attempted,
  224. "criteria_achieved" => $result->criteria_achieved
  225. );
  226. }
  227. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  228. //deprecated outcomes.
  229. else {
  230. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  231. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  232. }
  233. }
  234. //Log::info("ESTOY LOCO POR TI");
  235. //Log::info($the_processed_table);
  236. $out_att = [];
  237. $out_ach = [];
  238. foreach ($outcomes as $outcome) {
  239. $out_att[$outcome->id] = 0;
  240. $out_ach[$outcome->id] = 0;
  241. }
  242. foreach ($the_processed_table as $student_id => $outcome_ids) {
  243. //Log::info("AQUI");
  244. //Log::info($outcome_ids);
  245. foreach ($outcome_ids as $outcome_id => $crit_information) {
  246. //Log::info($crit_information);
  247. $crit_att = $crit_information['criteria_attempted'];
  248. $crit_ach = $crit_information['criteria_achieved'];
  249. $out_att[$outcome_id] += 1;
  250. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  251. $out_ach[$outcome_id] += 1;
  252. }
  253. }
  254. }
  255. $array_to_send['program_info']['outcomes_attempted_combined'] = $out_att;
  256. $array_to_send['program_info']['outcomes_achieved_combined'] = $out_ach;
  257. return $array_to_send;
  258. }
  259. public function templates()
  260. {
  261. return $this->hasMany('Template');
  262. }
  263. public function activities()
  264. {
  265. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
  266. }
  267. public function publishedActivities()
  268. {
  269. return $this->hasManyThrough('Activity', 'Course')
  270. //->whereNotNull('activities.outcomes_attempted')
  271. ->where('activities.draft', 0)
  272. ->where('activities.diagnostic', 0)->whereIn('semester_id', Session::get('semesters_ids'));
  273. }
  274. public function assessesOutcome($outcome_id)
  275. {
  276. foreach ($this->publishedActivities as $activity) {
  277. $assessed = DB::table('activity_criterion')
  278. ->join('assessments', 'assessments.activity_criterion_id', '=', 'activity_criterion.id')
  279. ->where('activity_id', $activity->id)
  280. ->first();
  281. if (!$assessed) continue;
  282. $outcomes_attempted = (array)$activity->o_att_array;
  283. if (array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0) {
  284. return true;
  285. }
  286. }
  287. return false;
  288. }
  289. // return the users that are pcoords for a program
  290. public function users()
  291. {
  292. return $this->belongsToMany('User');
  293. }
  294. public function objectives()
  295. {
  296. return $this->hasMany('Objective');
  297. }
  298. // Return learning objectives ordered by outcome
  299. public function objectivesByOutcome()
  300. {
  301. // Objective::
  302. $objectives = DB::table('outcomes')
  303. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  304. ->leftJoin('objectives', function ($join) {
  305. $join
  306. ->on('outcomes.id', '=', 'objectives.outcome_id')
  307. ->where('objectives.program_id', '=', $this->id);
  308. })
  309. ->orderBy('outcome_name', 'ASC')
  310. ->orderBy('objectives.text', 'ASC')
  311. ->get();
  312. return $objectives;
  313. }
  314. public function annualPlan()
  315. {
  316. return $this->hasMany("AnnualPlan");
  317. }
  318. public function hasObjectivesInOutcome($outcome_id)
  319. {
  320. return Objective::where('program_id', $this->id)
  321. ->where('outcome_id', $outcome_id)->count();
  322. }
  323. /**
  324. * Return all the criteria in/for the program, if any
  325. *
  326. * @return Illuminate\Database\Eloquent\Collection
  327. */
  328. /*
  329. public function criteria()
  330. {
  331. Log::info("AQUI");
  332. $lmao = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  333. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  334. ->where('program_id', $this->id)->get();
  335. return $lmao;
  336. $l = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
  337. ->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
  338. ->where('program_id', $this->id)->get();
  339. //get();
  340. }*/
  341. // public function attempted_outcome($outcome_id, $semester)
  342. // {
  343. // $conteo= DB::table('activity_criterion')
  344. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  345. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  346. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  347. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  348. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  349. // ->where('programs.id','=',$this->id)
  350. // ->where('courses.semester_id','=',$semester)
  351. // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  352. // ;
  353. // return $conteo;
  354. // }
  355. public function attempted_criteria_by_outcome($outcome_id, $semesters)
  356. {
  357. $semesters_array = [];
  358. foreach ($semesters as $semester) {
  359. $semesters_array[] = $semester->id;
  360. }
  361. $conteo = DB::table('activity_criterion')
  362. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  363. ->join('courses', 'activities.course_id', '=', 'courses.id')
  364. ->join('programs', 'programs.id', '=', 'courses.program_id')
  365. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  366. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  367. ->where('programs.id', '=', $this->id)
  368. ->whereIn('courses.semester_id', $semesters_array)
  369. ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'));
  370. return $conteo;
  371. }
  372. public function attempted_outcome($outcome_id, $semesters)
  373. {
  374. $semesters_array = [];
  375. foreach ($semesters as $semester) {
  376. $semesters_array[] = $semester->id;
  377. }
  378. $conteo = DB::table('activity_criterion')
  379. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  380. ->join('courses', 'activities.course_id', '=', 'courses.id')
  381. ->join('programs', 'programs.id', '=', 'courses.program_id')
  382. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  383. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  384. ->where('programs.id', '=', $this->id)
  385. ->whereIn('courses.semester_id', $semesters_array)
  386. ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'));
  387. /*
  388. Log::info(DB::table('activity_criterion')
  389. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  390. ->join('courses', 'activities.course_id', '=', 'courses.id')
  391. ->join('programs', 'programs.id', '=', 'courses.program_id')
  392. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  393. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  394. ->where('programs.id', '=', $this->id)
  395. ->whereIn('courses.semester_id', $semesters_array)
  396. ->toSql());
  397. */
  398. return $conteo;
  399. }
  400. public function achieved_criteria_by_outcome($outcome_id, $semesters)
  401. {
  402. $semesters_array = [];
  403. foreach ($semesters as $semester) {
  404. $semesters_array[] = $semester->id;
  405. }
  406. // DB::enableQueryLog();
  407. // dd(DB::getQueryLog());
  408. // $criteria=DB::table('new_criteria')
  409. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  410. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  411. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  412. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  413. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  414. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  415. // ->where('programs.id','=',$this->id)
  416. // ->whereIn('courses.semester_id',$semesters_array)
  417. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  418. // ->distinct()
  419. // ->get()
  420. // ;
  421. $criteria = DB::table('criteria')
  422. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  423. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  424. ->join('courses', 'activities.course_id', '=', 'courses.id')
  425. ->join('programs', 'programs.id', '=', 'courses.program_id')
  426. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  427. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  428. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  429. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  430. ->where('programs.id', '=', $this->id)
  431. ->whereIn('courses.semester_id', $semesters_array)
  432. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  433. ->distinct()
  434. ->get();
  435. // dd(DB::getQueryLog());
  436. $conteo = 0;
  437. $attempted_criteria_per_program_array = [];
  438. // $students_attempted=0;
  439. // $students_achieved=0;
  440. foreach ($criteria as $criterion) {
  441. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  442. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  443. $attempted_criteria_per_program_array[$criterion->id] = 1;
  444. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  445. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  446. }
  447. // var_dump($outcome_id);
  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 $conteo;
  478. }
  479. //get linea outcome
  480. public function getExpectedOutcomeTargetAttribute()
  481. {
  482. //
  483. $linea_undergrad = DB::table('target_outcomes_program')
  484. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  485. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  486. ->where('program_id', $this->id)
  487. ->whereIn("semester_id", Session::get('semesters_ids'))
  488. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  489. ->addSelect(DB::raw("count(target_outcomes_program.semester_id) as count_semester_id"))
  490. ->groupBy("expected_target")
  491. ->orderBy("expected_target", "DESC")
  492. ->first();
  493. if (!isset($linea_undergrad)) {
  494. $linea_undergrad = null;
  495. } elseif ($linea_undergrad->count_semester_id > 1) {
  496. $linea_undergrad = DB::table('target_outcomes_program')
  497. ->join('programs', 'programs.id', '=', 'target_outcomes_program.program_id')
  498. ->join('semesters', 'semesters.id', '=', 'target_outcomes_program.semester_id')
  499. ->where('program_id', $this->id)
  500. ->where('expected_target', $linea_undergrad->expected_target)
  501. ->whereIn("semester_id", Session::get('semesters_ids'))
  502. ->select("target_outcomes_program.*", 'programs.name as program_name', 'semesters.name as semester_name')
  503. //->addSelect("count(semester_id) as count_semester_id")
  504. //->groupBy("expected_target")
  505. ->orderBy("semester_id", "DESC")
  506. ->first();
  507. }
  508. return $linea_undergrad;
  509. }
  510. public function achieved_outcome($outcome_id, $semesters)
  511. {
  512. $semesters_array = [];
  513. foreach ($semesters as $semester) {
  514. $semesters_array[] = $semester->id;
  515. }
  516. // DB::enableQueryLog();
  517. // dd(DB::getQueryLog());
  518. // $criteria=DB::table('new_criteria')
  519. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  520. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  521. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  522. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  523. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  524. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  525. // ->where('programs.id','=',$this->id)
  526. // ->whereIn('courses.semester_id',$semesters_array)
  527. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  528. // ->distinct()
  529. // ->get()
  530. // ;
  531. $criteria = DB::table('criteria')
  532. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  533. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  534. ->join('courses', 'activities.course_id', '=', 'courses.id')
  535. ->join('programs', 'programs.id', '=', 'courses.program_id')
  536. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  537. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  538. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  539. ->where('criterion_objective_outcome.outcome_id', '=', $outcome_id)
  540. ->where('programs.id', '=', $this->id)
  541. ->whereIn('courses.semester_id', $semesters_array)
  542. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  543. ->distinct()
  544. ->get();
  545. // dd(DB::getQueryLog());
  546. $conteo = 0;
  547. $attempted_criteria_per_program_array = [];
  548. // $students_attempted=0;
  549. // $students_achieved=0;
  550. foreach ($criteria as $criterion) {
  551. if (!isset($students_attempted[$criterion->id])) $students_attempted[$criterion->id] = 0;
  552. if (!isset($students_achieved[$criterion->id])) $students_achieved[$criterion->id] = 0;
  553. $attempted_criteria_per_program_array[$criterion->id] = 1;
  554. $students_attempted[$criterion->id] += Criterion::students_attempted($criterion->id, $criterion->activity_id);
  555. $students_achieved[$criterion->id] += Criterion::students_achieved($criterion->id, $criterion->activity_id);
  556. }
  557. // var_dump($this->id);
  558. // if(isset($students_attempted))var_dump($students_attempted);
  559. // else{print "aqui hay algo";}
  560. // print "<br>";
  561. // if(isset($students_achieved))var_dump($students_achieved);
  562. // print "<br>";
  563. // print "<br>";
  564. // exit();
  565. if (isset($students_attempted)) {
  566. foreach ($students_attempted as $criteria_id => $students_attempted_n) {
  567. if ($students_attempted_n) {
  568. $percentage_students_who_achieved = 100.0 * $students_achieved[$criteria_id] / $students_attempted[$criteria_id];
  569. } else {
  570. $percentage_students_who_achieved = 0;
  571. }
  572. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  573. $conteo++;
  574. }
  575. }
  576. }
  577. $attempted_criteria_per_program = count($attempted_criteria_per_program_array);
  578. $achievedProgramOutcome = 0;
  579. $outcome = Outcome::where('id', $outcome_id)->select('expected_outcome')->first();
  580. // var_dump($outcome->expected_outcome);
  581. // exit();
  582. if ($attempted_criteria_per_program != 0 && 100.0 * $conteo / $attempted_criteria_per_program >= $outcome->expected_outcome) {
  583. $achievedProgramOutcome = 1;
  584. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  585. }
  586. return $achievedProgramOutcome;
  587. }
  588. public static function generalComponentPrograms()
  589. {
  590. return self::whereIn('id', array(123, 124, 125, 126, 127, 128, 129))->get();
  591. }
  592. public function assessmentOverview()
  593. {
  594. $assessment_overview = array();
  595. $assessment_overview['program_courses'] = $this->courses;
  596. $outcomeCount = Outcome::all()->count();
  597. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  598. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  599. $assessment_overview['assessed_courses_count'] = 0;
  600. foreach ($assessment_overview['program_courses'] as $course) {
  601. if ($course->outcomes_achieved != NULL) {
  602. $course_outcomes_achieved = json_decode($course->outcomes_achieved, true);
  603. $course_outcomes_attempted = json_decode($course->outcomes_attempted, true);
  604. for ($i = 1; $i <= count($assessment_overview['outcomes_attempted']); $i++) {
  605. $assessment_overview['outcomes_achieved'][$i] += $course_outcomes_achieved[$i];
  606. $assessment_overview['outcomes_attempted'][$i] += $course_outcomes_attempted[$i];
  607. }
  608. $assessment_overview['assessed_courses_count'] += 1;
  609. }
  610. }
  611. /**
  612. * List of grouped courses (grouped sections)
  613. */
  614. $assessment_overview['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  615. ->with('semester')
  616. ->with('program')
  617. ->where('program_id', $this->id)
  618. ->whereIn('semester_id', Session::get('semesters_ids'))
  619. ->groupBy(array('code', 'number', 'semester_id'))
  620. ->orderBy('code')
  621. ->orderBy('number')
  622. ->orderBy('semester_id')
  623. ->get();
  624. Log::info(Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  625. ->with('semester')
  626. ->with('program')
  627. ->where('program_id', $this->id)
  628. ->whereIn('semester_id', Session::get('semesters_ids'))
  629. ->groupBy(array('code', 'number', 'semester_id'))
  630. ->orderBy('code')
  631. ->orderBy('number')
  632. ->orderBy('semester_id')
  633. ->toSql());
  634. return $assessment_overview;
  635. }
  636. }