暫無描述

ProgramsController.php 19KB

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