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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. public function criteria()
  9. {
  10. return $this->hasManyThrough('Criterion', 'Objective')->orderBy('name');
  11. }
  12. public function fetchObjectivesReport($semester_id, $program_id)
  13. {
  14. /*$objectives = DB::table('typ_semester_outcome')
  15. ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
  16. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  17. ->join("typ_program", 'typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
  18. ->where('typ_semester_outcome.semester_id', $semester_id)
  19. ->where('typ_program.program_id', $program_id)
  20. ->where('typ_semester_outcome.outcome_id', $this->id)
  21. ->select('objectives.*')
  22. ->get();*/
  23. $objectives = DB::table('objectives')
  24. ->join('typ_semester_objectives', 'typ_semester_objectives.objective_id', '=', 'objectives.id')
  25. ->join('typ_semester_outcome', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  26. ->join('typ_program', 'typ_program.id', '=', 'typ_semester_outcome.typ_program_id')
  27. ->where('semester_id', $semester_id)
  28. ->where('program_id', $program_id)
  29. ->where('outcome_id', $this->id)
  30. ->select('objectives.*', 'typ_semester_objectives.id as typ_semester_objective_id', 'program_id', 'semester_id')
  31. ->distinct();
  32. Log::info($objectives->toSql());
  33. Log::info('semester_program_outcome' . $semester_id . ',' . $program_id . ',' . $this->id);
  34. return $objectives->get();
  35. }
  36. /**
  37. * Return the objectives that the outcome belongs to
  38. *
  39. * @return Illuminate\Database\Eloquent\Model
  40. */
  41. public function objectives()
  42. {
  43. return $this->hasMany('Objective');
  44. // return $this->belongsToMany('Objective', 'objective_outcome');
  45. }
  46. // public function attempted($semester, $is_grad)
  47. // {
  48. // return DB::table('new_criteria')
  49. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  50. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  51. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  52. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  53. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  54. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  55. // ->where('programs.is_graduate','=',$is_grad)
  56. // ->where('courses.semester_id','=',$semester)
  57. // ->count(DB::raw('DISTINCT new_criteria.id,activity_criterion.activity_id'))
  58. // ;
  59. //
  60. // }
  61. // public function attempted($semester, $is_grad)
  62. // {
  63. // $criteria=DB::table('new_criteria')
  64. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  65. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  66. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  67. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  68. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  69. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  70. // ->where('programs.is_graduate','=',$is_grad)
  71. // ->where('courses.semester_id','=',$semester)
  72. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  73. // ->distinct()
  74. // ->get()
  75. // ;
  76. // $conteo=0;
  77. // foreach($criteria as $criterion)
  78. // {
  79. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  80. // if($students_attempted)
  81. // {
  82. // $conteo++;
  83. // }
  84. // }
  85. // return $conteo;
  86. // }
  87. public static function active_by_semesters($selected_semesters, $level)
  88. {
  89. $min_start = "9000-01-01 00:00:00";
  90. $max_end = "1000-01-01 00:00:00";
  91. foreach ($selected_semesters as $semester) {
  92. if ($min_start > $semester->start) {
  93. $min_start = $semester->start;
  94. }
  95. if ($max_end < $semester->end) {
  96. $max_end = $semester->end;
  97. }
  98. }
  99. $outcomes = Outcome::where(function ($query) use ($min_start) {
  100. $query->where('deactivation_date', '>=', $min_start)
  101. ->orWhere('deactivation_date', null);
  102. })
  103. ->where('activation_date', '<=', $max_end)
  104. ->where(function ($query2) use ($level) {
  105. $query2->where("level", $level + 1)
  106. ->orWhere("level", 3);
  107. })
  108. ->orderBy('name', 'ASC')
  109. ->get();
  110. // return array('outcomes'=>$outcomes,'outcomes_attempted'=>$outcomes_attempted, 'outcomes_achieved'=>$outcomes_achieved, 'attemptedProgramsPerOutcome'=>$attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome'=>$achievedProgramsPerOutcome,'participating_programs'=>$participating_programs);
  111. return $outcomes;
  112. }
  113. public function programs_attempted($semesters)
  114. {
  115. $semesters_array = [];
  116. foreach ($semesters as $semester) {
  117. $semesters_array[] = $semester->id;
  118. }
  119. // $programs=DB::table('programs')
  120. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  121. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  122. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  123. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  124. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  125. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  126. // ->whereIn('courses.semester_id',$semesters_array)
  127. // ->distinct()
  128. // ->select('programs.id')
  129. // ->get()
  130. // ;
  131. $programs = DB::table('programs')
  132. ->join('courses', 'programs.id', '=', 'courses.program_id')
  133. ->join('activities', 'activities.course_id', '=', 'courses.id')
  134. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  135. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  136. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  137. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  138. ->whereIn('courses.semester_id', $semesters_array)
  139. ->distinct()
  140. ->select('programs.id')
  141. ->get();
  142. return $programs;
  143. }
  144. public function attempted($semesters, $is_grad)
  145. {
  146. $semesters_array = [];
  147. foreach ($semesters as $semester) {
  148. $semesters_array[] = $semester->id;
  149. }
  150. // $criteria=DB::table('new_criteria')
  151. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  152. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  153. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  154. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  155. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  156. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  157. // ->where('programs.is_graduate','=',$is_grad)
  158. // ->whereIn('courses.semester_id',$semesters_array)
  159. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  160. // ->distinct()
  161. // ->get()
  162. // ;
  163. $criteria = DB::table('criteria')
  164. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  165. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  166. ->join('courses', 'activities.course_id', '=', 'courses.id')
  167. ->join('programs', 'programs.id', '=', 'courses.program_id')
  168. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  169. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  170. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  171. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  172. ->where('programs.is_graduate', '=', $is_grad)
  173. ->whereIn('courses.semester_id', $semesters_array)
  174. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  175. ->distinct()
  176. ->get();
  177. $conteo = 0;
  178. foreach ($criteria as $criterion) {
  179. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  180. if ($students_attempted) {
  181. $conteo++;
  182. }
  183. }
  184. // var_dump($conteo);
  185. // exit();
  186. return $conteo;
  187. }
  188. public function courses_attempted($courses)
  189. {
  190. $courses_array = [];
  191. foreach ($courses as $course) {
  192. // var_dump($course);
  193. // exit();
  194. $courses_array[] = $course->id;
  195. }
  196. // $criteria=DB::table('new_criteria')
  197. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  198. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  199. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  200. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  201. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  202. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  203. // ->whereIn('courses.id',$courses_array)
  204. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  205. // ->distinct()
  206. // ->get()
  207. // ;
  208. $criteria = DB::table('criteria')
  209. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  210. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  211. ->join('courses', 'activities.course_id', '=', 'courses.id')
  212. ->join('programs', 'programs.id', '=', 'courses.program_id')
  213. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  214. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  215. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  216. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  217. ->whereIn('courses.id', $courses_array)
  218. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  219. ->distinct()
  220. ->get();
  221. $conteo = 0;
  222. foreach ($criteria as $criterion) {
  223. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  224. if ($students_attempted) {
  225. $conteo++;
  226. }
  227. }
  228. // var_dump($conteo);
  229. // exit();
  230. return $conteo;
  231. }
  232. public function courses_achieved($courses)
  233. {
  234. $courses_array = [];
  235. foreach ($courses as $course) {
  236. $courses_array[] = $course->id;
  237. }
  238. // $criteria=DB::table('new_criteria')
  239. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  240. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  241. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  242. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  243. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  244. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  245. // ->whereIn('courses.id',$courses_array)
  246. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  247. // ->distinct()
  248. // ->get()
  249. // ;
  250. $criteria = DB::table('criteria')
  251. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  252. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  253. ->join('courses', 'activities.course_id', '=', 'courses.id')
  254. ->join('programs', 'programs.id', '=', 'courses.program_id')
  255. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  256. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  257. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  258. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  259. ->whereIn('courses.id', $courses_array)
  260. ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
  261. ->distinct()
  262. ->get();
  263. $conteo = 0;
  264. foreach ($criteria as $criterion) {
  265. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  266. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  267. if ($students_attempted) {
  268. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  269. } else {
  270. $percentage_students_who_achieved = 0;
  271. }
  272. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  273. $conteo++;
  274. }
  275. }
  276. return $conteo;
  277. }
  278. public function achieved($semesters, $is_grad)
  279. {
  280. $semesters_array = [];
  281. foreach ($semesters as $semester) {
  282. $semesters_array[] = $semester->id;
  283. }
  284. // DB::enableQueryLog();
  285. // $criteria=DB::table('new_criteria')
  286. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  287. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  288. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  289. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  290. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  291. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  292. // ->where('programs.is_graduate','=',$is_grad)
  293. // ->whereIn('courses.semester_id',$semesters_array)
  294. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  295. // ->distinct()
  296. // ->get()
  297. // ;
  298. $criteria = DB::table('criteria')
  299. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  300. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  301. ->join('courses', 'activities.course_id', '=', 'courses.id')
  302. ->join('programs', 'programs.id', '=', 'courses.program_id')
  303. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  304. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  305. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  306. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  307. ->where('programs.is_graduate', '=', $is_grad)
  308. ->whereIn('courses.semester_id', $semesters_array)
  309. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  310. ->distinct()
  311. ->get();
  312. // dd(DB::getQueryLog());
  313. $conteo = 0;
  314. foreach ($criteria as $criterion) {
  315. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  316. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  317. if ($students_attempted) {
  318. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  319. } else {
  320. $percentage_students_who_achieved = 0;
  321. }
  322. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  323. $conteo++;
  324. }
  325. }
  326. return $conteo;
  327. }
  328. // public function achieved($semester, $is_grad)
  329. // {
  330. //
  331. // // DB::enableQueryLog();
  332. // $criteria=DB::table('criteria')
  333. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  334. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  335. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  336. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  337. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  338. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  339. // ->where('programs.is_graduate','=',$is_grad)
  340. // ->where('courses.semester_id','=',$semester)
  341. // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  342. // ->distinct()
  343. // ->get()
  344. // ;
  345. // // dd(DB::getQueryLog());
  346. //
  347. // $conteo=0;
  348. // foreach($criteria as $criterion)
  349. // {
  350. // $outcome_performance=DB::table('outcome_performance')
  351. // ->where('outcome_performance.outcome_id','=',$this->id)
  352. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  353. // ->where('outcome_performance.semester_id','=',$semester)
  354. // ->where('outcome_performance.level','=',$is_grad)
  355. // ->select('students_attempted','students_achieved')
  356. // ->first();
  357. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  358. // {
  359. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  360. // }
  361. // else
  362. // {
  363. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  364. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  365. //
  366. // if($students_attempted)
  367. // {
  368. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  369. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  370. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  371. // }
  372. // else
  373. // {
  374. // $percentage_students_who_achieved=0;
  375. // }
  376. // }
  377. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  378. // {
  379. // $conteo++;
  380. // }
  381. // }
  382. // return $conteo;
  383. // }
  384. //
  385. public static function active()
  386. {
  387. //TODO: Check when semester doesnt exist or session is empty
  388. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  389. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  390. }
  391. }