Aucune description

ProgramsController.php 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. $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. $semesters2 = Semester::whereIn('id',Session::get('semesters_ids'))->get();
  298. $program_courses = $program->courses;
  299. //$outcomes = Outcome::orderBy('name', 'asc')->get();
  300. $outcomes = Outcome::active_by_semesters($semesters2, $program->is_graduate);
  301. $outcomeCount = count($outcomes);
  302. $outcomes_achieved = [];
  303. $outcomes_attempted = [];
  304. // Log::info($program_courses);
  305. foreach($outcomes as $outcome)
  306. {
  307. $outcomes_attempted[$outcome->id]=0;
  308. $outcomes_achieved[$outcome->id]=0;
  309. }
  310. $assessed_courses_count=0;
  311. foreach ($program_courses as $course) {
  312. if ($course->outcomes_att()) {
  313. $course_outcomes_attempted = $course->outcomes_att();
  314. foreach ($course_outcomes_attempted as $outcome => $score) {
  315. if (array_key_exists($outcome, $outcomes_attempted))
  316. $outcomes_attempted[$outcome] += $score;
  317. else $outcomes_attempted[$outcome] = $score;
  318. }
  319. $assessed_courses_count+=1;
  320. }
  321. if ($course->outcomes_ach()) {
  322. $course_outcomes_achieved = $course->outcomes_ach();
  323. foreach ($course_outcomes_achieved as $outcome => $score) {
  324. if (array_key_exists($outcome, $outcomes_achieved))
  325. $outcomes_achieved[$outcome] += $score;
  326. else $outcomes_achieved[$outcome] = $score;
  327. }
  328. }
  329. }
  330. // $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  331. // ->whereNull('deleted_at')
  332. // ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  333. // ->orderBy('name', 'ASC')->get();
  334. //
  335. // $outcomes_achieved = array_fill(1, $outcomeCount, 0);
  336. // $outcomes_attempted = array_fill(1, $outcomeCount, 0);
  337. // $assessed_courses_count=0;
  338. // foreach ($program_courses as $course)
  339. // {
  340. // if($course->outcomes_achieved!=NULL)
  341. // {
  342. // $course_outcomes_achieved =json_decode($course->outcomes_achieved, true);
  343. // $course_outcomes_attempted =json_decode($course->outcomes_attempted, true);
  344. // for($i=1; $i<=count($outcomes_attempted); $i++)
  345. // {
  346. // $outcomes_achieved[$i]+=$course_outcomes_achieved[$i];
  347. // $outcomes_attempted[$i]+=$course_outcomes_attempted[$i];
  348. // }
  349. // $assessed_courses_count+=1;
  350. // }
  351. // }
  352. /**
  353. * List of grouped courses (grouped sections)
  354. */
  355. // select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  356. $grouped_courses = Course::
  357. select(DB::raw('id, name, code, number, semester_id, program_id'))
  358. ->with('semester')
  359. ->with('program')
  360. ->where('program_id', $program->id)
  361. ->whereIn('semester_id', Session::get('semesters_ids'))
  362. ->groupBy(array('code', 'number', 'semester_id'))
  363. ->orderBy('code')
  364. ->orderBy('number')
  365. ->orderBy('semester_id')
  366. ->get();
  367. foreach($grouped_courses as &$course)
  368. {
  369. $course->outcomes_attempted=null;
  370. if(count($course->assessedActivities) and count($course->publishedActivities))
  371. {
  372. $course->outcomes_attempted=true;
  373. }
  374. }
  375. // Log::info($grouped_courses);
  376. // exit();
  377. $semesters = Session::get('semesters_ids');
  378. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  379. Log::info($semesters->start);
  380. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  381. ->whereNull('deleted_at')
  382. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  383. ->orderBy('name', 'ASC')->get();
  384. $outcomeCount = count($outcomes);
  385. $programs_array = array();
  386. $programs_contact = array();
  387. $program_array = array();
  388. $program_array['program'] = $program;
  389. $program_array['outcomes_achieved'] = [];
  390. $program_array['outcomes_attempted'] = [];
  391. $program_array['program_courses'] = $program->courses;
  392. // $program_array['grouped_objectives'] = $program->objectives();
  393. $program_array['assessed_courses_count'] = 0;
  394. foreach ($program_array['program_courses'] as $course) {
  395. if (!$program_array['course_outcomes_achieved'] = $course->outcomes_ach()) {
  396. // $program_array['course_outcomes_achieved'] = $course->outcomes_ach();
  397. $program_array['course_outcomes_attempted'] = $course->outcomes_att();
  398. Log::info($program_array['course_outcomes_achieved']);
  399. foreach ($program_array['course_outcomes_achieved'] as $i => $score) {
  400. if (array_key_exists($i, $program_array['outcomes_achieved'])) $program_array['outcomes_achieved'][$i] += $program_array['course_outcomes_achieved'][$i];
  401. else $program_array['outcomes_achieved'][$i] = $program_array['course_outcomes_achieved'][$i];
  402. }
  403. foreach ($program_array['course_outcomes_attempted'] as $i => $score) {
  404. if (array_key_exists($i, $program_array['outcomes_attempted'])) $program_array['outcomes_attempted'][$i] += $program_array['course_outcomes_attempted'][$i];
  405. else $program_array['outcomes_attempted'][$i] = $program_array['course_outcomes_attempted'][$i];
  406. }
  407. $program_array['assessed_courses_count'] += 1;
  408. }
  409. }
  410. /**
  411. * List of grouped courses (grouped sections)
  412. */
  413. //old code
  414. /* $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, max(outcomes_attempted) as outcomes_attempted, semester_id, program_id'))
  415. ->with('semester')
  416. ->with('program')
  417. ->where('program_id', $program->id)
  418. ->whereIn('semester_id', Session::get('semesters_ids'))
  419. ->groupBy(array('code', 'number', 'semester_id'))
  420. ->orderBy('code')
  421. ->orderBy('number')
  422. ->orderBy('semester_id')
  423. ->get(); */
  424. $program_array['grouped_courses'] = Course::select(DB::raw('name, code, number, semester_id, program_id'))
  425. ->with('semester')
  426. ->with('program')
  427. ->where('program_id', $program->id)
  428. ->whereIn('semester_id', Session::get('semesters_ids'))
  429. ->groupBy(array('code', 'number', 'semester_id'))
  430. ->orderBy('code')
  431. ->orderBy('number')
  432. ->orderBy('semester_id')
  433. ->get();
  434. $programs_array[] = $program_array;
  435. // Program contact information
  436. $users = User::select('users.*')
  437. ->leftJoin('program_user', 'users.id', '=', 'program_user.user_id')
  438. ->where(function ($query) use ($program) {
  439. $query
  440. ->where('school_id', $program->school_id)
  441. ->where('role', 2);
  442. })
  443. ->orWhere(function ($query) use ($program) {
  444. $query
  445. ->where('role', 3)
  446. ->where('program_id', $program->id);
  447. })
  448. ->orWhere(function ($query) use ($program) {
  449. $query
  450. ->where('role', 4)
  451. ->where('program_id', $program->id);
  452. })
  453. ->get();
  454. $programs_contact[] = $users;
  455. return View::make('local.managers.shared.print_program', compact('title', 'program', 'outcomes', 'outcomes_attempted', 'outcomes_achieved', 'schools', 'program_courses', 'assessed_courses_count', 'grouped_courses'));
  456. }
  457. /**
  458. * A list of all programs
  459. */
  460. public function index()
  461. {
  462. $title = "Programs by School";
  463. $programs = Program::orderBy('name')->get();
  464. $schools = School::all();
  465. $semesters = Semester::all();
  466. return View::make('local.managers.shared.programs', compact('programs', 'schools', 'semesters', 'title'));
  467. }
  468. /**
  469. * Fetch a program
  470. */
  471. public function fetch()
  472. {
  473. //Log::info('id:' . Input::get('id'));
  474. return School::find(Input::get('id'))->programs;
  475. }
  476. }