Нема описа

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