Без опису

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