No Description

Outcome.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. if ($min_start > $semester->start) {
  69. $min_start = $semester->start;
  70. }
  71. if ($max_end < $semester->end) {
  72. $max_end = $semester->end;
  73. }
  74. }
  75. $outcomes = Outcome::where(function ($query) use ($min_start) {
  76. $query->where('deactivation_date', '>=', $min_start)
  77. ->orWhere('deactivation_date', null);
  78. })
  79. ->where('activation_date', '<=', $max_end)
  80. ->where(function ($query2) use ($level) {
  81. $query2->where("level", $level + 1)
  82. ->orWhere("level", 3);
  83. })
  84. ->orderBy('name', 'ASC')
  85. ->get();
  86. // return array('outcomes'=>$outcomes,'outcomes_attempted'=>$outcomes_attempted, 'outcomes_achieved'=>$outcomes_achieved, 'attemptedProgramsPerOutcome'=>$attemptedProgramsPerOutcome, 'achievedProgramsPerOutcome'=>$achievedProgramsPerOutcome,'participating_programs'=>$participating_programs);
  87. return $outcomes;
  88. }
  89. public function programs_attempted($semesters)
  90. {
  91. $semesters_array = [];
  92. foreach ($semesters as $semester) {
  93. $semesters_array[] = $semester->id;
  94. }
  95. // $programs=DB::table('programs')
  96. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  97. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  98. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  99. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  100. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  101. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  102. // ->whereIn('courses.semester_id',$semesters_array)
  103. // ->distinct()
  104. // ->select('programs.id')
  105. // ->get()
  106. // ;
  107. $programs = DB::table('programs')
  108. ->join('courses', 'programs.id', '=', 'courses.program_id')
  109. ->join('activities', 'activities.course_id', '=', 'courses.id')
  110. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  111. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  112. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  113. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  114. ->whereIn('courses.semester_id', $semesters_array)
  115. ->distinct()
  116. ->select('programs.id')
  117. ->get();
  118. return $programs;
  119. }
  120. public function attempted($semesters, $is_grad)
  121. {
  122. $semesters_array = [];
  123. foreach ($semesters as $semester) {
  124. $semesters_array[] = $semester->id;
  125. }
  126. // $criteria=DB::table('new_criteria')
  127. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  128. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  129. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  130. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  131. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  132. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  133. // ->where('programs.is_graduate','=',$is_grad)
  134. // ->whereIn('courses.semester_id',$semesters_array)
  135. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  136. // ->distinct()
  137. // ->get()
  138. // ;
  139. $criteria = DB::table('criteria')
  140. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  141. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  142. ->join('courses', 'activities.course_id', '=', 'courses.id')
  143. ->join('programs', 'programs.id', '=', 'courses.program_id')
  144. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  145. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  146. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  147. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  148. ->where('programs.is_graduate', '=', $is_grad)
  149. ->whereIn('courses.semester_id', $semesters_array)
  150. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  151. ->distinct()
  152. ->get();
  153. $conteo = 0;
  154. foreach ($criteria as $criterion) {
  155. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  156. if ($students_attempted) {
  157. $conteo++;
  158. }
  159. }
  160. // var_dump($conteo);
  161. // exit();
  162. return $conteo;
  163. }
  164. public function courses_attempted($courses)
  165. {
  166. $courses_array = [];
  167. foreach ($courses as $course) {
  168. // var_dump($course);
  169. // exit();
  170. $courses_array[] = $course->id;
  171. }
  172. // $criteria=DB::table('new_criteria')
  173. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  174. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  175. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  176. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  177. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  178. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  179. // ->whereIn('courses.id',$courses_array)
  180. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  181. // ->distinct()
  182. // ->get()
  183. // ;
  184. $criteria = DB::table('criteria')
  185. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', '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', '=', 'criteria.id')
  190. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  191. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  192. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  193. ->whereIn('courses.id', $courses_array)
  194. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  195. ->distinct()
  196. ->get();
  197. $conteo = 0;
  198. foreach ($criteria as $criterion) {
  199. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  200. if ($students_attempted) {
  201. $conteo++;
  202. }
  203. }
  204. // var_dump($conteo);
  205. // exit();
  206. return $conteo;
  207. }
  208. public function courses_achieved($courses)
  209. {
  210. $courses_array = [];
  211. foreach ($courses as $course) {
  212. $courses_array[] = $course->id;
  213. }
  214. // $criteria=DB::table('new_criteria')
  215. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  216. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  217. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  218. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  219. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  220. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  221. // ->whereIn('courses.id',$courses_array)
  222. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  223. // ->distinct()
  224. // ->get()
  225. // ;
  226. $criteria = DB::table('criteria')
  227. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  228. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  229. ->join('courses', 'activities.course_id', '=', 'courses.id')
  230. ->join('programs', 'programs.id', '=', 'courses.program_id')
  231. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  232. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  233. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  234. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  235. ->whereIn('courses.id', $courses_array)
  236. ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
  237. ->distinct()
  238. ->get();
  239. $conteo = 0;
  240. foreach ($criteria as $criterion) {
  241. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  242. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  243. if ($students_attempted) {
  244. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  245. } else {
  246. $percentage_students_who_achieved = 0;
  247. }
  248. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  249. $conteo++;
  250. }
  251. }
  252. return $conteo;
  253. }
  254. public function achieved($semesters, $is_grad)
  255. {
  256. $semesters_array = [];
  257. foreach ($semesters as $semester) {
  258. $semesters_array[] = $semester->id;
  259. }
  260. // DB::enableQueryLog();
  261. // $criteria=DB::table('new_criteria')
  262. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  263. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  264. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  265. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  266. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  267. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  268. // ->where('programs.is_graduate','=',$is_grad)
  269. // ->whereIn('courses.semester_id',$semesters_array)
  270. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  271. // ->distinct()
  272. // ->get()
  273. // ;
  274. $criteria = DB::table('criteria')
  275. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  276. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  277. ->join('courses', 'activities.course_id', '=', 'courses.id')
  278. ->join('programs', 'programs.id', '=', 'courses.program_id')
  279. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  280. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  281. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  282. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  283. ->where('programs.is_graduate', '=', $is_grad)
  284. ->whereIn('courses.semester_id', $semesters_array)
  285. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  286. ->distinct()
  287. ->get();
  288. // dd(DB::getQueryLog());
  289. $conteo = 0;
  290. foreach ($criteria as $criterion) {
  291. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  292. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  293. if ($students_attempted) {
  294. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  295. } else {
  296. $percentage_students_who_achieved = 0;
  297. }
  298. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  299. $conteo++;
  300. }
  301. }
  302. return $conteo;
  303. }
  304. // public function achieved($semester, $is_grad)
  305. // {
  306. //
  307. // // DB::enableQueryLog();
  308. // $criteria=DB::table('criteria')
  309. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  310. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  311. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  312. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  313. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  314. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  315. // ->where('programs.is_graduate','=',$is_grad)
  316. // ->where('courses.semester_id','=',$semester)
  317. // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  318. // ->distinct()
  319. // ->get()
  320. // ;
  321. // // dd(DB::getQueryLog());
  322. //
  323. // $conteo=0;
  324. // foreach($criteria as $criterion)
  325. // {
  326. // $outcome_performance=DB::table('outcome_performance')
  327. // ->where('outcome_performance.outcome_id','=',$this->id)
  328. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  329. // ->where('outcome_performance.semester_id','=',$semester)
  330. // ->where('outcome_performance.level','=',$is_grad)
  331. // ->select('students_attempted','students_achieved')
  332. // ->first();
  333. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  334. // {
  335. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  336. // }
  337. // else
  338. // {
  339. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  340. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  341. //
  342. // if($students_attempted)
  343. // {
  344. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  345. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  346. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  347. // }
  348. // else
  349. // {
  350. // $percentage_students_who_achieved=0;
  351. // }
  352. // }
  353. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  354. // {
  355. // $conteo++;
  356. // }
  357. // }
  358. // return $conteo;
  359. // }
  360. //
  361. public static function active()
  362. {
  363. //TODO: Check when semester doesnt exist or session is empty
  364. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  365. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  366. }
  367. }