Açıklama Yok

ProgramsController.php 18KB

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