Keine Beschreibung

ProgramsController.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 showReport()
  118. {
  119. // create an array with the ID of Semesters selected in the form
  120. $selected_semesters_id = array();
  121. $semesters = Semester::all();
  122. foreach ($semesters as $semester) {
  123. if ($semester->is_visible){
  124. if (Input::get('semester'.$semester->id)!=null){
  125. array_push($selected_semesters_id, $semester->id);
  126. }
  127. }
  128. }
  129. $selected_semesters = DB::table('semesters')
  130. ->wherein('semesters.id',$selected_semesters_id)
  131. ->get();
  132. // create a srting with the selected metodos de divulgfacion
  133. $selected_divulgaciones = '';
  134. $divulgaciones = array('profesores','comiteDepartamental','comiteFacultadEscuela',
  135. 'pleno','estudiantes','administrativos','senado','comunidadWeb',
  136. 'otros');
  137. foreach ($divulgaciones as $divulgacion) {
  138. if (Input::get($divulgacion)!=null){
  139. $selected_divulgaciones = $selected_divulgaciones.'\n'.Input::get($divulgacion);
  140. }
  141. }
  142. //OUTCOMES Join criteria join program
  143. $programs = DB::table('programs')
  144. ->select('id','name')
  145. ->orderBy('name', 'asc')
  146. ->get();
  147. // $program
  148. $tables_names = '{';
  149. foreach ($programs as $program) {
  150. $tables_names = $tables_names.'"table'.$program->id.'" : "'.$program->name.'",';// code...
  151. }
  152. $tables_names = $tables_names.'}';
  153. $title = "Programs Reports";
  154. // $title = "Program Report: ".$program->name;
  155. $programs_info = array();
  156. //OUTCOMES Join criteria join program
  157. foreach ($programs as $program) {
  158. $info_by_id = Program::find($program->id);
  159. $domains = DB::table('outcomes')
  160. ->join('criteria','criteria.outcome_id','=','outcomes.id')
  161. ->join('programs','programs.id','=','criteria.program_id')
  162. ->join('courses','courses.program_id','=','programs.id')
  163. ->where('programs.id',$program->id)
  164. ->select('outcomes.name','outcomes.activation_date')
  165. ->distinct()
  166. ->orderBy('outcomes.name', 'asc')
  167. ->get();
  168. $courses_used = DB::table('outcomes')
  169. ->join('criteria','criteria.outcome_id','=','outcomes.id')
  170. ->join('programs','programs.id','=','criteria.program_id')
  171. ->join('courses','courses.program_id','=','programs.id')
  172. ->where('programs.id',$program->id)
  173. ->select('courses.number', 'outcomes.name as domain_name', 'courses.code')
  174. ->distinct()
  175. ->orderBy('courses.name', 'asc')
  176. ->get();
  177. $transformative_actions = DB::table('outcomes')
  178. ->join('criteria','criteria.outcome_id','=','outcomes.id')
  179. ->join('programs','programs.id','=','criteria.program_id')
  180. ->join('courses','courses.program_id','=','programs.id')
  181. ->join('activities','activities.course_id','=','courses.id')
  182. ->join('activity_criterion','activity_criterion.activity_id','=','activities.id')
  183. ->where('programs.id',$program->id)
  184. ->select('activity_criterion.transformative_actions', 'outcomes.name as domain_name')
  185. ->distinct()
  186. ->orderBy('activity_criterion.transformative_actions', 'asc')
  187. ->get();
  188. $info = array($info_by_id, $domains, $courses_used, $transformative_actions);
  189. array_push($programs_info, $info);
  190. }
  191. return View::make('local.managers.shared.program_report', compact('title','programs_info','selected_divulgaciones','selected_semesters','tables_names'));
  192. }
  193. // public function show($id)
  194. // {
  195. //
  196. // $program = Program::find($id);
  197. // $title= $program->school->name.': '.$program->name;
  198. // $program_courses = $program->courses;
  199. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  200. // $schools = School::all();
  201. // $outcomeCount = Outcome::all()->count();
  202. //
  203. //
  204. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  205. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  206. //
  207. // $assessed_courses_count=0;
  208. // foreach ($program_courses as $course)
  209. // {
  210. // if($course->outcomes_achieved!=NULL)
  211. // {
  212. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  213. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  214. // for($i=1; $i<=count($outcomes_attempted); $i++)
  215. // {
  216. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  217. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  218. // }
  219. // $assessed_courses_count+=1;
  220. // }
  221. // }
  222. //
  223. // /**
  224. // * List of grouped courses (grouped sections)
  225. // */
  226. //
  227. // $grouped_courses = Course::
  228. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  229. // ->with('semester')
  230. // ->with('program')
  231. // ->where('program_id', $program->id)
  232. // ->whereIn('semester_id', Session::get('semesters_ids'))
  233. // ->groupBy(array('code', 'number', 'semester_id'))
  234. // ->orderBy('code')
  235. // ->orderBy('number')
  236. // ->orderBy('semester_id')
  237. // ->get();
  238. //
  239. // // Program contact information
  240. // $users = User::
  241. // select('users.*')
  242. // ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  243. // ->where(function($query) use($program)
  244. // {
  245. // $query
  246. // ->where('school_id', $program->school_id)
  247. // ->where('role', 2);
  248. // })
  249. // ->orWhere(function($query) use($program)
  250. // {
  251. // $query
  252. // ->where('role', 3)
  253. // ->where('program_id', $program->id);
  254. // })
  255. // ->orWhere(function($query) use($program)
  256. // {
  257. // $query
  258. // ->where('role', 4)
  259. // ->where('program_id', $program->id);
  260. // })
  261. // ->get();
  262. //
  263. // return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  264. //
  265. // }
  266. /**
  267. * Info to print a program
  268. */
  269. public function print_program($id)
  270. {
  271. $program = Program::find($id);
  272. $title= $program->name.' Assessment Report - '.date('m/d/Y');
  273. $program_courses = $program->courses;
  274. $outcomes = Outcome::orderBy('name', 'asc')->get();
  275. $schools = School::all();
  276. $outcomeCount = Outcome::all()->count();
  277. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  278. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  279. $assessed_courses_count=0;
  280. foreach ($program_courses as $course)
  281. {
  282. if($course->outcomes_achieved!=NULL)
  283. {
  284. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  285. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  286. for($i=1; $i<=count($outcomes_attempted); $i++)
  287. {
  288. $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  289. $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  290. }
  291. $assessed_courses_count+=1;
  292. }
  293. }
  294. /**
  295. * List of grouped courses (grouped sections)
  296. */
  297. $grouped_courses = Course::
  298. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  299. ->with('semester')
  300. ->with('program')
  301. ->where('program_id', $program->id)
  302. ->whereIn('semester_id', Session::get('semesters_ids'))
  303. ->groupBy(array('code', 'number', 'semester_id'))
  304. ->orderBy('code')
  305. ->orderBy('number')
  306. ->orderBy('semester_id')
  307. ->get();
  308. return View::make('local.managers.shared.print_program', compact('title', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  309. }
  310. /**
  311. * A list of all programs
  312. */
  313. public function index()
  314. {
  315. $title = "Programs by School";
  316. $programs = Program::orderBy('name')->get();
  317. $schools = School::all();
  318. $semesters = Semester::all();
  319. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'semesters', 'title'));
  320. }
  321. /**
  322. * Fetch a program
  323. */
  324. public function fetch()
  325. {
  326. Log::info('id:'.Input::get('id'));
  327. return School::find(Input::get('id'))->programs;
  328. }
  329. }