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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 programs_attempted_in_school($semesters, $school_id)
  145. {
  146. $semesters_array = [];
  147. foreach ($semesters as $semester) {
  148. $semesters_array[] = $semester->id;
  149. }
  150. // $programs=DB::table('programs')
  151. // ->join('courses', 'programs.id', '=', 'courses.program_id')
  152. // ->join('activities', 'activities.course_id', '=', 'courses.id')
  153. // ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  154. // ->join('new_criteria', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  155. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  156. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  157. // ->whereIn('courses.semester_id',$semesters_array)
  158. // ->distinct()
  159. // ->select('programs.id')
  160. // ->get()
  161. // ;
  162. $programs = DB::table('programs')
  163. ->join('courses', 'programs.id', '=', 'courses.program_id')
  164. ->join('activities', 'activities.course_id', '=', 'courses.id')
  165. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  166. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  167. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  168. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  169. ->where('programs.school_id', '=', $school_id)
  170. ->whereIn('courses.semester_id', $semesters_array)
  171. ->distinct()
  172. ->select('programs.id')
  173. ->get();
  174. return $programs;
  175. }
  176. public function attempted($semesters, $is_grad)
  177. {
  178. $semesters_array = [];
  179. foreach ($semesters as $semester) {
  180. $semesters_array[] = $semester->id;
  181. }
  182. // $criteria=DB::table('new_criteria')
  183. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  184. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  185. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  186. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  187. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  188. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  189. // ->where('programs.is_graduate','=',$is_grad)
  190. // ->whereIn('courses.semester_id',$semesters_array)
  191. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  192. // ->distinct()
  193. // ->get()
  194. // ;
  195. $criteria = DB::table('criteria')
  196. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  197. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  198. ->join('courses', 'activities.course_id', '=', 'courses.id')
  199. ->join('programs', 'programs.id', '=', 'courses.program_id')
  200. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  201. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  202. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  203. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  204. ->where('programs.is_graduate', '=', $is_grad)
  205. ->whereIn('courses.semester_id', $semesters_array)
  206. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  207. ->distinct()
  208. ->get();
  209. $conteo = 0;
  210. foreach ($criteria as $criterion) {
  211. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  212. if ($students_attempted) {
  213. $conteo++;
  214. }
  215. }
  216. // var_dump($conteo);
  217. // exit();
  218. return $conteo;
  219. }
  220. public function attempted_by_school($semesters, $school_id, $is_grad)
  221. {
  222. $semesters_array = [];
  223. foreach ($semesters as $semester) {
  224. $semesters_array[] = $semester->id;
  225. }
  226. // $criteria=DB::table('new_criteria')
  227. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_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', '=', 'new_criteria.id')
  232. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  233. // ->where('programs.is_graduate','=',$is_grad)
  234. // ->whereIn('courses.semester_id',$semesters_array)
  235. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  236. // ->distinct()
  237. // ->get()
  238. // ;
  239. $criteria = DB::table('criteria')
  240. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  241. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  242. ->join('courses', 'activities.course_id', '=', 'courses.id')
  243. ->join('programs', 'programs.id', '=', 'courses.program_id')
  244. ->join('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  245. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  246. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  247. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  248. ->where('programs.is_graduate', '=', $is_grad)
  249. ->where('programs.school_id', '=', $school_id)
  250. ->whereIn('courses.semester_id', $semesters_array)
  251. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  252. ->distinct()
  253. ->get();
  254. $conteo = 0;
  255. foreach ($criteria as $criterion) {
  256. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  257. if ($students_attempted) {
  258. $conteo++;
  259. }
  260. }
  261. // var_dump($conteo);
  262. // exit();
  263. return $conteo;
  264. }
  265. public function attempted_by_program($semesters, $program_id, $is_grad)
  266. {
  267. $semesters_array = [];
  268. foreach ($semesters as $semester) {
  269. $semesters_array[] = $semester->id;
  270. }
  271. // $criteria=DB::table('new_criteria')
  272. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  273. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  274. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  275. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  276. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  277. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  278. // ->where('programs.is_graduate','=',$is_grad)
  279. // ->whereIn('courses.semester_id',$semesters_array)
  280. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  281. // ->distinct()
  282. // ->get()
  283. // ;
  284. $criteria = DB::table('criteria')
  285. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', '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('rubric_activity', 'activities.id', '=', 'rubric_activity.activity_id')
  290. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  291. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  292. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  293. ->where('programs.is_graduate', '=', $is_grad)
  294. ->where('programs.id', '=', $program_id)
  295. ->whereIn('courses.semester_id', $semesters_array)
  296. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  297. ->distinct()
  298. ->get();
  299. $conteo = 0;
  300. foreach ($criteria as $criterion) {
  301. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  302. if ($students_attempted) {
  303. $conteo++;
  304. }
  305. }
  306. // var_dump($conteo);
  307. // exit();
  308. return $conteo;
  309. }
  310. public function courses_attempted($courses)
  311. {
  312. $courses_array = [];
  313. foreach ($courses as $course) {
  314. // var_dump($course);
  315. // exit();
  316. $courses_array[] = $course->id;
  317. }
  318. // $criteria=DB::table('new_criteria')
  319. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  320. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  321. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  322. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  323. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  324. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  325. // ->whereIn('courses.id',$courses_array)
  326. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  327. // ->distinct()
  328. // ->get()
  329. // ;
  330. $criteria = DB::table('criteria')
  331. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  332. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  333. ->join('courses', 'activities.course_id', '=', 'courses.id')
  334. ->join('programs', 'programs.id', '=', 'courses.program_id')
  335. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  336. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  337. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  338. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  339. ->whereIn('courses.id', $courses_array)
  340. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  341. ->distinct()
  342. ->get();
  343. $conteo = 0;
  344. foreach ($criteria as $criterion) {
  345. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  346. if ($students_attempted) {
  347. $conteo++;
  348. }
  349. }
  350. // var_dump($conteo);
  351. // exit();
  352. return $conteo;
  353. }
  354. public function courses_achieved($courses)
  355. {
  356. $courses_array = [];
  357. foreach ($courses as $course) {
  358. $courses_array[] = $course->id;
  359. }
  360. // $criteria=DB::table('new_criteria')
  361. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  362. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  363. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  364. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  365. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  366. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  367. // ->whereIn('courses.id',$courses_array)
  368. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  369. // ->distinct()
  370. // ->get()
  371. // ;
  372. $criteria = DB::table('criteria')
  373. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  374. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  375. ->join('courses', 'activities.course_id', '=', 'courses.id')
  376. ->join('programs', 'programs.id', '=', 'courses.program_id')
  377. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  378. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  379. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  380. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  381. ->whereIn('courses.id', $courses_array)
  382. ->select('criteria.id', 'expected_percentage as expected_percentage_students_achieving', 'activity_criterion.activity_id')
  383. ->distinct()
  384. ->get();
  385. $conteo = 0;
  386. foreach ($criteria as $criterion) {
  387. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  388. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  389. if ($students_attempted) {
  390. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  391. } else {
  392. $percentage_students_who_achieved = 0;
  393. }
  394. if ($percentage_students_who_achieved >= $criterion->expected_percentage_students_achieving) {
  395. $conteo++;
  396. }
  397. }
  398. return $conteo;
  399. }
  400. public function achieved($semesters, $is_grad)
  401. {
  402. $semesters_array = [];
  403. foreach ($semesters as $semester) {
  404. $semesters_array[] = $semester->id;
  405. }
  406. // DB::enableQueryLog();
  407. // $criteria=DB::table('new_criteria')
  408. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  409. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  410. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  411. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  412. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  413. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  414. // ->where('programs.is_graduate','=',$is_grad)
  415. // ->whereIn('courses.semester_id',$semesters_array)
  416. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  417. // ->distinct()
  418. // ->get()
  419. // ;
  420. $criteria = DB::table('criteria')
  421. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  422. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  423. ->join('courses', 'activities.course_id', '=', 'courses.id')
  424. ->join('programs', 'programs.id', '=', 'courses.program_id')
  425. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  426. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  427. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  428. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  429. ->where('programs.is_graduate', '=', $is_grad)
  430. ->whereIn('courses.semester_id', $semesters_array)
  431. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  432. ->distinct()
  433. ->get();
  434. // dd(DB::getQueryLog());
  435. $conteo = 0;
  436. foreach ($criteria as $criterion) {
  437. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  438. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  439. if ($students_attempted) {
  440. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  441. } else {
  442. $percentage_students_who_achieved = 0;
  443. }
  444. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  445. $conteo++;
  446. }
  447. }
  448. return $conteo;
  449. }
  450. public function achieved_by_school($semesters, $school_id, $is_grad)
  451. {
  452. $semesters_array = [];
  453. foreach ($semesters as $semester) {
  454. $semesters_array[] = $semester->id;
  455. }
  456. // DB::enableQueryLog();
  457. // $criteria=DB::table('new_criteria')
  458. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  459. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  460. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  461. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  462. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  463. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  464. // ->where('programs.is_graduate','=',$is_grad)
  465. // ->whereIn('courses.semester_id',$semesters_array)
  466. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  467. // ->distinct()
  468. // ->get()
  469. // ;
  470. $criteria = DB::table('criteria')
  471. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  472. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  473. ->join('courses', 'activities.course_id', '=', 'courses.id')
  474. ->join('programs', 'programs.id', '=', 'courses.program_id')
  475. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  476. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  477. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  478. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  479. ->where('programs.is_graduate', '=', $is_grad)
  480. ->where('programs.school_id', '=', $school_id)
  481. ->whereIn('courses.semester_id', $semesters_array)
  482. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  483. ->distinct()
  484. ->get();
  485. // dd(DB::getQueryLog());
  486. $conteo = 0;
  487. foreach ($criteria as $criterion) {
  488. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  489. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  490. if ($students_attempted) {
  491. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  492. } else {
  493. $percentage_students_who_achieved = 0;
  494. }
  495. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  496. $conteo++;
  497. }
  498. }
  499. return $conteo;
  500. }
  501. public function achieved_by_program($semesters, $program_id, $is_grad)
  502. {
  503. $semesters_array = [];
  504. foreach ($semesters as $semester) {
  505. $semesters_array[] = $semester->id;
  506. }
  507. // DB::enableQueryLog();
  508. // $criteria=DB::table('new_criteria')
  509. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  510. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  511. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  512. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  513. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  514. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  515. // ->where('programs.is_graduate','=',$is_grad)
  516. // ->whereIn('courses.semester_id',$semesters_array)
  517. // ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  518. // ->distinct()
  519. // ->get()
  520. // ;
  521. $criteria = DB::table('criteria')
  522. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  523. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  524. ->join('courses', 'activities.course_id', '=', 'courses.id')
  525. ->join('programs', 'programs.id', '=', 'courses.program_id')
  526. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  527. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  528. ->join('rubrics', 'rubric_activity.rubric_id', '=', 'rubrics.id')
  529. ->where('criterion_objective_outcome.outcome_id', '=', $this->id)
  530. ->where('programs.is_graduate', '=', $is_grad)
  531. ->where('programs.school_.semester_id', $semesters_array)
  532. ->select('criteria.id', 'expected_percentage', 'activity_criterion.activity_id')
  533. ->distinct()
  534. ->get();
  535. // dd(DB::getQueryLog());
  536. $conteo = 0;
  537. foreach ($criteria as $criterion) {
  538. $students_attempted = Criterion::students_attempted($criterion->id, $criterion->activity_id);
  539. $students_achieved = Criterion::students_achieved($criterion->id, $criterion->activity_id);
  540. if ($students_attempted) {
  541. $percentage_students_who_achieved = 100.0 * $students_achieved / $students_attempted;
  542. } else {
  543. $percentage_students_who_achieved = 0;
  544. }
  545. if ($percentage_students_who_achieved >= $criterion->expected_percentage) {
  546. $conteo++;
  547. }
  548. }
  549. return $conteo;
  550. }
  551. // public function achieved($semester, $is_grad)
  552. // {
  553. //
  554. // // DB::enableQueryLog();
  555. // $criteria=DB::table('criteria')
  556. // ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criteria.id')
  557. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  558. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  559. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  560. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  561. // ->where('criterion_objective_outcome.outcome_id','=',$this->id)
  562. // ->where('programs.is_graduate','=',$is_grad)
  563. // ->where('courses.semester_id','=',$semester)
  564. // ->select('criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  565. // ->distinct()
  566. // ->get()
  567. // ;
  568. // // dd(DB::getQueryLog());
  569. //
  570. // $conteo=0;
  571. // foreach($criteria as $criterion)
  572. // {
  573. // $outcome_performance=DB::table('outcome_performance')
  574. // ->where('outcome_performance.outcome_id','=',$this->id)
  575. // ->where('outcome_performance.criterion_id','=',$criterion->id)
  576. // ->where('outcome_performance.semester_id','=',$semester)
  577. // ->where('outcome_performance.level','=',$is_grad)
  578. // ->select('students_attempted','students_achieved')
  579. // ->first();
  580. // if(!empty($outcome_performance) and $outcome_performance->students_attempted)
  581. // {
  582. // $percentage_students_who_achieved=100.0*$outcome_performance->students_achieved/$outcome_performance->students_attempted;
  583. // }
  584. // else
  585. // {
  586. // $students_attempted=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  587. // $students_achieved=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  588. //
  589. // if($students_attempted)
  590. // {
  591. // $percentage_students_who_achieved=100.0*$students_achieved/$students_attempted;
  592. // DB::table('outcome_performance')->insert(array('criterion_id'=>$criterion->id,'outcome_id'=>$this->id,'semester_id'=>$semester,
  593. // 'students_attempted' => $students_attempted,'students_achieved' => $students_achieved,'level'=>$is_grad));
  594. // }
  595. // else
  596. // {
  597. // $percentage_students_who_achieved=0;
  598. // }
  599. // }
  600. // if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  601. // {
  602. // $conteo++;
  603. // }
  604. // }
  605. // return $conteo;
  606. // }
  607. //
  608. public static function active()
  609. {
  610. //TODO: Check when semester doesnt exist or session is empty
  611. $selected_semester = Semester::find(Session::get('semesters_ids')[0]);
  612. return Outcome::withTrashed()->where('deactivation_date', '>=', $selected_semester->start)->orWhere('deactivation_date', null)->orderBy('name', 'ASC')->get();
  613. }
  614. }