Sin descripción

Outcome.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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 objectives()
  225. {
  226. return $this->hasMany('Objective');
  227. // return $this->belongsToMany('Objective', 'objective_outcome');
  228. }
  229. public function scopeObjectivesFromProgram($query, $programs)
  230. {
  231. return Objective::join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  232. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  233. //->join('programs', 'programs.id', '=', 'objective_program.program_id')
  234. ->whereIn("program_id", $programs)
  235. ->where('outcome_id', $this->id)
  236. ->where('objective_program.objective_id', '<>', '0')
  237. ->select('objectives.*')
  238. ->groupBy('objectives.id');
  239. }
  240. // public function attempted($semester, $is_grad)
  241. // {
  242. // return DB::table('new_criteria')
  243. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  244. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  245. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  246. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  247. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  248. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  249. // ->where('programs.is_graduate','=',$is_grad)
  250. // ->where('courses.semester_id','=',$semester)
  251. // ->count(DB::raw('DISTINCT new_criteria.id,activity_criterion.activity_id'))
  252. // ;
  253. //
  254. // }
  255. // public function attempted($semester, $is_grad)
  256. // {
  257. // $criteria=DB::table('new_criteria')
  258. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  259. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  260. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  261. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  262. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  263. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  264. // ->where('programs.is_graduate','=',$is_grad)
  265. // ->where('courses.semester_id','=',$semester)
  266. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  267. // ->distinct()
  268. // ->get()
  269. // ;
  270. // $conteo=0;
  271. // foreach($criteria as $criterion)
  272. // {
  273. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  274. // if($students_attempted)
  275. // {
  276. // $conteo++;
  277. // }
  278. // }
  279. // return $conteo;
  280. // }
  281. public static function active_by_semesters($selected_semesters, $level)
  282. {
  283. $min_start = "9000-01-01 00:00:00";
  284. $max_end = "1000-01-01 00:00:00";
  285. foreach ($selected_semesters as $semester) {
  286. if ($min_start > $semester->start) {
  287. $min_start = $semester->start;
  288. }
  289. if ($max_end < $semester->end) {
  290. $max_end = $semester->end;
  291. }
  292. }
  293. $outcomes = Outcome::where(function ($query) use ($min_start) {
  294. $query->where('deactivation_date', '>=', $min_start)
  295. ->orWhere('deactivation_date', null);
  296. })
  297. ->where('activation_date', '<=', $max_end)
  298. ->where(function ($query2) use ($level) {
  299. $query2->where("level", $level + 1)
  300. ->orWhere("level", 3);
  301. })
  302. ->orderBy('name', 'ASC')
  303. ->get();
  304. // return array('outcomes'=>$outcomes,'outcomes_attempted'=>$outcomes_attempted, 'outcomes_achieved'=>$outcomes_achieved, 'attemptedProgramsPerOutcome'=>$attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome'=>$achievedProgramsPerOutcome,'participating_programs'=>$participating_programs);
  305. return $outcomes;
  306. }
  307. public function programs_attempted($semesters)
  308. {
  309. $semesters_array = [];
  310. foreach ($semesters as $semester) {
  311. $semesters_array[] = $semester->id;
  312. }
  313. // $programs=DB::table('programs')
  314. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  315. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  316. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  317. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  318. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  319. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  320. // ->whereIn('courses.semester_id',$semesters_array)
  321. // ->distinct()
  322. // ->select('programs.id')
  323. // ->get()
  324. // ;
  325. $programs = DB::table('programs')
  326. ->join('courses', 'programs.id', '=', 'courses.program_id')
  327. ->join('activities', 'activities.course_id', '=', 'courses.id')
  328. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  329. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  330. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  331. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  332. ->whereIn('courses.semester_id', $semesters_array)
  333. ->distinct()
  334. ->select('programs.id')
  335. ->get();
  336. return $programs;
  337. }
  338. public function programs_attempted_in_school($semesters, $school_id)
  339. {
  340. $semesters_array = [];
  341. foreach ($semesters as $semester) {
  342. $semesters_array[] = $semester->id;
  343. }
  344. // $programs=DB::table('programs')
  345. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  346. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  347. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  348. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  349. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  350. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  351. // ->whereIn('courses.semester_id',$semesters_array)
  352. // ->distinct()
  353. // ->select('programs.id')
  354. // ->get()
  355. // ;
  356. $programs = DB::table('programs')
  357. ->join('courses', 'programs.id', '=', 'courses.program_id')
  358. ->join('activities', 'activities.course_id', '=', 'courses.id')
  359. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  360. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  361. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  362. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  363. ->where('programs.school_id', '=', $school_id)
  364. ->whereIn('courses.semester_id', $semesters_array)
  365. ->distinct()
  366. ->select('programs.id')
  367. ->get();
  368. return $programs;
  369. }
  370. public function attempted($semesters, $is_grad)
  371. {
  372. $semesters_array = [];
  373. foreach ($semesters as $semester) {
  374. $semesters_array[] = $semester->id;
  375. }
  376. // $criteria=DB::table('new_criteria')
  377. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  378. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  379. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  380. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  381. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  382. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  383. // ->where('programs.is_graduate','=',$is_grad)
  384. // ->whereIn('courses.semester_id',$semesters_array)
  385. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  386. // ->distinct()
  387. // ->get()
  388. // ;
  389. $criteria = DB::table('criteria')
  390. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  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('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  395. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  396. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  397. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  398. ->where('programs.is_graduate', '=', $is_grad)
  399. ->whereIn('courses.semester_id', $semesters_array)
  400. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  401. ->distinct()
  402. ->get();
  403. $conteo = 0;
  404. foreach ($criteria as $criterion) {
  405. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  406. if ($students_attempted) {
  407. $conteo++;
  408. }
  409. }
  410. // var_dump($conteo);
  411. // exit();
  412. return $conteo;
  413. }
  414. public function attempted_by_school($semesters, $school_id, $is_grad)
  415. {
  416. $semesters_array = [];
  417. foreach ($semesters as $semester) {
  418. $semesters_array[] = $semester->id;
  419. }
  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','=',$this->id)
  427. // ->where('programs.is_graduate','=',$is_grad)
  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('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  439. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  440. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  441. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  442. ->where('programs.is_graduate', '=', $is_grad)
  443. ->where('programs.school_id', '=', $school_id)
  444. ->whereIn('courses.semester_id', $semesters_array)
  445. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  446. ->distinct()
  447. ->get();
  448. $conteo = 0;
  449. foreach ($criteria as $criterion) {
  450. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  451. if ($students_attempted) {
  452. $conteo++;
  453. }
  454. }
  455. // var_dump($conteo);
  456. // exit();
  457. return $conteo;
  458. }
  459. public function attempted_by_program($semesters, $program_id, $is_grad)
  460. {
  461. $semesters_array = [];
  462. foreach ($semesters as $semester) {
  463. $semesters_array[] = $semester->id;
  464. }
  465. // $criteria=DB::table('new_criteria')
  466. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  467. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  468. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  469. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  470. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  471. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  472. // ->where('programs.is_graduate','=',$is_grad)
  473. // ->whereIn('courses.semester_id',$semesters_array)
  474. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  475. // ->distinct()
  476. // ->get()
  477. // ;
  478. $criteria = DB::table('criteria')
  479. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  480. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  481. ->join('courses', 'activities.course_id', '=', 'courses.id')
  482. ->join('programs', 'programs.id', '=', 'courses.program_id')
  483. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  484. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  485. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  486. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  487. ->where('programs.is_graduate', '=', $is_grad)
  488. ->where('programs.id', '=', $program_id)
  489. ->whereIn('courses.semester_id', $semesters_array)
  490. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  491. ->distinct()
  492. ->get();
  493. $conteo = 0;
  494. foreach ($criteria as $criterion) {
  495. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  496. if ($students_attempted) {
  497. $conteo++;
  498. }
  499. }
  500. // var_dump($conteo);
  501. // exit();
  502. return $conteo;
  503. }
  504. public function courses_attempted($courses)
  505. {
  506. $courses_array = [];
  507. foreach ($courses as $course) {
  508. // var_dump($course);
  509. // exit();
  510. $courses_array[] = $course->id;
  511. }
  512. // $criteria=DB::table('new_criteria')
  513. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  514. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  515. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  516. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  517. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  518. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  519. // ->whereIn('courses.id',$courses_array)
  520. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  521. // ->distinct()
  522. // ->get()
  523. // ;
  524. $criteria = DB::table('criteria')
  525. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  526. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  527. ->join('courses', 'activities.course_id', '=', 'courses.id')
  528. ->join('programs', 'programs.id', '=', 'courses.program_id')
  529. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  530. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  531. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  532. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  533. ->whereIn('courses.id', $courses_array)
  534. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  535. ->distinct()
  536. ->get();
  537. $conteo = 0;
  538. foreach ($criteria as $criterion) {
  539. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  540. if ($students_attempted) {
  541. $conteo++;
  542. }
  543. }
  544. // var_dump($conteo);
  545. // exit();
  546. return $conteo;
  547. }
  548. public function courses_achieved($courses)
  549. {
  550. $courses_array = [];
  551. foreach ($courses as $course) {
  552. $courses_array[] = $course->id;
  553. }
  554. // $criteria=DB::table('new_criteria')
  555. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  556. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  557. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  558. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  559. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  560. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  561. // ->whereIn('courses.id',$courses_array)
  562. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  563. // ->distinct()
  564. // ->get()
  565. // ;
  566. $criteria = DB::table('criteria')
  567. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  568. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  569. ->join('courses', 'activities.course_id', '=', 'courses.id')
  570. ->join('programs', 'programs.id', '=', 'courses.program_id')
  571. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  572. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  573. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  574. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  575. ->whereIn('courses.id', $courses_array)
  576. ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
  577. ->distinct()
  578. ->get();
  579. $conteo = 0;
  580. foreach ($criteria as $criterion) {
  581. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  582. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  583. if ($students_attempted) {
  584. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  585. } else {
  586. $percentage_students_who_achieved = 0;
  587. }
  588. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  589. $conteo++;
  590. }
  591. }
  592. return $conteo;
  593. }
  594. public function achieved($semesters, $is_grad)
  595. {
  596. $semesters_array = [];
  597. foreach ($semesters as $semester) {
  598. $semesters_array[] = $semester->id;
  599. }
  600. // DB::enableQueryLog();
  601. // $criteria=DB::table('new_criteria')
  602. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  603. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  604. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  605. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  606. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  607. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  608. // ->where('programs.is_graduate','=',$is_grad)
  609. // ->whereIn('courses.semester_id',$semesters_array)
  610. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  611. // ->distinct()
  612. // ->get()
  613. // ;
  614. $criteria = DB::table('criteria')
  615. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  616. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  617. ->join('courses', 'activities.course_id', '=', 'courses.id')
  618. ->join('programs', 'programs.id', '=', 'courses.program_id')
  619. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  620. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  621. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  622. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  623. ->where('programs.is_graduate', '=', $is_grad)
  624. ->whereIn('courses.semester_id', $semesters_array)
  625. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  626. ->distinct()
  627. ->get();
  628. // dd(DB::getQueryLog());
  629. $conteo = 0;
  630. foreach ($criteria as $criterion) {
  631. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  632. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  633. if ($students_attempted) {
  634. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  635. } else {
  636. $percentage_students_who_achieved = 0;
  637. }
  638. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  639. $conteo++;
  640. }
  641. }
  642. return $conteo;
  643. }
  644. public function achieved_by_school($semesters, $school_id, $is_grad)
  645. {
  646. $semesters_array = [];
  647. foreach ($semesters as $semester) {
  648. $semesters_array[] = $semester->id;
  649. }
  650. // DB::enableQueryLog();
  651. // $criteria=DB::table('new_criteria')
  652. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  653. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  654. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  655. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  656. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  657. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  658. // ->where('programs.is_graduate','=',$is_grad)
  659. // ->whereIn('courses.semester_id',$semesters_array)
  660. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  661. // ->distinct()
  662. // ->get()
  663. // ;
  664. $criteria = DB::table('criteria')
  665. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  666. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  667. ->join('courses', 'activities.course_id', '=', 'courses.id')
  668. ->join('programs', 'programs.id', '=', 'courses.program_id')
  669. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  670. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  671. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  672. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  673. ->where('programs.is_graduate', '=', $is_grad)
  674. ->where('programs.school_id', '=', $school_id)
  675. ->whereIn('courses.semester_id', $semesters_array)
  676. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  677. ->distinct()
  678. ->get();
  679. // dd(DB::getQueryLog());
  680. $conteo = 0;
  681. foreach ($criteria as $criterion) {
  682. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  683. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  684. if ($students_attempted) {
  685. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  686. } else {
  687. $percentage_students_who_achieved = 0;
  688. }
  689. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  690. $conteo++;
  691. }
  692. }
  693. return $conteo;
  694. }
  695. public function achieved_by_program($semesters, $program_id, $is_grad)
  696. {
  697. $semesters_array = [];
  698. foreach ($semesters as $semester) {
  699. $semesters_array[] = $semester->id;
  700. }
  701. // DB::enableQueryLog();
  702. // $criteria=DB::table('new_criteria')
  703. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  704. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  705. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  706. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  707. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  708. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  709. // ->where('programs.is_graduate','=',$is_grad)
  710. // ->whereIn('courses.semester_id',$semesters_array)
  711. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  712. // ->distinct()
  713. // ->get()
  714. // ;
  715. $criteria = DB::table('criteria')
  716. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  717. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  718. ->join('courses', 'activities.course_id', '=', 'courses.id')
  719. ->join('programs', 'programs.id', '=', 'courses.program_id')
  720. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  721. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  722. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  723. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  724. ->where('programs.is_graduate', '=', $is_grad)
  725. ->where('programs.school_.semester_id', $semesters_array)
  726. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  727. ->distinct()
  728. ->get();
  729. // dd(DB::getQueryLog());
  730. $conteo = 0;
  731. foreach ($criteria as $criterion) {
  732. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  733. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  734. if ($students_attempted) {
  735. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  736. } else {
  737. $percentage_students_who_achieved = 0;
  738. }
  739. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  740. $conteo++;
  741. }
  742. }
  743. return $conteo;
  744. }
  745. // public function achieved($semester, $is_grad)
  746. // {
  747. //
  748. // // DB::enableQueryLog();
  749. // $criteria=DB::table('criteria')
  750. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  751. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  752. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  753. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  754. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  755. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  756. // ->where('programs.is_graduate','=',$is_grad)
  757. // ->where('courses.semester_id','=',$semester)
  758. // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  759. // ->distinct()
  760. // ->get()
  761. // ;
  762. // // dd(DB::getQueryLog());
  763. //
  764. // $conteo=0;
  765. // foreach($criteria as $criterion)
  766. // {
  767. // $outcome_performance=DB::table('outcome_performance')
  768. // ->where('outcome_performance.outcome_id','=',$this->id)
  769. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  770. // ->where('outcome_performance.semester_id','=',$semester)
  771. // ->where('outcome_performance.level','=',$is_grad)
  772. // ->select('students_attempted','students_achieved')
  773. // ->first();
  774. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  775. // {
  776. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  777. // }
  778. // else
  779. // {
  780. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  781. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  782. //
  783. // if($students_attempted)
  784. // {
  785. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  786. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  787. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  788. // }
  789. // else
  790. // {
  791. // $percentage_students_who_achieved=0;
  792. // }
  793. // }
  794. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  795. // {
  796. // $conteo++;
  797. // }
  798. // }
  799. // return $conteo;
  800. // }
  801. //
  802. public static function active()
  803. {
  804. //TODO: Check when semester doesnt exist or session is empty
  805. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  806. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  807. }
  808. }