Ingen beskrivning

Outcome.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. <?php
  2. use Illuminate\Database\Eloquent\SoftDeletingTrait;
  3. class Outcome extends Eloquent
  4. {
  5. use SoftDeletingTrait;
  6. protected $dates = ['deleted_at'];
  7. protected $fillable = array('name', 'definition');
  8. protected $appends = array("annual_objectives");
  9. //dirty code, this belongs to annual plan, but outcome has the important data
  10. public function getExpectedTargetAttribute()
  11. {
  12. if (isset($this->semester_id) && isset($this->program_id)) {
  13. $expected_target = DB::table("target_outcomes_program")
  14. ->where('program_id', $this->program_id)
  15. ->where('semester_id', $this->semester_id)
  16. ->first();
  17. Log::info("PApi que hayy chabau");
  18. Log::info(array($expected_target));
  19. if ($expected_target != null) {
  20. Log::info("PApi no chabau");
  21. return $expected_target->expected_target;
  22. } else return "Go to Annual Plan and define a target for learning outcome";
  23. }
  24. Log::info("PApi rip chabau");
  25. return null;
  26. }
  27. //Dirty code sort of, la accion transformadora es para el programa, ppero esta bajo el dominio
  28. //tecnicamente esto es hasta del annual plan, pero na, outcomes bajo el annual plan van a tener
  29. // este atributo
  30. //program_transformative_actions
  31. public function getProgramTransformativeActionsAttribute()
  32. {
  33. /*$transformative_actions = DB::table('transformative_typ_outcome')
  34. ->where('typ_semester_outcome_id', $this->typ_semester_outcome_id)
  35. ->get();
  36. $trans_actions = [];
  37. foreach ($transformative_actions as $trans) {
  38. $ta = TransformativeAction::where('id', $trans->trans_id)->first();
  39. $ta->setAttribute('semester_id', $this->semester_id);
  40. $trans_actions[] = $ta;
  41. }
  42. return $trans_actions;*/
  43. return TransformativeAction::join('transformative_typ_outcome', 'transformative_typ_outcome.trans_id', '=', 'transformative_actions.id')
  44. ->where('typ_semester_outcome_id', $this->typ_semester_outcome_id)
  45. ->select('transformative_actions.*', DB::raw("{$this->semester_id} as semester_id"))
  46. ->get();
  47. }
  48. public function getCommentsAttribute()
  49. {
  50. return DB::table('typ_outcome_report_comments')
  51. ->where('typ_semester_outcome_id', $this->typ_semester_outcome_id)
  52. ->get();
  53. }
  54. // Son los resultados de los estudiantes por dominio, devuelve el percent.
  55. public function getStudentPerformanceAttribute()
  56. {
  57. //create Counter for students
  58. $whole_dict = [];
  59. foreach ($this->annual_objectives as $objective) {
  60. foreach ($objective->grouped_annual_course as $course_code) {
  61. Log::info("Existen los cursos");
  62. Log::info(json_encode($course_code));
  63. foreach ($course_code->student_report_for_outcome as $student) {
  64. //If is not defined, define
  65. if (!isset($whole_dict[$student->student_id])) {
  66. $whole_dict[$student->student_id] = array(
  67. 'student' => $student->student_id,
  68. 'criteria_attempted' => 0,
  69. 'criteria_achieved' => 0
  70. );
  71. }
  72. $whole_dict[$student->student_id]["criteria_attempted"] += $student->criteria_attempted;
  73. $whole_dict[$student->student_id]["criteria_achieved"] += $student->criteria_achieved;
  74. }
  75. }
  76. }
  77. $students_achieved = 0;
  78. $students_attempted = 0;
  79. Log::info('Outcome_content');
  80. Log::info($whole_dict);
  81. foreach ($whole_dict as $student) {
  82. if ($student['criteria_attempted']) {
  83. $students_attempted += 1;
  84. $percentage = (($student['criteria_achieved'] / $student['criteria_attempted']) * 100);
  85. if ($percentage >= $this->expected_outcome) {
  86. $students_achieved += 1;
  87. }
  88. }
  89. }
  90. if ($students_attempted != 0)
  91. return round(($students_achieved / $students_attempted) * 100, 2);
  92. else
  93. return "N/A";
  94. /*
  95. if (course_code.criteria.length) {
  96. $.each(course_code.students, function(index, student) {
  97. if (wholeDict[student.student_id] === undefined) {
  98. wholeDict[student.student_id] = {
  99. 'student': student.student_id,
  100. 'criteria_attempted': 0,
  101. 'criteria_achieved': 0
  102. }
  103. }
  104. wholeDict[student.student_id][
  105. "criteria_attempted"
  106. ] += student
  107. .criteria_attempted;
  108. wholeDict[student.student_id][
  109. "criteria_achieved"
  110. ] += student
  111. .criteria_achieved;
  112. });
  113. $.each(wholeDict, function(key, dict) {
  114. if (dict.criteria_attempted) {
  115. students_attempted += 1;
  116. percentage = ((dict.criteria_achieved / dict.criteria_attempted) * 100).toFixed(
  117. 2);
  118. if (parseFloat(percentage) >= parseFloat(outcome.expected_outcome)) {
  119. achieved = "Yes"
  120. students_achieved += 1;
  121. } else achieved = "No"
  122. } else {
  123. percentage = "N/A"
  124. achieved = "N/A"
  125. }
  126. tableStudent.row.add([
  127. dict.student,
  128. dict.criteria_attempted,
  129. dict.criteria_achieved,
  130. percentage,
  131. achieved
  132. ]);
  133. })
  134. */
  135. }
  136. public function criteria()
  137. {
  138. return $this->hasManyThrough('Criterion', 'Objective')->orderBy('name');
  139. }
  140. public function fetchObjectivesReport($semester_id, $program_id, $with_model = false)
  141. {
  142. /*$objectives = DB::table('typ_semester_outcome')
  143. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  144. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  145. ->join("typ_program", 'typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
  146. ->where('typ_semester_outcome.semester_id', $semester_id)
  147. ->where('typ_program.program_id', $program_id)
  148. ->where('typ_semester_outcome.outcome_id', $this->id)
  149. ->select('objectives.*')
  150. ->get();*/
  151. $objectives = DB::table('objectives')
  152. ->join('typ_semester_objectives', 'typ_semester_objectives.objective_id', '=', 'objectives.id')
  153. ->join('typ_semester_outcome', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  154. ->join('typ_program', 'typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
  155. ->where('semester_id', $semester_id)
  156. ->where('program_id', $program_id)
  157. ->where('outcome_id', $this->id)
  158. ->select('objectives.id as objective_id', 'objectives.text', 'typ_semester_objectives.id as typ_semester_objective_id', 'program_id', 'semester_id')
  159. ->distinct();
  160. Log::info('agooooo me');
  161. ////Log::info($objectives->toSql());
  162. //Log::info('semester_program_outcome' . $semester_id . ',' . $program_id . ',' . $this->id);
  163. if ($with_model) {
  164. Log::info("Acho aqui estamos en with_model");
  165. $objective_id = $objectives->lists('objective_id');
  166. $typ_semester_objective_ids = $objectives->lists('typ_semester_objective_id');
  167. //$program_id = $objectives->lists('program_id');
  168. //$semester_id = $objectives ->lists('semester_id');
  169. $objectives = Objective::whereIn("objectives.id", $objective_id);
  170. Log::info($objective_id);
  171. //Log::info(array($objectives));
  172. foreach ($objectives as $i => $o) {
  173. Log::info("entramos aqui tambien?");
  174. $o->setAttribute("typ_semester_objective_id", $typ_semester_objective_ids[$i]);
  175. $o->setAttribute("program_id", $program_id);
  176. $o->setAttribute("semester_id", $semester_id);
  177. }
  178. return $objectives;
  179. }
  180. return $objectives->get();
  181. }
  182. //Intento de get objectives pareados en un plan
  183. public function getAnnualObjectivesAttribute()
  184. {
  185. if (isset($this->typ_semester_outcome_id)) {
  186. /*Log::info('estamos aqui');
  187. $objectives = DB::table("typ_semester_objectives")
  188. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  189. ->where('typ_semester_outcome_id', $this->typ_semester_outcome_id)
  190. ->select('typ_semester_objectives.id as typ_semester_objective_id', 'objectives.id as objective_id')
  191. ->get();
  192. //$objectives_id = $objectives->lists('objective_id');
  193. //$typ_semester_objective_ids = $objectives->lists('typ_semester_objective_id');
  194. //$program_id = $objectives->lists('program_id');
  195. //$semester_id = $objectives ->lists('semester_id');
  196. //Log::info($this->typ_semester_outcome_id);
  197. //Log::info($objectives_id);
  198. $objectives_list = []; // Objective::whereIn("id", $objectives_id)->get();
  199. foreach ($objectives as $i => $ob) {
  200. $o = Objective::find($ob->objective_id);
  201. //Log::info("entramos aqui tambien?");
  202. $o->setAttribute("typ_semester_objective_id", $ob->typ_semester_objective_id); //$typ_semester_objective_ids[$i]);
  203. $o->setAttribute("semester_id", $this->semester_id);
  204. $o->setAttribute('program_id', $this->program_id);
  205. $objectives_list[] = $o;
  206. }
  207. return $objectives_list;*/
  208. return Objective::join("typ_semester_objectives", 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  209. ->where('typ_semester_outcome_id', $this->typ_semester_outcome_id)
  210. ->select(
  211. 'typ_semester_objectives.id as typ_semester_objective_id',
  212. 'objectives.id as objective_id',
  213. 'objectives.*',
  214. DB::raw("{$this->semester_id} as semester_id"),
  215. DB::raw("{$this->program_id} as program_id")
  216. )
  217. ->get();
  218. //return $objectives;
  219. }
  220. Log::info("Lol");
  221. return null;
  222. }
  223. /**
  224. * Return the objectives that the outcome belongs to
  225. *
  226. * @return Illuminate\Database\Eloquent\Model
  227. */
  228. public function objectives()
  229. {
  230. return $this->hasMany('Objective');
  231. // return $this->belongsToMany('Objective', 'objective_outcome');
  232. }
  233. // public function attempted($semester, $is_grad)
  234. // {
  235. // return DB::table('new_criteria')
  236. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  237. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  238. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  239. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  240. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  241. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  242. // ->where('programs.is_graduate','=',$is_grad)
  243. // ->where('courses.semester_id','=',$semester)
  244. // ->count(DB::raw('DISTINCT new_criteria.id,activity_criterion.activity_id'))
  245. // ;
  246. //
  247. // }
  248. // public function attempted($semester, $is_grad)
  249. // {
  250. // $criteria=DB::table('new_criteria')
  251. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  252. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  253. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  254. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  255. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  256. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  257. // ->where('programs.is_graduate','=',$is_grad)
  258. // ->where('courses.semester_id','=',$semester)
  259. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  260. // ->distinct()
  261. // ->get()
  262. // ;
  263. // $conteo=0;
  264. // foreach($criteria as $criterion)
  265. // {
  266. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  267. // if($students_attempted)
  268. // {
  269. // $conteo++;
  270. // }
  271. // }
  272. // return $conteo;
  273. // }
  274. public static function active_by_semesters($selected_semesters, $level)
  275. {
  276. $min_start = "9000-01-01 00:00:00";
  277. $max_end = "1000-01-01 00:00:00";
  278. foreach ($selected_semesters as $semester) {
  279. if ($min_start > $semester->start) {
  280. $min_start = $semester->start;
  281. }
  282. if ($max_end < $semester->end) {
  283. $max_end = $semester->end;
  284. }
  285. }
  286. $outcomes = Outcome::where(function ($query) use ($min_start) {
  287. $query->where('deactivation_date', '>=', $min_start)
  288. ->orWhere('deactivation_date', null);
  289. })
  290. ->where('activation_date', '<=', $max_end)
  291. ->where(function ($query2) use ($level) {
  292. $query2->where("level", $level + 1)
  293. ->orWhere("level", 3);
  294. })
  295. ->orderBy('name', 'ASC')
  296. ->get();
  297. // return array('outcomes'=>$outcomes,'outcomes_attempted'=>$outcomes_attempted, 'outcomes_achieved'=>$outcomes_achieved, 'attemptedProgramsPerOutcome'=>$attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome'=>$achievedProgramsPerOutcome,'participating_programs'=>$participating_programs);
  298. return $outcomes;
  299. }
  300. public function programs_attempted($semesters)
  301. {
  302. $semesters_array = [];
  303. foreach ($semesters as $semester) {
  304. $semesters_array[] = $semester->id;
  305. }
  306. // $programs=DB::table('programs')
  307. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  308. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  309. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  310. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  311. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  312. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  313. // ->whereIn('courses.semester_id',$semesters_array)
  314. // ->distinct()
  315. // ->select('programs.id')
  316. // ->get()
  317. // ;
  318. $programs = DB::table('programs')
  319. ->join('courses', 'programs.id', '=', 'courses.program_id')
  320. ->join('activities', 'activities.course_id', '=', 'courses.id')
  321. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  322. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  323. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  324. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  325. ->whereIn('courses.semester_id', $semesters_array)
  326. ->distinct()
  327. ->select('programs.id')
  328. ->get();
  329. return $programs;
  330. }
  331. public function programs_attempted_in_school($semesters, $school_id)
  332. {
  333. $semesters_array = [];
  334. foreach ($semesters as $semester) {
  335. $semesters_array[] = $semester->id;
  336. }
  337. // $programs=DB::table('programs')
  338. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  339. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  340. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  341. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  342. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  343. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  344. // ->whereIn('courses.semester_id',$semesters_array)
  345. // ->distinct()
  346. // ->select('programs.id')
  347. // ->get()
  348. // ;
  349. $programs = DB::table('programs')
  350. ->join('courses', 'programs.id', '=', 'courses.program_id')
  351. ->join('activities', 'activities.course_id', '=', 'courses.id')
  352. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  353. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  354. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  355. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  356. ->where('programs.school_id', '=', $school_id)
  357. ->whereIn('courses.semester_id', $semesters_array)
  358. ->distinct()
  359. ->select('programs.id')
  360. ->get();
  361. return $programs;
  362. }
  363. public function attempted($semesters, $is_grad)
  364. {
  365. $semesters_array = [];
  366. foreach ($semesters as $semester) {
  367. $semesters_array[] = $semester->id;
  368. }
  369. // $criteria=DB::table('new_criteria')
  370. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  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', '=', 'new_criteria.id')
  375. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  376. // ->where('programs.is_graduate','=',$is_grad)
  377. // ->whereIn('courses.semester_id',$semesters_array)
  378. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  379. // ->distinct()
  380. // ->get()
  381. // ;
  382. $criteria = DB::table('criteria')
  383. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  384. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  385. ->join('courses', 'activities.course_id', '=', 'courses.id')
  386. ->join('programs', 'programs.id', '=', 'courses.program_id')
  387. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  388. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  389. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  390. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  391. ->where('programs.is_graduate', '=', $is_grad)
  392. ->whereIn('courses.semester_id', $semesters_array)
  393. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  394. ->distinct()
  395. ->get();
  396. $conteo = 0;
  397. foreach ($criteria as $criterion) {
  398. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  399. if ($students_attempted) {
  400. $conteo++;
  401. }
  402. }
  403. // var_dump($conteo);
  404. // exit();
  405. return $conteo;
  406. }
  407. public function attempted_by_school($semesters, $school_id, $is_grad)
  408. {
  409. $semesters_array = [];
  410. foreach ($semesters as $semester) {
  411. $semesters_array[] = $semester->id;
  412. }
  413. // $criteria=DB::table('new_criteria')
  414. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  415. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  416. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  417. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  418. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  419. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  420. // ->where('programs.is_graduate','=',$is_grad)
  421. // ->whereIn('courses.semester_id',$semesters_array)
  422. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  423. // ->distinct()
  424. // ->get()
  425. // ;
  426. $criteria = DB::table('criteria')
  427. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  428. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  429. ->join('courses', 'activities.course_id', '=', 'courses.id')
  430. ->join('programs', 'programs.id', '=', 'courses.program_id')
  431. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  432. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  433. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  434. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  435. ->where('programs.is_graduate', '=', $is_grad)
  436. ->where('programs.school_id', '=', $school_id)
  437. ->whereIn('courses.semester_id', $semesters_array)
  438. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  439. ->distinct()
  440. ->get();
  441. $conteo = 0;
  442. foreach ($criteria as $criterion) {
  443. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  444. if ($students_attempted) {
  445. $conteo++;
  446. }
  447. }
  448. // var_dump($conteo);
  449. // exit();
  450. return $conteo;
  451. }
  452. public function attempted_by_program($semesters, $program_id, $is_grad)
  453. {
  454. $semesters_array = [];
  455. foreach ($semesters as $semester) {
  456. $semesters_array[] = $semester->id;
  457. }
  458. // $criteria=DB::table('new_criteria')
  459. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  460. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  461. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  462. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  463. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  464. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  465. // ->where('programs.is_graduate','=',$is_grad)
  466. // ->whereIn('courses.semester_id',$semesters_array)
  467. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  468. // ->distinct()
  469. // ->get()
  470. // ;
  471. $criteria = DB::table('criteria')
  472. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  473. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  474. ->join('courses', 'activities.course_id', '=', 'courses.id')
  475. ->join('programs', 'programs.id', '=', 'courses.program_id')
  476. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  477. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  478. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  479. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  480. ->where('programs.is_graduate', '=', $is_grad)
  481. ->where('programs.id', '=', $program_id)
  482. ->whereIn('courses.semester_id', $semesters_array)
  483. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  484. ->distinct()
  485. ->get();
  486. $conteo = 0;
  487. foreach ($criteria as $criterion) {
  488. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  489. if ($students_attempted) {
  490. $conteo++;
  491. }
  492. }
  493. // var_dump($conteo);
  494. // exit();
  495. return $conteo;
  496. }
  497. public function courses_attempted($courses)
  498. {
  499. $courses_array = [];
  500. foreach ($courses as $course) {
  501. // var_dump($course);
  502. // exit();
  503. $courses_array[] = $course->id;
  504. }
  505. // $criteria=DB::table('new_criteria')
  506. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  507. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  508. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  509. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  510. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  511. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  512. // ->whereIn('courses.id',$courses_array)
  513. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  514. // ->distinct()
  515. // ->get()
  516. // ;
  517. $criteria = DB::table('criteria')
  518. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  519. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  520. ->join('courses', 'activities.course_id', '=', 'courses.id')
  521. ->join('programs', 'programs.id', '=', 'courses.program_id')
  522. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  523. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  524. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  525. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  526. ->whereIn('courses.id', $courses_array)
  527. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  528. ->distinct()
  529. ->get();
  530. $conteo = 0;
  531. foreach ($criteria as $criterion) {
  532. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  533. if ($students_attempted) {
  534. $conteo++;
  535. }
  536. }
  537. // var_dump($conteo);
  538. // exit();
  539. return $conteo;
  540. }
  541. public function courses_achieved($courses)
  542. {
  543. $courses_array = [];
  544. foreach ($courses as $course) {
  545. $courses_array[] = $course->id;
  546. }
  547. // $criteria=DB::table('new_criteria')
  548. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  549. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  550. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  551. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  552. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  553. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  554. // ->whereIn('courses.id',$courses_array)
  555. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  556. // ->distinct()
  557. // ->get()
  558. // ;
  559. $criteria = DB::table('criteria')
  560. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  561. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  562. ->join('courses', 'activities.course_id', '=', 'courses.id')
  563. ->join('programs', 'programs.id', '=', 'courses.program_id')
  564. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  565. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  566. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  567. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  568. ->whereIn('courses.id', $courses_array)
  569. ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
  570. ->distinct()
  571. ->get();
  572. $conteo = 0;
  573. foreach ($criteria as $criterion) {
  574. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  575. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  576. if ($students_attempted) {
  577. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  578. } else {
  579. $percentage_students_who_achieved = 0;
  580. }
  581. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  582. $conteo++;
  583. }
  584. }
  585. return $conteo;
  586. }
  587. public function achieved($semesters, $is_grad)
  588. {
  589. $semesters_array = [];
  590. foreach ($semesters as $semester) {
  591. $semesters_array[] = $semester->id;
  592. }
  593. // DB::enableQueryLog();
  594. // $criteria=DB::table('new_criteria')
  595. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  596. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  597. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  598. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  599. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  600. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  601. // ->where('programs.is_graduate','=',$is_grad)
  602. // ->whereIn('courses.semester_id',$semesters_array)
  603. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  604. // ->distinct()
  605. // ->get()
  606. // ;
  607. $criteria = DB::table('criteria')
  608. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  609. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  610. ->join('courses', 'activities.course_id', '=', 'courses.id')
  611. ->join('programs', 'programs.id', '=', 'courses.program_id')
  612. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  613. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  614. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  615. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  616. ->where('programs.is_graduate', '=', $is_grad)
  617. ->whereIn('courses.semester_id', $semesters_array)
  618. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  619. ->distinct()
  620. ->get();
  621. // dd(DB::getQueryLog());
  622. $conteo = 0;
  623. foreach ($criteria as $criterion) {
  624. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  625. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  626. if ($students_attempted) {
  627. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  628. } else {
  629. $percentage_students_who_achieved = 0;
  630. }
  631. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  632. $conteo++;
  633. }
  634. }
  635. return $conteo;
  636. }
  637. public function achieved_by_school($semesters, $school_id, $is_grad)
  638. {
  639. $semesters_array = [];
  640. foreach ($semesters as $semester) {
  641. $semesters_array[] = $semester->id;
  642. }
  643. // DB::enableQueryLog();
  644. // $criteria=DB::table('new_criteria')
  645. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  646. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  647. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  648. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  649. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  650. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  651. // ->where('programs.is_graduate','=',$is_grad)
  652. // ->whereIn('courses.semester_id',$semesters_array)
  653. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  654. // ->distinct()
  655. // ->get()
  656. // ;
  657. $criteria = DB::table('criteria')
  658. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  659. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  660. ->join('courses', 'activities.course_id', '=', 'courses.id')
  661. ->join('programs', 'programs.id', '=', 'courses.program_id')
  662. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  663. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  664. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  665. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  666. ->where('programs.is_graduate', '=', $is_grad)
  667. ->where('programs.school_id', '=', $school_id)
  668. ->whereIn('courses.semester_id', $semesters_array)
  669. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  670. ->distinct()
  671. ->get();
  672. // dd(DB::getQueryLog());
  673. $conteo = 0;
  674. foreach ($criteria as $criterion) {
  675. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  676. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  677. if ($students_attempted) {
  678. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  679. } else {
  680. $percentage_students_who_achieved = 0;
  681. }
  682. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  683. $conteo++;
  684. }
  685. }
  686. return $conteo;
  687. }
  688. public function achieved_by_program($semesters, $program_id, $is_grad)
  689. {
  690. $semesters_array = [];
  691. foreach ($semesters as $semester) {
  692. $semesters_array[] = $semester->id;
  693. }
  694. // DB::enableQueryLog();
  695. // $criteria=DB::table('new_criteria')
  696. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  697. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  698. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  699. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  700. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  701. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  702. // ->where('programs.is_graduate','=',$is_grad)
  703. // ->whereIn('courses.semester_id',$semesters_array)
  704. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  705. // ->distinct()
  706. // ->get()
  707. // ;
  708. $criteria = DB::table('criteria')
  709. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  710. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  711. ->join('courses', 'activities.course_id', '=', 'courses.id')
  712. ->join('programs', 'programs.id', '=', 'courses.program_id')
  713. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  714. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  715. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  716. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  717. ->where('programs.is_graduate', '=', $is_grad)
  718. ->where('programs.school_.semester_id', $semesters_array)
  719. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  720. ->distinct()
  721. ->get();
  722. // dd(DB::getQueryLog());
  723. $conteo = 0;
  724. foreach ($criteria as $criterion) {
  725. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  726. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  727. if ($students_attempted) {
  728. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  729. } else {
  730. $percentage_students_who_achieved = 0;
  731. }
  732. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  733. $conteo++;
  734. }
  735. }
  736. return $conteo;
  737. }
  738. // public function achieved($semester, $is_grad)
  739. // {
  740. //
  741. // // DB::enableQueryLog();
  742. // $criteria=DB::table('criteria')
  743. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  744. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  745. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  746. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  747. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  748. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  749. // ->where('programs.is_graduate','=',$is_grad)
  750. // ->where('courses.semester_id','=',$semester)
  751. // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  752. // ->distinct()
  753. // ->get()
  754. // ;
  755. // // dd(DB::getQueryLog());
  756. //
  757. // $conteo=0;
  758. // foreach($criteria as $criterion)
  759. // {
  760. // $outcome_performance=DB::table('outcome_performance')
  761. // ->where('outcome_performance.outcome_id','=',$this->id)
  762. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  763. // ->where('outcome_performance.semester_id','=',$semester)
  764. // ->where('outcome_performance.level','=',$is_grad)
  765. // ->select('students_attempted','students_achieved')
  766. // ->first();
  767. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  768. // {
  769. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  770. // }
  771. // else
  772. // {
  773. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  774. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  775. //
  776. // if($students_attempted)
  777. // {
  778. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  779. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  780. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  781. // }
  782. // else
  783. // {
  784. // $percentage_students_who_achieved=0;
  785. // }
  786. // }
  787. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  788. // {
  789. // $conteo++;
  790. // }
  791. // }
  792. // return $conteo;
  793. // }
  794. //
  795. public static function active()
  796. {
  797. //TODO: Check when semester doesnt exist or session is empty
  798. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  799. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  800. }
  801. }