Bez popisu

ProgramsController.php 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. if ($min_start > $semester->start) {
  21. $min_start = $semester->start;
  22. }
  23. if ($max_end < $semester->end) {
  24. $max_end = $semester->end;
  25. }
  26. }
  27. $outcomes = Outcome::where(function ($query) use ($min_start) {
  28. $query->where('deactivation_date', '>=', $min_start)
  29. ->orWhere('deactivation_date', null);
  30. })
  31. ->where('activation_date', '<=', $max_end)
  32. ->where(function ($query2) use ($level) {
  33. $query2->where("level", $level + 1)
  34. ->orWhere("level", 3);
  35. })
  36. ->orderBy('name', 'ASC')
  37. ->get();
  38. $outcomeCount = Outcome::where(function ($query) use ($min_start) {
  39. $query->where('deactivation_date', '>=', $min_start)
  40. ->orWhere('deactivation_date', null);
  41. })
  42. ->where('activation_date', '<=', $max_end)
  43. ->where(function ($query2) use ($level) {
  44. $query2->where("level", $level + 1)
  45. ->orWhere("level", 3);
  46. })
  47. ->count();
  48. foreach ($outcomes as $outcome) {
  49. $outcomes_attempted[$outcome->id] = $program->attempted_outcome($outcome->id, $selected_semesters);
  50. if ($outcomes_attempted[$outcome->id]) $outcomes_achieved[$outcome->id] = $program->achieved_outcome($outcome->id, $selected_semesters);
  51. }
  52. foreach ($outcomes as $outcome) {
  53. $assessed_courses[$outcome->id] = DB::table('activity_criterion')
  54. ->join('activities', 'activity_criterion.activity_id', '=', 'activities.id')
  55. ->join('courses', 'activities.course_id', '=', 'courses.id')
  56. ->join('programs', 'programs.id', '=', 'courses.program_id')
  57. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  58. ->where('criterion_objective_outcome.outcome_id', '=', $outcome->id)
  59. ->where('programs.id', '=', $program->id)
  60. ->where('courses.semester_id', '=', $semester)
  61. ->count(DB::raw('DISTINCT courses.id'));
  62. }
  63. $assessed_courses_count = array_sum($assessed_courses);
  64. /**
  65. * List of grouped courses (grouped sections)
  66. */
  67. $grouped_courses = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  68. ->with('semester')
  69. ->with('program')
  70. ->where('program_id', $program->id)
  71. ->whereIn('semester_id', Session::get('semesters_ids'))
  72. ->groupBy(array('code', 'number', 'semester_id'))
  73. ->orderBy('code')
  74. ->orderBy('number')
  75. ->orderBy('semester_id')
  76. ->get();
  77. // Program contact information
  78. $users = User::select('users.*')
  79. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  80. ->where(function ($query) use ($program) {
  81. $query
  82. ->where('school_id', $program->school_id)
  83. ->where('role', 2);
  84. })
  85. ->orWhere(function ($query) use ($program) {
  86. $query
  87. ->where('role', 3)
  88. ->where('program_id', $program->id);
  89. })
  90. ->orWhere(function ($query) use ($program) {
  91. $query
  92. ->where('role', 4)
  93. ->where('program_id', $program->id);
  94. })
  95. ->get();
  96. // var_dump($outcomes_attempted);
  97. // print "<br>";
  98. // var_dump($outcomes_achieved);
  99. // print "<br>";
  100. return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  101. }
  102. public function showReport()
  103. {
  104. // create an array with the ID of Semesters selected in the form
  105. $selected_semesters_id = array();
  106. $semesters = Semester::all();
  107. foreach ($semesters as $semester) {
  108. if ($semester->is_visible) {
  109. if (Input::get('semester' . $semester->id) != null) {
  110. array_push($selected_semesters_id, $semester->id);
  111. }
  112. }
  113. }
  114. $selected_semesters = DB::table('semesters')
  115. ->wherein('semesters.id', $selected_semesters_id)
  116. ->get();
  117. // create a srting with the selected metodos de divulgfacion
  118. $selected_divulgaciones = '';
  119. $divulgaciones = array(
  120. 'profesores', 'comiteDepartamental', 'comiteFacultadEscuela',
  121. 'pleno', 'estudiantes', 'administrativos', 'senado', 'comunidadWeb',
  122. 'otros'
  123. );
  124. foreach ($divulgaciones as $divulgacion) {
  125. if (Input::get($divulgacion) != null) {
  126. $selected_divulgaciones = $selected_divulgaciones . '\n' . Input::get($divulgacion);
  127. }
  128. }
  129. //OUTCOMES Join criteria join program
  130. $programs = DB::table('programs')
  131. ->select('id', 'name')
  132. ->orderBy('name', 'asc')
  133. ->get();
  134. // $program
  135. $tables_names = '{';
  136. foreach ($programs as $program) {
  137. $tables_names = $tables_names . '"table' . $program->id . '" : "' . $program->name . '",'; // code...
  138. }
  139. $tables_names = $tables_names . '}';
  140. $title = "Programs Reports";
  141. // $title = "Program Report: ".$program->name;
  142. $programs_info = array();
  143. //OUTCOMES Join criteria join program
  144. foreach ($programs as $program) {
  145. $info_by_id = Program::find($program->id);
  146. $domains = DB::table('outcomes')
  147. ->join('criteria', 'criteria.outcome_id', '=', 'outcomes.id')
  148. ->join('programs', 'programs.id', '=', 'criteria.program_id')
  149. ->join('courses', 'courses.program_id', '=', 'programs.id')
  150. ->where('programs.id', $program->id)
  151. ->select('outcomes.name', 'outcomes.activation_date')
  152. ->distinct()
  153. ->orderBy('outcomes.name', 'asc')
  154. ->get();
  155. $courses_used = DB::table('outcomes')
  156. ->join('criteria', 'criteria.outcome_id', '=', 'outcomes.id')
  157. ->join('programs', 'programs.id', '=', 'criteria.program_id')
  158. ->join('courses', 'courses.program_id', '=', 'programs.id')
  159. ->where('programs.id', $program->id)
  160. ->select('courses.number', 'outcomes.name as domain_name', 'courses.code')
  161. ->distinct()
  162. ->orderBy('courses.name', 'asc')
  163. ->get();
  164. $transformative_actions = DB::table('outcomes')
  165. ->join('criteria', 'criteria.outcome_id', '=', 'outcomes.id')
  166. ->join('programs', 'programs.id', '=', 'criteria.program_id')
  167. ->join('courses', 'courses.program_id', '=', 'programs.id')
  168. ->join('activities', 'activities.course_id', '=', 'courses.id')
  169. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  170. ->where('programs.id', $program->id)
  171. ->select('activity_criterion.transformative_actions', 'outcomes.name as domain_name')
  172. ->distinct()
  173. ->orderBy('activity_criterion.transformative_actions', 'asc')
  174. ->get();
  175. $info = array($info_by_id, $domains, $courses_used, $transformative_actions);
  176. array_push($programs_info, $info);
  177. }
  178. return View::make('local.managers.shared.program_report', compact('title', 'programs_info', 'selected_divulgaciones', 'selected_semesters', 'tables_names'));
  179. }
  180. // public function show($id)
  181. // {
  182. //
  183. // $program = Program::find($id);
  184. // $title= $program->school->name.': '.$program->name;
  185. // $program_courses = $program->courses;
  186. // $outcomes = Outcome::orderBy('name', 'asc')->get();
  187. // $schools = School::all();
  188. // $outcomeCount = Outcome::all()->count();
  189. //
  190. //
  191. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  192. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  193. //
  194. // $assessed_courses_count=0;
  195. // foreach ($program_courses as $course)
  196. // {
  197. // if($course->outcomes_achieved!=NULL)
  198. // {
  199. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  200. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  201. // for($i=1; $i<=count($outcomes_attempted); $i++)
  202. // {
  203. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  204. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  205. // }
  206. // $assessed_courses_count+=1;
  207. // }
  208. // }
  209. //
  210. // /**
  211. // * List of grouped courses (grouped sections)
  212. // */
  213. //
  214. // $grouped_courses = Course::
  215. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  216. // ->with('semester')
  217. // ->with('program')
  218. // ->where('program_id', $program->id)
  219. // ->whereIn('semester_id', Session::get('semesters_ids'))
  220. // ->groupBy(array('code', 'number', 'semester_id'))
  221. // ->orderBy('code')
  222. // ->orderBy('number')
  223. // ->orderBy('semester_id')
  224. // ->get();
  225. //
  226. // // Program contact information
  227. // $users = User::
  228. // select('users.*')
  229. // ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  230. // ->where(function($query) use($program)
  231. // {
  232. // $query
  233. // ->where('school_id', $program->school_id)
  234. // ->where('role', 2);
  235. // })
  236. // ->orWhere(function($query) use($program)
  237. // {
  238. // $query
  239. // ->where('role', 3)
  240. // ->where('program_id', $program->id);
  241. // })
  242. // ->orWhere(function($query) use($program)
  243. // {
  244. // $query
  245. // ->where('role', 4)
  246. // ->where('program_id', $program->id);
  247. // })
  248. // ->get();
  249. //
  250. // return View::make('local.managers.shared.program', compact('title', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses', 'program', 'users'));
  251. //
  252. // }
  253. /**
  254. * Info to print a program
  255. */
  256. public function print_program($id)
  257. {
  258. $program = Program::find($id);
  259. $title = $program->name . ' Assessment Report - ' . date('m/d/Y');
  260. $program_courses = $program->courses;
  261. /* //$outcomes = Outcome::orderBy('name', 'asc')->get();
  262. $schools = School::all();
  263. // $outcomeCount = Outcome::all()->count();
  264. $semesters = Session::get('semesters_ids');
  265. $semesters = DB::table('semesters')->where('id', $course->semester_id)->orderBy('start', 'ASC')->first();
  266. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  267. ->whereNull('deleted_at')
  268. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  269. ->orderBy('name', 'ASC')->get();
  270. $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  271. $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  272. $assessed_courses_count=0;
  273. foreach ($program_courses as $course)
  274. {
  275. if($course->outcomes_achieved!=NULL)
  276. {
  277. $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  278. $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  279. for($i=1; $i<=count($outcomes_attempted); $i++)
  280. {
  281. $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  282. $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  283. }
  284. $assessed_courses_count+=1;
  285. }
  286. }
  287. /**
  288. * List of grouped courses (grouped sections)
  289. */
  290. /* $grouped_courses = Course::
  291. select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  292. ->with('semester')
  293. ->with('program')
  294. ->where('program_id', $program->id)
  295. ->whereIn('semester_id', Session::get('semesters_ids'))
  296. ->groupBy(array('code', 'number', 'semester_id'))
  297. ->orderBy('code')
  298. ->orderBy('number')
  299. ->orderBy('semester_id')
  300. ->get();
  301. */
  302. $semesters = Session::get('semesters_ids');
  303. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  304. Log::info($semesters->start);
  305. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  306. ->whereNull('deleted_at')
  307. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  308. ->orderBy('name', 'ASC')->get();
  309. $outcomeCount = count($outcomes);
  310. $programs_array = array();
  311. $programs_contact = array();
  312. foreach ($programs as $program) {
  313. $program_array = array();
  314. $program_array['program'] = $program;
  315. $program_array['outcomes_achieved'] = [];
  316. $program_array['outcomes_attempted'] = [];
  317. $program_array['program_courses'] = $program->courses;
  318. $program_array['grouped_objectives'] = $program->objectives();
  319. $program_array['assessed_courses_count'] = 0;
  320. foreach ($program_array['program_courses'] as $course) {
  321. if (!empty($course->outcomes_ach())) {
  322. $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  323. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  324. Log::info($program_array['course_outcomes_achieved']);
  325. foreach ($program_array['course_outcomes_achieved'] as $i => $score) {
  326. if (array_key_exists($i, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  327. else $program_array['outcomes_achieved'][$i] = $program_array['course_outcomes_achieved'][$i];
  328. }
  329. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  330. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  331. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  332. }
  333. $program_array['assessed_courses_count'] += 1;
  334. }
  335. }
  336. /**
  337. * List of grouped courses (grouped sections)
  338. */
  339. //old code
  340. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  341. ->with('semester')
  342. ->with('program')
  343. ->where('program_id', $program->id)
  344. ->whereIn('semester_id', Session::get('semesters_ids'))
  345. ->groupBy(array('code', 'number', 'semester_id'))
  346. ->orderBy('code')
  347. ->orderBy('number')
  348. ->orderBy('semester_id')
  349. ->get(); */
  350. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  351. ->with('semester')
  352. ->with('program')
  353. ->where('program_id', $program->id)
  354. ->whereIn('semester_id', Session::get('semesters_ids'))
  355. ->groupBy(array('code', 'number', 'semester_id'))
  356. ->orderBy('code')
  357. ->orderBy('number')
  358. ->orderBy('semester_id')
  359. ->get();
  360. $programs_array[] = $program_array;
  361. // Program contact information
  362. $users = User::select('users.*')
  363. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  364. ->where(function ($query) use ($program) {
  365. $query
  366. ->where('school_id', $program->school_id)
  367. ->where('role', 2);
  368. })
  369. ->orWhere(function ($query) use ($program) {
  370. $query
  371. ->where('role', 3)
  372. ->where('program_id', $program->id);
  373. })
  374. ->orWhere(function ($query) use ($program) {
  375. $query
  376. ->where('role', 4)
  377. ->where('program_id', $program->id);
  378. })
  379. ->get();
  380. $programs_contact[] = $users;
  381. }
  382. return View::make('local.managers.shared.print_program', compact('title', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  383. }
  384. /**
  385. * A list of all programs
  386. */
  387. public function index()
  388. {
  389. $title = "Programs by School";
  390. $programs = Program::orderBy('name')->get();
  391. $schools = School::all();
  392. $semesters = Semester::all();
  393. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'semesters', 'title'));
  394. }
  395. /**
  396. * Fetch a program
  397. */
  398. public function fetch()
  399. {
  400. Log::info('id:' . Input::get('id'));
  401. return School::find(Input::get('id'))->programs;
  402. }
  403. }