Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <?php
  2. class ProgramsController extends \BaseController
  3. {
  4. /**
  5. * Shows a particular program
  6. */
  7. public function show($id)
  8. {
  9. $program = Program::find($id);
  10. $title= $program->school->name.': '.$program->name;
  11. $program_courses = $program->courses;
  12. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  13. $schools = School::all();
  14. // $outcomeCount = Outcome::all()->count();
  15. $selected_semesters = Semester::find(Session::get('semesters_ids'));
  16. $level=$program->is_graduate;
  17. $min_start="9000-01-01 00:00:00";
  18. $max_end="1000-01-01 00:00:00";
  19. foreach($selected_semesters as $semester)
  20. {
  21. if($min_start>$semester->start)
  22. {
  23. $min_start=$semester->start;
  24. }
  25. if($max_end<$semester->end)
  26. {
  27. $max_end=$semester->end;
  28. }
  29. }
  30. $outcomes = Outcome::where(function($query) use ($min_start)
  31. {
  32. $query->where('deactivation_date', '>=', $min_start)
  33. ->orWhere('deactivation_date', null);
  34. })
  35. ->where('activation_date', '<=', $max_end)
  36. ->where(function($query2) use ($level)
  37. {
  38. $query2->where("level", $level+1)
  39. ->orWhere("level",3);
  40. })
  41. ->orderBy('name', 'ASC')
  42. ->get();
  43. $outcomeCount = Outcome::where(function($query) use ($min_start)
  44. {
  45. $query->where('deactivation_date', '>=', $min_start)
  46. ->orWhere('deactivation_date', null);
  47. })
  48. ->where('activation_date', '<=', $max_end)
  49. ->where(function($query2) use ($level)
  50. {
  51. $query2->where("level",$level+1)
  52. ->orWhere("level",3);
  53. })
  54. ->count();
  55. foreach($outcomes as $outcome)
  56. {
  57. $outcomes_attempted[$outcome->id]=$program->attempted_outcome($outcome->id, $selected_semesters);
  58. if($outcomes_attempted[$outcome->id])$outcomes_achieved[$outcome->id]=$program->achieved_outcome($outcome->id, $selected_semesters);
  59. }
  60. foreach($outcomes as $outcome)
  61. {
  62. $assessed_courses[$outcome->id]=DB::table('activity_criterion')
  63. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  64. ->join('courses', 'activities.course_id', '=', 'courses.id')
  65. ->join('programs', 'programs.id', '=', 'courses.program_id')
  66. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  67. ->where('criterion_objective_outcome.outcome_id','=',$outcome->id)
  68. ->where('programs.id','=',$program->id)
  69. ->where('courses.semester_id','=',$semester)
  70. ->count(DB::raw('DISTINCT courses.id'))
  71. ;
  72. }
  73. $assessed_courses_count=array_sum($assessed_courses);
  74. /**
  75. * List of grouped courses (grouped sections)
  76. */
  77. $grouped_courses = Course::
  78. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  79. ->with('semester')
  80. ->with('program')
  81. ->where('program_id', $program->id)
  82. ->whereIn('semester_id', Session::get('semesters_ids'))
  83. ->groupBy(array('code', 'number', 'semester_id'))
  84. ->orderBy('code')
  85. ->orderBy('number')
  86. ->orderBy('semester_id')
  87. ->get();
  88. // Program contact information
  89. $users = User::
  90. select('users.*')
  91. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  92. ->where(function($query) use($program)
  93. {
  94. $query
  95. ->where('school_id', $program->school_id)
  96. ->where('role', 2);
  97. })
  98. ->orWhere(function($query) use($program)
  99. {
  100. $query
  101. ->where('role', 3)
  102. ->where('program_id', $program->id);
  103. })
  104. ->orWhere(function($query) use($program)
  105. {
  106. $query
  107. ->where('role', 4)
  108. ->where('program_id', $program->id);
  109. })
  110. ->get();
  111. // var_dump($outcomes_attempted);
  112. // print "<br>";
  113. // var_dump($outcomes_achieved);
  114. // print "<br>";
  115. return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  116. }
  117. // public function show($id)
  118. // {
  119. //
  120. // $program = Program::find($id);
  121. // $title= $program->school->name.': '.$program->name;
  122. // $program_courses = $program->courses;
  123. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  124. // $schools = School::all();
  125. // $outcomeCount = Outcome::all()->count();
  126. //
  127. //
  128. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  129. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  130. //
  131. // $assessed_courses_count=0;
  132. // foreach ($program_courses as $course)
  133. // {
  134. // if($course->outcomes_achieved!=NULL)
  135. // {
  136. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  137. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  138. // for($i=1; $i<=count($outcomes_attempted); $i++)
  139. // {
  140. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  141. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  142. // }
  143. // $assessed_courses_count+=1;
  144. // }
  145. // }
  146. //
  147. // /**
  148. // * List of grouped courses (grouped sections)
  149. // */
  150. //
  151. // $grouped_courses = Course::
  152. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  153. // ->with('semester')
  154. // ->with('program')
  155. // ->where('program_id', $program->id)
  156. // ->whereIn('semester_id', Session::get('semesters_ids'))
  157. // ->groupBy(array('code', 'number', 'semester_id'))
  158. // ->orderBy('code')
  159. // ->orderBy('number')
  160. // ->orderBy('semester_id')
  161. // ->get();
  162. //
  163. // // Program contact information
  164. // $users = User::
  165. // select('users.*')
  166. // ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  167. // ->where(function($query) use($program)
  168. // {
  169. // $query
  170. // ->where('school_id', $program->school_id)
  171. // ->where('role', 2);
  172. // })
  173. // ->orWhere(function($query) use($program)
  174. // {
  175. // $query
  176. // ->where('role', 3)
  177. // ->where('program_id', $program->id);
  178. // })
  179. // ->orWhere(function($query) use($program)
  180. // {
  181. // $query
  182. // ->where('role', 4)
  183. // ->where('program_id', $program->id);
  184. // })
  185. // ->get();
  186. //
  187. // return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  188. //
  189. // }
  190. /**
  191. * Info to print a program
  192. */
  193. public function print_program($id)
  194. {
  195. $program = Program::find($id);
  196. $title= $program->name.' Assessment Report - '.date('m/d/Y');
  197. $program_courses = $program->courses;
  198. $outcomes = Outcome::orderBy('name', 'asc')->get();
  199. $schools = School::all();
  200. $outcomeCount = Outcome::all()->count();
  201. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  202. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  203. $assessed_courses_count=0;
  204. foreach ($program_courses as $course)
  205. {
  206. if($course->outcomes_achieved!=NULL)
  207. {
  208. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  209. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  210. for($i=1; $i<=count($outcomes_attempted); $i++)
  211. {
  212. $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  213. $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  214. }
  215. $assessed_courses_count+=1;
  216. }
  217. }
  218. /**
  219. * List of grouped courses (grouped sections)
  220. */
  221. $grouped_courses = Course::
  222. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  223. ->with('semester')
  224. ->with('program')
  225. ->where('program_id', $program->id)
  226. ->whereIn('semester_id', Session::get('semesters_ids'))
  227. ->groupBy(array('code', 'number', 'semester_id'))
  228. ->orderBy('code')
  229. ->orderBy('number')
  230. ->orderBy('semester_id')
  231. ->get();
  232. return View::make('local.managers.shared.print_program', compact('title', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  233. }
  234. /**
  235. * A list of all programs
  236. */
  237. public function index()
  238. {
  239. $title = "Programs by School";
  240. $programs = Program::orderBy('name')->get();
  241. $schools = School::all();
  242. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'title'));
  243. }
  244. /**
  245. * Fetch a program
  246. */
  247. public function fetch()
  248. {
  249. Log::info('id:'.Input::get('id'));
  250. return School::find(Input::get('id'))->programs;
  251. }
  252. }