Няма описание

ProgramsController.php 19KB

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