Нема описа

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <?php
  2. class Program extends Eloquent
  3. {
  4. public function school()
  5. {
  6. return $this->belongsTo('School');
  7. }
  8. public function courses()
  9. {
  10. return $this->hasMany('Course')->with('semester')->whereIn('semester_id', Session::get('semesters_ids'))->orderBy('code')->orderBy('number')->orderBy('section');
  11. }
  12. public function coordinators()
  13. {
  14. return $this->hasMany('User');
  15. }
  16. public function professors()
  17. {
  18. return $this->hasMany('Professor');
  19. }
  20. public function students()
  21. {
  22. return $this->hasMany('Student');
  23. }
  24. public function templates()
  25. {
  26. return $this->hasMany('Template');
  27. }
  28. public function activities()
  29. {
  30. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->whereIn('semester_id', Session::get('semesters_ids'));
  31. }
  32. public function publishedActivities()
  33. {
  34. return $this->hasManyThrough('Activity', 'Course')->whereNotNull('activities.outcomes_attempted')->where('activities.draft', 0)->whereIn('semester_id', Session::get('semesters_ids'));
  35. }
  36. public function assessesOutcome($outcome_id)
  37. {
  38. foreach ($this->publishedActivities as $activity)
  39. {
  40. $outcomes_attempted = (array)$activity->o_att_array;
  41. if(array_key_exists($outcome_id, $outcomes_attempted) && $outcomes_attempted[$outcome_id] != 0)
  42. {
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. // return the users that are pcoords for a program
  49. public function users()
  50. {
  51. return $this->belongsToMany('User');
  52. }
  53. public function objectives()
  54. {
  55. return $this->hasMany('Objective');
  56. }
  57. // Return learning objectives ordered by outcome
  58. public function objectivesByOutcome()
  59. {
  60. // Objective::
  61. $objectives = DB::table('outcomes')
  62. ->select('outcomes.id as outcome_id', 'outcomes.name as outcome_name', 'objectives.id as objective_id', 'objectives.text', 'objectives.active')
  63. ->leftJoin('objectives', function($join)
  64. {
  65. $join
  66. ->on('outcomes.id', '=', 'objectives.outcome_id')
  67. ->where('objectives.program_id', '=', $this->id);
  68. })
  69. ->orderBy('outcome_name', 'ASC')
  70. ->orderBy('objectives.text', 'ASC')
  71. ->get();
  72. return $objectives;
  73. }
  74. public function hasObjectivesInOutcome($outcome_id)
  75. {
  76. return Objective::where('program_id', $this->id)
  77. ->where('outcome_id', $outcome_id)->count();
  78. }
  79. /**
  80. * Return all the criteria in/for the program, if any
  81. *
  82. * @return Illuminate\Database\Eloquent\Collection
  83. */
  84. public function criteria()
  85. {
  86. return $this->hasMany('Criterion');
  87. }
  88. // public function attempted_outcome($outcome_id, $semester)
  89. // {
  90. // $conteo= DB::table('activity_criterion')
  91. // ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  92. // ->join('courses', 'activities.course_id', '=', 'courses.id')
  93. // ->join('programs', 'programs.id', '=', 'courses.program_id')
  94. // ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  95. // ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  96. // ->where('programs.id','=',$this->id)
  97. // ->where('courses.semester_id','=',$semester)
  98. // ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  99. // ;
  100. // return $conteo;
  101. // }
  102. public function attempted_criteria_by_outcome($outcome_id, $semesters)
  103. {
  104. $semesters_array=[];
  105. foreach($semesters as $semester)
  106. {
  107. $semesters_array[]=$semester->id;
  108. }
  109. $conteo= DB::table('activity_criterion')
  110. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  111. ->join('courses', 'activities.course_id', '=', 'courses.id')
  112. ->join('programs', 'programs.id', '=', 'courses.program_id')
  113. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  114. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  115. ->where('programs.id','=',$this->id)
  116. ->whereIn('courses.semester_id',$semesters_array)
  117. ->count(DB::raw('DISTINCT criterion_objective_outcome.criterion_id'))
  118. ;
  119. return $conteo;
  120. }
  121. public function attempted_outcome($outcome_id, $semesters)
  122. {
  123. $semesters_array=[];
  124. foreach($semesters as $semester)
  125. {
  126. $semesters_array[]=$semester->id;
  127. }
  128. $conteo= DB::table('activity_criterion')
  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', '=', 'activity_criterion.criterion_id')
  133. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  134. ->where('programs.id','=',$this->id)
  135. ->whereIn('courses.semester_id',$semesters_array)
  136. ->count(DB::raw('DISTINCT criterion_objective_outcome.outcome_id'))
  137. ;
  138. return $conteo;
  139. }
  140. public function achieved_criteria_by_outcome($outcome_id, $semesters)
  141. {
  142. $semesters_array=[];
  143. foreach($semesters as $semester)
  144. {
  145. $semesters_array[]=$semester->id;
  146. }
  147. // DB::enableQueryLog();
  148. // dd(DB::getQueryLog());
  149. $criteria=DB::table('new_criteria')
  150. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  151. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  152. ->join('courses', 'activities.course_id', '=', 'courses.id')
  153. ->join('programs', 'programs.id', '=', 'courses.program_id')
  154. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  155. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  156. ->where('programs.id','=',$this->id)
  157. ->whereIn('courses.semester_id',$semesters_array)
  158. ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  159. ->distinct()
  160. ->get()
  161. ;
  162. // dd(DB::getQueryLog());
  163. $conteo=0;
  164. $attempted_criteria_per_program_array=[];
  165. // $students_attempted=0;
  166. // $students_achieved=0;
  167. foreach($criteria as $criterion)
  168. {
  169. if(!isset($students_attempted[$criterion->id]))$students_attempted[$criterion->id]=0;
  170. if(!isset($students_achieved[$criterion->id]))$students_achieved[$criterion->id]=0;
  171. $attempted_criteria_per_program_array[$criterion->id]=1;
  172. $students_attempted[$criterion->id]+=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  173. $students_achieved[$criterion->id]+=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  174. }
  175. // var_dump($outcome_id);
  176. // var_dump($this->id);
  177. // if(isset($students_attempted))var_dump($students_attempted);
  178. // else{print "aqui hay algo";}
  179. // print "<br>";
  180. // if(isset($students_achieved))var_dump($students_achieved);
  181. // print "<br>";
  182. // print "<br>";
  183. // exit();
  184. if(isset($students_attempted))
  185. {
  186. foreach($students_attempted as $criteria_id => $students_attempted_n)
  187. {
  188. if($students_attempted_n)
  189. {
  190. $percentage_students_who_achieved=100.0*$students_achieved[$criteria_id]/$students_attempted[$criteria_id];
  191. }
  192. else
  193. {
  194. $percentage_students_who_achieved=0;
  195. }
  196. if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  197. {
  198. $conteo++;
  199. }
  200. }
  201. }
  202. $attempted_criteria_per_program=count($attempted_criteria_per_program_array);
  203. $achievedProgramOutcome=0;
  204. $outcome=Outcome::where('id',$outcome_id)->select('expected_outcome')->first();
  205. // var_dump($outcome->expected_outcome);
  206. // exit();
  207. if($attempted_criteria_per_program!=0 && 100.0*$conteo/$attempted_criteria_per_program >= $outcome->expected_outcome)
  208. {
  209. $achievedProgramOutcome=1;
  210. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  211. }
  212. return $conteo;
  213. }
  214. public function achieved_outcome($outcome_id, $semesters)
  215. {
  216. $semesters_array=[];
  217. foreach($semesters as $semester)
  218. {
  219. $semesters_array[]=$semester->id;
  220. }
  221. // DB::enableQueryLog();
  222. // dd(DB::getQueryLog());
  223. $criteria=DB::table('new_criteria')
  224. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'new_criteria.id')
  225. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  226. ->join('courses', 'activities.course_id', '=', 'courses.id')
  227. ->join('programs', 'programs.id', '=', 'courses.program_id')
  228. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'new_criteria.id')
  229. ->where('criterion_objective_outcome.outcome_id','=',$outcome_id)
  230. ->where('programs.id','=',$this->id)
  231. ->whereIn('courses.semester_id',$semesters_array)
  232. ->select('new_criteria.id','expected_percentage_students_achieving','activity_criterion.activity_id')
  233. ->distinct()
  234. ->get()
  235. ;
  236. // dd(DB::getQueryLog());
  237. $conteo=0;
  238. $attempted_criteria_per_program_array=[];
  239. // $students_attempted=0;
  240. // $students_achieved=0;
  241. foreach($criteria as $criterion)
  242. {
  243. if(!isset($students_attempted[$criterion->id]))$students_attempted[$criterion->id]=0;
  244. if(!isset($students_achieved[$criterion->id]))$students_achieved[$criterion->id]=0;
  245. $attempted_criteria_per_program_array[$criterion->id]=1;
  246. $students_attempted[$criterion->id]+=Criterion::students_attempted($criterion->id, $criterion->activity_id);
  247. $students_achieved[$criterion->id]+=Criterion::students_achieved($criterion->id, $criterion->activity_id);
  248. }
  249. // var_dump($outcome_id);
  250. // var_dump($this->id);
  251. // if(isset($students_attempted))var_dump($students_attempted);
  252. // else{print "aqui hay algo";}
  253. // print "<br>";
  254. // if(isset($students_achieved))var_dump($students_achieved);
  255. // print "<br>";
  256. // print "<br>";
  257. // exit();
  258. if(isset($students_attempted))
  259. {
  260. foreach($students_attempted as $criteria_id => $students_attempted_n)
  261. {
  262. if($students_attempted_n)
  263. {
  264. $percentage_students_who_achieved=100.0*$students_achieved[$criteria_id]/$students_attempted[$criteria_id];
  265. }
  266. else
  267. {
  268. $percentage_students_who_achieved=0;
  269. }
  270. if($percentage_students_who_achieved>=$criterion->expected_percentage_students_achieving)
  271. {
  272. $conteo++;
  273. }
  274. }
  275. }
  276. $attempted_criteria_per_program=count($attempted_criteria_per_program_array);
  277. $achievedProgramOutcome=0;
  278. $outcome=Outcome::where('id',$outcome_id)->select('expected_outcome')->first();
  279. // var_dump($outcome->expected_outcome);
  280. // exit();
  281. if($attempted_criteria_per_program!=0 && 100.0*$conteo/$attempted_criteria_per_program >= $outcome->expected_outcome)
  282. {
  283. $achievedProgramOutcome=1;
  284. // $output[]= 'END OF PROGRAM: '.$program->name.'-'.json_encode($achievedProgramsPerOutcome);
  285. }
  286. return $achievedProgramOutcome;
  287. }
  288. public static function generalComponentPrograms(){
  289. return self::whereIn('id', array(123,124,125,126,127,128,129))->get();
  290. }
  291. public function assessmentOverview(){
  292. $assessment_overview = array();
  293. $assessment_overview['program_courses'] = $this->courses;
  294. $outcomeCount = Outcome::all()->count();
  295. $assessment_overview['outcomes_achieved'] = array_fill(1, $outcomeCount, 0);
  296. $assessment_overview['outcomes_attempted'] = array_fill(1, $outcomeCount, 0);
  297. $assessment_overview['assessed_courses_count'] = 0;
  298. foreach ($assessment_overview['program_courses'] as $course)
  299. {
  300. if($course->outcomes_achieved!=NULL)
  301. {
  302. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  303. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  304. for($i=1; $i<=count($assessment_overview['outcomes_attempted']); $i++)
  305. {
  306. $assessment_overview['outcomes_achieved'][$i]+=$course_outcomes_achieved[$i];
  307. $assessment_overview['outcomes_attempted'][$i]+=$course_outcomes_attempted[$i];
  308. }
  309. $assessment_overview['assessed_courses_count']+=1;
  310. }
  311. }
  312. /**
  313. * List of grouped courses (grouped sections)
  314. */
  315. $assessment_overview['grouped_courses'] = Course::
  316. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  317. ->with('semester')
  318. ->with('program')
  319. ->where('program_id', $this->id)
  320. ->whereIn('semester_id', Session::get('semesters_ids'))
  321. ->groupBy(array('code', 'number', 'semester_id'))
  322. ->orderBy('code')
  323. ->orderBy('number')
  324. ->orderBy('semester_id')
  325. ->get();
  326. Log::info(Course::
  327. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  328. ->with('semester')
  329. ->with('program')
  330. ->where('program_id', $this->id)
  331. ->whereIn('semester_id', Session::get('semesters_ids'))
  332. ->groupBy(array('code', 'number', 'semester_id'))
  333. ->orderBy('code')
  334. ->orderBy('number')
  335. ->orderBy('semester_id')
  336. ->toSql());
  337. return $assessment_overview;
  338. }
  339. }