No Description

Outcome.php 17KB

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