Bez popisu

Outcome.php 12KB

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