Няма описание

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