설명 없음

Outcome.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 static 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. $programs=DB::table('programs')
  114. ->join('courses', 'programs.id', '=', 'courses.program_id')
  115. ->join('activities', 'activities.course_id', '=', 'courses.id')
  116. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  117. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  118. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  119. ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  120. ->whereIn('courses.semester_id',$semesters_array)
  121. ->distinct()
  122. ->select('programs.id')
  123. ->get()
  124. ;
  125. return $programs;
  126. }
  127. public function attempted($semesters, $is_grad)
  128. {
  129. $semesters_array=[];
  130. foreach($semesters as $semester)
  131. {
  132. $semesters_array[]=$semester->id;
  133. }
  134. // $criteria=DB::table('new_criteria')
  135. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  136. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  137. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  138. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  139. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  140. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  141. // ->where('programs.is_graduate','=',$is_grad)
  142. // ->whereIn('courses.semester_id',$semesters_array)
  143. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  144. // ->distinct()
  145. // ->get()
  146. // ;
  147. $criteria=DB::table('criteria')
  148. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  149. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  150. ->join('courses', 'activities.course_id', '=', 'courses.id')
  151. ->join('programs', 'programs.id', '=', 'courses.program_id')
  152. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  153. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  154. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  155. ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  156. ->where('programs.is_graduate','=',$is_grad)
  157. ->whereIn('courses.semester_id',$semesters_array)
  158. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  159. ->distinct()
  160. ->get()
  161. ;
  162. $conteo=0;
  163. foreach($criteria as $criterion)
  164. {
  165. $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  166. if($students_attempted)
  167. {
  168. $conteo++;
  169. }
  170. }
  171. // var_dump($conteo);
  172. // exit();
  173. return $conteo;
  174. }
  175. public function courses_attempted($courses)
  176. {
  177. $courses_array=[];
  178. foreach($courses as $course)
  179. {
  180. // var_dump($course);
  181. // exit();
  182. $courses_array[]=$course->id;
  183. }
  184. // $criteria=DB::table('new_criteria')
  185. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  186. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  187. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  188. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  189. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  190. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  191. // ->whereIn('courses.id',$courses_array)
  192. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  193. // ->distinct()
  194. // ->get()
  195. // ;
  196. $criteria=DB::table('criteria')
  197. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', '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', '=', 'criteria.id')
  202. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  203. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  204. ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  205. ->whereIn('courses.id',$courses_array)
  206. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  207. ->distinct()
  208. ->get()
  209. ;
  210. $conteo=0;
  211. foreach($criteria as $criterion)
  212. {
  213. $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  214. if($students_attempted)
  215. {
  216. $conteo++;
  217. }
  218. }
  219. // var_dump($conteo);
  220. // exit();
  221. return $conteo;
  222. }
  223. public function courses_achieved($courses)
  224. {
  225. $courses_array=[];
  226. foreach($courses as $course)
  227. {
  228. $courses_array[]=$course->id;
  229. }
  230. // $criteria=DB::table('new_criteria')
  231. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  232. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  233. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  234. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  235. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  236. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  237. // ->whereIn('courses.id',$courses_array)
  238. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  239. // ->distinct()
  240. // ->get()
  241. // ;
  242. $criteria=DB::table('criteria')
  243. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', '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', '=', 'criteria.id')
  248. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  249. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  250. ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  251. ->whereIn('courses.id',$courses_array)
  252. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  253. ->distinct()
  254. ->get()
  255. ;
  256. $conteo=0;
  257. foreach($criteria as $criterion)
  258. {
  259. $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  260. $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  261. if($students_attempted)
  262. {
  263. $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  264. }
  265. else
  266. {
  267. $percentage_students_who_achieved=0;
  268. }
  269. if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  270. {
  271. $conteo++;
  272. }
  273. }
  274. return $conteo;
  275. }
  276. public function achieved($semesters, $is_grad)
  277. {
  278. $semesters_array=[];
  279. foreach($semesters as $semester)
  280. {
  281. $semesters_array[]=$semester->id;
  282. }
  283. // DB::enableQueryLog();
  284. // $criteria=DB::table('new_criteria')
  285. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  286. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  287. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  288. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  289. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  290. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  291. // ->where('programs.is_graduate','=',$is_grad)
  292. // ->whereIn('courses.semester_id',$semesters_array)
  293. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  294. // ->distinct()
  295. // ->get()
  296. // ;
  297. $criteria=DB::table('criteria')
  298. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  299. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  300. ->join('courses', 'activities.course_id', '=', 'courses.id')
  301. ->join('programs', 'programs.id', '=', 'courses.program_id')
  302. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  303. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  304. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  305. ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  306. ->where('programs.is_graduate','=',$is_grad)
  307. ->whereIn('courses.semester_id',$semesters_array)
  308. ->select('criteria.id','expected_percentage','activity_criterion.activity_id')
  309. ->distinct()
  310. ->get()
  311. ;
  312. // dd(DB::getQueryLog());
  313. $conteo=0;
  314. foreach($criteria as $criterion)
  315. {
  316. $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  317. $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  318. if($students_attempted)
  319. {
  320. $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  321. }
  322. else
  323. {
  324. $percentage_students_who_achieved=0;
  325. }
  326. if($percentage_students_who_achieved>=$criterion->expected_percentage)
  327. {
  328. $conteo++;
  329. }
  330. }
  331. return $conteo;
  332. }
  333. // public function achieved($semester, $is_grad)
  334. // {
  335. //
  336. // // DB::enableQueryLog();
  337. // $criteria=DB::table('new_criteria')
  338. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  339. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  340. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  341. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  342. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  343. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  344. // ->where('programs.is_graduate','=',$is_grad)
  345. // ->where('courses.semester_id','=',$semester)
  346. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  347. // ->distinct()
  348. // ->get()
  349. // ;
  350. // // dd(DB::getQueryLog());
  351. //
  352. // $conteo=0;
  353. // foreach($criteria as $criterion)
  354. // {
  355. // $outcome_performance=DB::table('outcome_performance')
  356. // ->where('outcome_performance.outcome_id','=',$this->id)
  357. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  358. // ->where('outcome_performance.semester_id','=',$semester)
  359. // ->where('outcome_performance.level','=',$is_grad)
  360. // ->select('students_attempted','students_achieved')
  361. // ->first();
  362. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  363. // {
  364. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  365. // }
  366. // else
  367. // {
  368. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  369. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  370. //
  371. // if($students_attempted)
  372. // {
  373. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  374. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  375. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  376. // }
  377. // else
  378. // {
  379. // $percentage_students_who_achieved=0;
  380. // }
  381. // }
  382. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  383. // {
  384. // $conteo++;
  385. // }
  386. // }
  387. // return $conteo;
  388. // }
  389. //
  390. public static function active()
  391. {
  392. //TODO: Check when semester doesnt exist or session is empty
  393. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  394. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  395. }
  396. }