Nav apraksta

ProgramsController.php 17KB

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