Ingen beskrivning

Outcome.php 38KB

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