Ingen beskrivning

AnnualPlansController.php 60KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. <?php
  2. use Barryvdh\DomPDF\PDF as PDF;
  3. use Illuminate\Support\Facades\Auth;
  4. use Illuminate\Support\Facades\Input;
  5. class AnnualPlansController extends \BaseController
  6. {
  7. /**
  8. * Checks whether a user has permission to view a page in this controller
  9. *
  10. * @var User $user Authenticated user
  11. */
  12. private function userHasAccess($program_id)
  13. {
  14. $user = Auth::user();
  15. switch ($user->role) {
  16. case '3':
  17. $programs = $user->programs->lists('id');
  18. // If program does not belong to user, show 403
  19. if (!in_array($program_id, $programs))
  20. return false;
  21. break;
  22. case '2':
  23. $programs = Program::where('school_id', $user->school_id)->lists('id');
  24. // If program is not in user's school, show 403
  25. if (!in_array($program_id, $programs))
  26. return false;
  27. break;
  28. case '4':
  29. return false;
  30. }
  31. return true;
  32. }
  33. public function viewAllPlans($program_id)
  34. {
  35. $program = Program::find($program_id);
  36. $title = "Annual Plans for " . $program->name;
  37. $annual_plans = DB::select("select semester_start, semester_end, program_id, annual_plans.id, academic_year from annual_plans, annual_cycle where annual_plans.annual_cycle_id = annual_cycle.id and program_id ={$program_id} order by semester_start desc");
  38. return View::make('local.managers.shared.view-annual-plans', compact('title', 'program_id', 'annual_plans'));
  39. }
  40. /**
  41. * Lists annual plans by year and program
  42. * @var string $title Title for page
  43. * @var Program $programs Collection of programs user has access to
  44. * @var User $user Authenticated user
  45. * @var Quinquennium $quinquenniums All current or past quinquenniums
  46. * @var Quinquennium $current_quinquennium Current quinquennium
  47. */
  48. public function postReport()
  49. {
  50. $program_id = Input::get('program_id') + 0;
  51. $realized = Input::get('realized');
  52. $logrado = Input::get('logrado');
  53. $continued = Input::get('continued');
  54. $semester = Input::get('semester');
  55. $typ_objective = Input::get('typ_objective');
  56. $transformative = Input::get('transformative');
  57. $comments = Input::get("comments");
  58. $annual_id = Input::get("annual_id") + 0;
  59. $id = Auth::user()['id'];
  60. for ($i = 0; $i < count($semester); $i++) {
  61. $real = $realized[$i] + 0;
  62. $logr = $logrado[$i] + 0;
  63. $cont = $continued[$i] + 0;
  64. $obj = $typ_objective[$i] + 0;
  65. $trans = $transformative[$i] + 0;
  66. $sem = $semester[$i] + 0;
  67. $comment = $comments[$i];
  68. //if it was continued
  69. if ($real == 1) $real = 2;
  70. else $real = 1;
  71. if ($cont == 1) $cont = $sem + 1;
  72. else $cont = "NULL";
  73. $annual_trans_id = DB::select("select id from annual_plan_transformative where annual_plan_id ={$annual_id} and trans_id = {$trans} and typ_semester_objective_id = {$obj}")[0]->id;
  74. $queryUpdate = DB::select("select * from annual_report_transformative where annual_trans_id = {$annual_trans_id}");
  75. if (!count($queryUpdate)) {
  76. DB::insert("insert into annual_report_transformative (accomplished, cycle_of_life, semester_used, semester_continue, annual_trans_id, supervised_coordinator_id, comments) values ({$logr},{$real},{$sem},{$cont},{$annual_trans_id}, {$id}, '{$comment}')");
  77. } else {
  78. DB::update("update annual_report_transformative set accomplished = {$logr}, cycle_of_life ={$real}, semester_used ={$sem}, semester_continue={$cont}, supervised_coordinator_id={$id}, comments = '{$comment}' where annual_trans_id ={$annual_trans_id}");
  79. }
  80. }
  81. return;
  82. }
  83. /*public function index()
  84. {
  85. $title = 'Annual Plans';
  86. $user = Auth::user();
  87. $quinquenniums = Quinquennium::where('start_date', '<=', date('Y-m-d'))->get();
  88. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  89. ->where('end_date', '>=', date('Y-m-d'))
  90. ->first();
  91. switch ($user->role) {
  92. case '1':
  93. $programs = Program::all();
  94. break;
  95. case '2':
  96. $programs = Program::where('school_id', $user->school_id)->get();
  97. break;
  98. case 3:
  99. $programs = $user->programs;
  100. break;
  101. default:
  102. App::abort('404');
  103. break;
  104. }
  105. return View::make('local.managers.shared.index_annual_plans', compact('title', 'quinquenniums', 'programs', 'current_quinquennium'));
  106. }*/
  107. public function adminIndex($school_id)
  108. {
  109. $title = "Annual Plans";
  110. $programs = Program::where("school_id", $school_id)->get();
  111. return View::make('local.managers.admins.appraisal-program', compact('title', 'programs'));
  112. }
  113. public function showPlan($program_id, $typ_id = null)
  114. {
  115. $program = Program::find($program_id);
  116. $title = "Annual Plans for " . $program->name;
  117. //$typ_parts = DB::select("select * from typ_parts");
  118. // $current_typ = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'))[0];
  119. $current_typ_arr = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'));
  120. // var_dump($current_typ);exit();
  121. if (!empty($current_typ_arr)) $current_typ = $current_typ_arr[0];
  122. else {
  123. $current_typ = new stdClass();
  124. $current_typ->id = 0;
  125. }
  126. //$program = Program::where('id', '=', $program_id)->first();
  127. //Dame los annual plans que esten dentro del three year plan
  128. $annual_plans = DB::table('annual_cycle')
  129. ->join('annual_plans', 'annual_cycle_id', '=', 'annual_cycle.id')
  130. ->where('program_id', $program_id)
  131. ->orderBy('semester_start', 'desc')
  132. ->get();
  133. /*$annual_plans = DB::select("
  134. select
  135. academic_year,
  136. semester_start,
  137. semester_end,
  138. program_id,
  139. annual_plans.id as id
  140. from annual_plans
  141. join annual_cycle on annual_cycle_id = annual_cycle.id
  142. where program_id = {$program_id}
  143. and(
  144. semester_start in(
  145. select semester_id
  146. from typ_semester_outcome
  147. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  148. where program_id = {$program_id} )
  149. or semester_end in(
  150. select semester_id
  151. from typ_semester_outcome
  152. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  153. where program_id = {$program_id} )
  154. )
  155. order by semester_start desc");*/
  156. // $annual_plans = DB::select("select academic_year, semester_start, semester_end, program_id, annual_plans.id as id from annual_plans, annual_cycle where program_id = {$program_id} and annual_cycle.id = annual_plans.annual_cycle_id order by annual_plans.id desc ");
  157. // Log::info($annual_plans);
  158. $outcomes = array();
  159. $allSemesterOrder = array();
  160. Log::info($annual_plans);
  161. /*foreach ($annual_plans as $an_plan) {
  162. Log::info($an_plan->id);
  163. $outcomes[$an_plan->id]["first"] = DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id = {$an_plan->semester_start} and typ_program_id in (select id from typ_program where program_id ={$an_plan->program_id} and three_year_plan_id ={$current_typ->id} ))");
  164. $allSemesterOrder[$an_plan->id]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  165. $outcomes[$an_plan->id]["second"] = DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id ={$an_plan->semester_end} and typ_program_id in (select id from typ_program where program_id ={$an_plan->program_id} and three_year_plan_id = {$current_typ->id} ))");
  166. $allSemesterOrder[$an_plan->id]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  167. }*/
  168. //$alltyp = DB::select('select * from three_year_plan order by id desc');
  169. //$current_typ = $current_typ->id;
  170. return View::make('local.managers.shared.annual-plans', compact('title', 'annual_plans', 'current_typ', 'program', 'outcomes', 'allSemesterOrder', 'alltyp'));
  171. }
  172. public function fetchInfo()
  173. {
  174. Log::info(Input::get('id'));
  175. $an_plan = DB::table("annual_plans")
  176. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  177. ->where('annual_plans.id', '=', Input::get('id'))
  178. ->select('annual_plans.id as id', 'program_id', 'academic_year', 'semester_start', 'semester_end', 'is_submitted')
  179. ->first();
  180. $years = explode('-', $an_plan->academic_year);
  181. $current_typ_program = DB::table('typ_program')
  182. ->join('typ_semester_outcome', 'typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  183. ->where('program_id', $an_plan->program_id)
  184. ->where(function ($query) use (&$an_plan) {
  185. $query->where('semester_id', $an_plan->semester_start)
  186. ->orWhere('semester_id', $an_plan->semester_end);
  187. })
  188. ->select('typ_program.*')
  189. ->first();
  190. Log::info(array($an_plan));
  191. Log::info(array($current_typ_program));
  192. //DB::select("select * from typ_program where program_id = {$an_plan->program_id} and three_year_plan_id in (select id from three_year_plan where year_start <= {$years[0]} and year_end>= {$years[1]})")[0];
  193. $json_to_send = [];
  194. $json_to_send["annual_plans"] = $an_plan;
  195. $json_to_send["outcomes"]["first"] = DB::table('outcomes')
  196. ->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  197. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  198. ->join('typ_semester_courses', 'typ_semester_objectives.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  199. ->where('semester_id', $an_plan->semester_start)
  200. ->where('typ_program_id', $current_typ_program->id)
  201. ->select('outcomes.*', 'typ_semester_outcome.id as typ_semester_outcome_id')
  202. ->groupBy('typ_semester_outcome_id')
  203. ->get();
  204. //DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id = {$an_plan->semester_start} and typ_program_id = {$current_typ_program->id})");
  205. $json_to_send["allSemesterOrder"]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  206. $json_to_send["outcomes"]["second"] = DB::table('outcomes')
  207. ->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  208. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  209. ->join('typ_semester_courses', 'typ_semester_objectives.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  210. ->where('semester_id', $an_plan->semester_end)
  211. ->where('typ_program_id', $current_typ_program->id)
  212. ->select('outcomes.*', 'typ_semester_outcome.id as typ_semester_outcome_id')
  213. ->groupBy('typ_semester_outcome_id')
  214. ->get();
  215. //DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id ={$an_plan->semester_end} and typ_program_id = {$current_typ_program->id})");
  216. $json_to_send["allSemesterOrder"]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  217. return json_encode($json_to_send);
  218. }
  219. /**
  220. * Page to create a new plan for the current quinquennium
  221. * @var string $title Title for page
  222. * @var Program $programs Collection of programs user has access to
  223. * @var Outcome $outcomes List of outcomes ordered by name
  224. * @var User $user Currently logged user
  225. * @var Course $courses Courses for a particular program
  226. */
  227. public function fetchTYP($program_id)
  228. {
  229. $typ_info = array();
  230. $semester = DB::select("select * from semesters where id=?", array(Input::get('semester')))[0];
  231. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  232. //$typ_info['courses'] = DB::select("select * from courses where id in (select course_id from typ_semester_courses where typ_semester_outcome_id in (select id from typ_semester_outcome where semester_id ={$semester->id} and typ_program_id in (select id from typ_program where program_id ={$program_id} )and outcome_id = ?))", array(Input::get('id')));
  233. //foreach ($typ_info['courses'] as $course) {
  234. // $typ_info['courses_objective'][$course->id] = DB::select("select * from objectives where id in (select objective_id from typ_semester_objectives where typ_semester_course_id in (select id from typ_semester_courses where typ_semester_outcome_id in (select id from typ_semester_outcome where semester_id = {$semester->id} and typ_program_id in (select id from typ_program where program_id ={$program_id}))and course_id ={$course->id}))");
  235. // foreach ($typ_info['courses_objective'][$course->id] as $objective) {
  236. // $typ_info['criteria'][$objective->id] = DB::select("select * from criteria where id in (select criterion_id from criterion_objective_outcome where outcome_id = ? and objective_id = {$objective->id})", array(Input::get('id')));
  237. // }
  238. //}
  239. //$typ_info['courses'] = DB::select("select * from courses where id in (select course_id from typ_semester_courses where typ_semester_objective_id in (select id from typ_semester_objectives where typ_semester_outcome_id in (select id from type_semester_outcome where semester_id ={$semester->id} and typ_program_id in (select id from typ_program where program_id ={$program_id} )and outcome_id = ?)))", array(Input::get('id')));
  240. //$typ_info['unique_objective'] = DB::select("select * from objectives where id in (select distinct objective_id from typ_semester_objectives where typ_semester_outcome_id in (select id from typ_semester_outcome where semester_id = {$semester->id} and outcome_id =? and typ_program_id in (select id from typ_program where program_id ={$program_id})))", array(Input::get('id')));
  241. //foreach ($typ_info['unique_objective'] as $objective) {
  242. // $typ_info['courses_objective'][$objective->id] = DB::select("select * from courses where id in (SELECT course_id from typ_semester_courses where typ_semester_outcome_id in (select id from typ_semester_outcome where semester_id={$semester->id} and outcome_id =? and typ_program_id in (select id from typ_program where program_id = {$program_id})) and id in (select typ_semester_course_id from typ_semester_objectives where objective_id = {$objective->id}))", array(Input::get('id')));
  243. // $typ_info['criteria'][$objective->id] = DB::select("select * from criteria where id in (select criterion_id from criterion_objective_outcome where outcome_id = ? and objective_id = {$objective->id})", array(Input::get('id')));
  244. //}
  245. $annual_plan = DB::select("select annual_plans.id from annual_plans, annual_cycle where annual_plans.annual_cycle_id = annual_cycle.id and (semester_start = {$semester->id} or semester_end ={$semester->id}) and program_id ={$program_id}")[0];
  246. //$typ_info['expected_target'] = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester->id}");
  247. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  248. ->where('program_id', $program_id)
  249. ->where('semester_id', $semester->id)
  250. ->first();
  251. if (!$typ_info['expected_target']) {
  252. DB::beginTransaction();
  253. DB::table('target_outcomes_program')->insert(
  254. array(
  255. 'program_id' => $program_id,
  256. 'semester_id' => $semester->id,
  257. 'expected_target' => 70.00
  258. )
  259. );
  260. DB::commit();
  261. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  262. ->where('program_id', $program_id)
  263. ->where('semester_id', $semester->id)
  264. ->first();
  265. }
  266. $typ_info['objectives'] = DB::select("select * from objectives where id in (select objective_id from typ_semester_objectives where typ_semester_outcome_id in(select id from typ_semester_outcome where outcome_id = ? and semester_id = {$semester->id} and typ_program_id in (select id from typ_program where program_id ={$program_id})))", array(Input::get('id')));
  267. $typ_info['transformative_actions'] = DB::select("select * from transformative_actions where by_professor =0 and is_custom=0");
  268. foreach ($typ_info['objectives'] as $objective) {
  269. $typ_info['courses'][$objective->id] = DB::select("select c.id, c.number, c.name, c.code, typ.id typ_course_id from courses c, typ_semester_courses typ, (select course_id, id from typ_semester_courses where typ_semester_objective_id in (select id from typ_semester_objectives where objective_id ={$objective->id} and typ_semester_outcome_id in (select id from typ_semester_outcome where outcome_id =? and semester_id ={$semester->id} and typ_program_id in(select id from typ_program where program_id ={$program_id})))) rel where typ.course_id =c.id and rel.course_id = c.id and typ.id = rel.id ", array(Input::get('id')));
  270. $typ_info['criteria'][$objective->id] = DB::select("select * from criteria where deleted_at IS NULL and id in (select criterion_id from criterion_objective_outcome where outcome_id = ? and objective_id = {$objective->id})", array(Input::get('id')));
  271. Log::info($typ_info['criteria'][$objective->id]);
  272. $typ_info['typ_objective_id'][$objective->id] = DB::select("select id from typ_semester_objectives where objective_id = {$objective->id} and typ_semester_outcome_id in (select id from typ_semester_outcome where outcome_id =? and semester_id ={$semester->id} and typ_program_id in (select id from typ_program where program_id ={$program_id}))", array(Input::get('id')));
  273. Log::info($typ_info['typ_objective_id'][$objective->id]);
  274. $typ_info['typ_objective_id'][$objective->id] = $typ_info['typ_objective_id'][$objective->id][0];
  275. Log::info($typ_info['typ_objective_id'][$objective->id]->id);
  276. Log::info($annual_plan->id);
  277. // $typ_info['annual_plans_transformative'][$objective->id] = DB::select(
  278. // "select trans_id from annual_plan_transformative
  279. // where annual_plan_id={$annual_plan->id}
  280. // and typ_semester_objective_id ={$typ_info['typ_objective_id'][$objective->id]->id}"
  281. // );
  282. foreach ($typ_info['courses'][$objective->id] as $course) {
  283. $typ_info['selected_criteria'][$objective->id][$course->typ_course_id] = DB::select("select criteria_id, typ_semester_course_id typ_course_id from annual_plan_objective where annual_plan_id ={$annual_plan->id} and typ_semester_course_id ={$course->typ_course_id} ");
  284. $typ_info['annual_plans_transformative'][$objective->id][$course->typ_course_id] = DB::table('annual_plan_transformative')
  285. ->select('trans_id')
  286. ->where('annual_plan_id', $annual_plan->id)
  287. ->where('typ_semester_course_id', $course->typ_course_id)
  288. ->get();
  289. //Log::info($course->typ_course_id);
  290. $typ_info['custom_transformative'][$objective->id][$course->id] = DB::table('transformative_actions')
  291. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  292. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  293. ->where('is_custom', 1)
  294. ->where('by_professor', 0)
  295. ->where('ta_course.course_number', $course->number)
  296. ->where('ta_course.course_code', $course->code)
  297. ->where('transformative_objective.objective_id', $objective->id)
  298. ->get();
  299. }
  300. }
  301. $typ_info['annual_plan'] = $annual_plan;
  302. Log::info($typ_info);
  303. $typ_info['transformative_actions_for_outcome'] = DB::table('transformative_actions')
  304. ->join('transformative_typ_outcome', 'transformative_typ_outcome.trans_id', '=', 'transformative_actions.id')
  305. ->where('transformative_typ_outcome.typ_semester_outcome_id', $typ_semester_outcome_id)
  306. ->get();
  307. $typ_info['categories'] = "<option value='0'>Nothing Selected</option>";
  308. $types = DB::table('transformative_actions')
  309. ->select('type_of_TA', 'is_custom')
  310. ->where('type_of_TA', '<>', '')
  311. ->where(function ($query) use (&$program_id) {
  312. $query->whereNull('program_id')
  313. ->orWhere('program_id', $program_id);
  314. })
  315. ->where('by_professor', 0)
  316. ->groupBy('type_of_TA')
  317. ->get();
  318. $optGroupGeneral = "<optgroup label='General Transformative Actions'>";
  319. $optGroupCustom = "<optgroup label ='Program Custom Actions'>";
  320. foreach ($types as $type) {
  321. if ($type->is_custom) {
  322. $optGroupCustom .= "<option value = '" . $type->type_of_TA . "' data-is-custom = '1'>" . $type->type_of_TA . "</option>";
  323. } else {
  324. $optGroupGeneral .= "<option value = '" . $type->type_of_TA . "' data-is-custom = '0'>" . $type->type_of_TA . "</option>";
  325. }
  326. }
  327. $typ_info['categories'] .= $optGroupGeneral . '</optgroup>';
  328. $typ_info['categories'] .= $optGroupCustom . '</optgroup>';
  329. $typ_info['categories'] .= '<option value ="new"> New Type of Transformative Action</option>';
  330. return json_encode($typ_info);
  331. }
  332. public function deleteTA()
  333. {
  334. $annual_id = Input::get('annual_id') + 0;
  335. $typ_id = Input::get('typ_id') + 0;
  336. $trans_id = Input::get('TA_id') + 0;
  337. DB::delete("delete from `annual_plan_transformative` where annual_plan_id ={$annual_id} and typ_semester_course_id ={$typ_id} and trans_id={$trans_id}");
  338. return;
  339. }
  340. public function postTA()
  341. {
  342. $annual_id = Input::get('annual_id') + 0;
  343. $TA_id = Input::get('TA_id') + 0;
  344. $typ_id = Input::get('typ_course_id') + 0;
  345. $old_ta = Input::get('old_ta') + 0;
  346. $id = Auth::user()['id'];
  347. $date = date('Y-m-d');
  348. $date = strtotime($date);
  349. $query = DB::select("select * from annual_plan_transformative where annual_plan_id ={$annual_id} and trans_id ={$old_ta} and typ_semester_course_id ={$typ_id}");
  350. if (!count($query)) {
  351. DB::insert("insert into `annual_plan_transformative` (`annual_plan_id`,`trans_id`, `typ_semester_course_id`, `proposing_coordinator_id`, `proposed_date`) values({$annual_id},{$TA_id},{$typ_id}, {$id}, now() ) ");
  352. return "Insert Successful";
  353. } else {
  354. if ($TA_id == 0) {
  355. DB::delete("delete from annual_plan_transformative where trans_id={$TA_id} and annual_plan_id ={$annual_id} and typ_semester_course_id ={$typ_id}");
  356. return "deleted";
  357. } else {
  358. DB::update("update annual_plan_transformative set trans_id = {$TA_id}, proposing_coordinator_id = {$id}, proposed_date = now() where trans_id={$old_ta} and annual_plan_id ={$annual_id} and typ_semester_course_id ={$typ_id}");
  359. return "updated";
  360. }
  361. }
  362. }
  363. public function CreateOrEdit($program_id)
  364. {
  365. $semester_id = Input::get('semester_id');
  366. $expected_target = Input::get('expected_target');
  367. $exist = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester_id}");
  368. if ($exist) {
  369. //update
  370. DB::update("update target_outcomes_program set expected_target = {$expected_target}, updated_at = now() where program_id = {$program_id} and semester_id = {$semester_id}");
  371. } else {
  372. //create a new one
  373. DB::insert("insert into target_outcomes_program (program_id, semester_id, expected_target, created_at, updated_at) values({$program_id}, {$semester_id}, '{$expected_target}', '{now()}', '{now()}')");
  374. }
  375. return;
  376. }
  377. public function transformativeReport()
  378. {
  379. $json_to_send = array();
  380. $annual_id = Input::get('an_id');
  381. $transformative_action_info = DB::select("select * from transformative_actions where id in (select distinct trans_id from annual_plan_transformative where annual_plan_id = {$annual_id}) ");
  382. foreach ($transformative_action_info as $trans) {
  383. $json_to_send['Trans_act'][$trans->id] = $trans;
  384. $json_to_send['outcomes'][$trans->id] = DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where id in(select typ_semester_outcome_id from typ_semester_objectives where id in (select typ_semester_objective_id from annual_plan_transformative where trans_id ={$trans->id} and annual_plan_id = {$annual_id})))");
  385. foreach ($json_to_send['outcomes'][$trans->id] as $outcome) {
  386. $json_to_send['typ_objective'][$outcome->id][$trans->id] = DB::select("select * from typ_semester_objectives where typ_semester_outcome_id in (select id from typ_semester_outcome where outcome_id ={$outcome->id}) and id in (select typ_semester_objective_id from annual_plan_transformative where annual_plan_id ={$annual_id} and trans_id = {$trans->id})");
  387. foreach ($json_to_send['typ_objective'][$outcome->id][$trans->id] as $typ) {
  388. $json_to_send['objective'][$outcome->id][$typ->id][$trans->id] = DB::select("select * from objectives where id = {$typ->objective_id}")[0];
  389. $json_to_send['coordinator'][$outcome->id][$typ->id][$trans->id] = DB::select("select * from users where id in (select proposing_coordinator_id from annual_plan_transformative where typ_semester_objective_id = {$typ->id} and annual_plan_id = {$annual_id} and trans_id = {$trans->id})")[0];
  390. $json_to_send['proposed_date'][$outcome->id][$typ->id][$trans->id] = DB::select("select proposed_date from annual_plan_transformative where typ_semester_objective_id = {$typ->id} and annual_plan_id = {$annual_id} and trans_id = {$trans->id} ")[0];
  391. $json_to_send['all_info_report'][$outcome->id][$typ->id][$trans->id] = DB::select("select art.accomplished, art.cycle_of_life, semesters.name, art.semester_continue, art.annual_trans_id, art.supervised_coordinator_id from annual_report_transformative art, (select id from annual_plan_transformative where typ_semester_objective_id = {$typ->id} and annual_plan_id = {$annual_id} and trans_id = {$trans->id} ) apt, semesters where art.annual_trans_id = apt.id and semesters.id = art.semester_used")[0];
  392. }
  393. }
  394. if ($trans->user_id) {
  395. $json_to_send['suggested'][$trans->id] = DB::select("select * from users where id = {$trans->user_id}");
  396. }
  397. }
  398. return json_encode($json_to_send);
  399. }
  400. public function deleteCriteria()
  401. {
  402. $criteria = Input::get('criteria') + 0;
  403. $typ_course_id = Input::get('typ_course_id') + 0;
  404. $annual_plan = Input::get('annual_plan') + 0;
  405. $old_criteria = Input::get('old_criteria') + 0;
  406. $message = '';
  407. DB::delete("delete from annual_plan_objective where annual_plan_id ={$annual_plan} and typ_semester_course_id ={$typ_course_id} and criteria_id={$criteria}");
  408. return;
  409. }
  410. public function fetchAllTables()
  411. {
  412. $annual_plan = array();
  413. $an_id = Input::get('id');
  414. $program_id = Input::get('program_id');
  415. $an_semesters = DB::select("select semester_start, semester_end, program_id from annual_plans, annual_cycle where annual_plans.annual_cycle_id = annual_cycle.id and annual_plans.id ={$an_id} and program_id ={$program_id}")[0];
  416. $annual_plan['first']['outcomes'] = DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id = {$an_semesters->semester_start} and typ_program_id in(select id from typ_program where program_id ={$an_semesters->program_id}))");
  417. $annual_plan['second']['outcomes'] = DB::select("select * from outcomes where id in (select outcome_id from typ_semester_outcome where semester_id = {$an_semesters->semester_end} and typ_program_id in(select id from typ_program where program_id ={$an_semesters->program_id}))");
  418. $annual_plan['first']['semester'] = array('id' => $an_semesters->semester_start);
  419. $annual_plan['second']['semester'] = array('id' => $an_semesters->semester_end);
  420. foreach ($annual_plan['first']['outcomes'] as $outcomes) {
  421. $annual_plan['first']['objectives'][$outcomes->id] = DB::select("select * from objectives where id in (select objective_id from typ_semester_objectives where typ_semester_outcome_id in(select id from typ_semester_outcome where outcome_id = {$outcomes->id} and semester_id = {$an_semesters->semester_start} and typ_program_id in (select id from typ_program where program_id ={$an_semesters->program_id})))");
  422. Log::info($outcomes->id);
  423. Log::info($annual_plan['first']['objectives'][$outcomes->id]);
  424. foreach ($annual_plan['first']['objectives'][$outcomes->id] as $objective) {
  425. $annual_plan['first']['typ_objective_id'][$objective->id] = DB::select("select id from typ_semester_objectives where objective_id = {$objective->id} and typ_semester_outcome_id in (select id from typ_semester_outcome where outcome_id ={$outcomes->id} and semester_id ={$an_semesters->semester_start} and typ_program_id in(select id from typ_program where program_id ={$an_semesters->program_id})) ")[0];
  426. $annual_plan['first']['courses'][$objective->id] = DB::select("select typ.id typ_course_id, typ.course_id, c.code, c.number, c.name from (select course_id, id from typ_semester_courses where typ_semester_objective_id = {$annual_plan['first']['typ_objective_id'][$objective->id]->id}) typ, courses c where c.id = typ.course_id");
  427. foreach ($annual_plan['first']['courses'][$objective->id] as $course) {
  428. $annual_plan['first']['criteria'][$objective->id][$course->typ_course_id] = DB::select("select * from criteria where id in(select criteria_id from annual_plan_objective where annual_plan_id = {$an_id} and typ_semester_course_id = {$course->typ_course_id} )");
  429. $annual_plan['first']['trans_actions'][$objective->id][$course->typ_course_id] = DB::select("select * from transformative_actions where id in (select trans_id from annual_plan_transformative where typ_semester_course_id = {$course->typ_course_id})");
  430. }
  431. Log::info($objective->id);
  432. /*$annual_plan['first']['trans_actions'][$objective->id] = DB::select("select * from transformative_actions where id in (select trans_id from annual_plan_transformative where typ_semester_objective_id ={$annual_plan['first']['typ_objective_id'][$objective->id]->id})");
  433. foreach ($annual_plan['first']['trans_actions'][$objective->id] as $trans) {
  434. Log::info($annual_plan['first']['typ_objective_id'][$objective->id]->id);
  435. Log::info($trans->id);
  436. Log::info($an_id);
  437. $annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id] = DB::select("select * from annual_report_transformative where annual_trans_id in (select id from annual_plan_transformative where trans_id = {$trans->id} and typ_semester_objective_id ={$annual_plan['first']['typ_objective_id'][$objective->id]->id} and annual_plan_id = {$an_id} )");
  438. if (count($annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  439. Log::info("entró");
  440. $annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id] = $annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id][0];
  441. }
  442. }*/
  443. }
  444. }
  445. foreach ($annual_plan['second']['outcomes'] as $outcomes) {
  446. $annual_plan['second']['objectives'][$outcomes->id] = DB::select("select * from objectives where id in (select objective_id from typ_semester_objectives where typ_semester_outcome_id in(select id from typ_semester_outcome where outcome_id = {$outcomes->id} and semester_id = {$an_semesters->semester_end} and typ_program_id in (select id from typ_program where program_id ={$an_semesters->program_id})))");
  447. foreach ($annual_plan['second']['objectives'][$outcomes->id] as $objective) {
  448. $annual_plan['second']['typ_objective_id'][$objective->id] = DB::select("select id from typ_semester_objectives where objective_id = {$objective->id} and typ_semester_outcome_id in (select id from typ_semester_outcome where outcome_id ={$outcomes->id} and semester_id ={$an_semesters->semester_end} and typ_program_id in(select id from typ_program where program_id ={$an_semesters->program_id})) ")[0];
  449. $annual_plan['second']['courses'][$objective->id] = DB::select("select typ.id typ_course_id, typ.course_id, c.code, c.number, c.name from (select course_id, id from typ_semester_courses where typ_semester_objective_id = {$annual_plan['second']['typ_objective_id'][$objective->id]->id}) typ, courses c where c.id = typ.course_id");
  450. foreach ($annual_plan['second']['courses'][$objective->id] as $course) {
  451. $annual_plan['second']['criteria'][$objective->id][$course->course_id] = DB::select("select * from criteria where id in(select criteria_id from annual_plan_objective where annual_plan_id = {$an_id} and typ_semester_course_id ={$course->typ_course_id})");
  452. $annual_plan['second']['trans_actions'][$objective->id][$course->typ_course_id] = DB::select("select * from transformative_actions where id in (select trans_id from annual_plan_transformative where typ_semester_course_id = {$course->typ_course_id})");
  453. }
  454. /*
  455. $annual_plan['second']['trans_actions'][$objective->id] = DB::select("select * from transformative_actions where id in (select trans_id from annual_plan_transformative where typ_semester_objective_id ={$annual_plan['second']['typ_objective_id'][$objective->id]->id})");
  456. Log::info($annual_plan['second']['typ_objective_id'][$objective->id]->id);
  457. foreach ($annual_plan['second']['trans_actions'][$objective->id] as $trans) {
  458. $annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id] = DB::select("select * from annual_report_transformative where annual_trans_id in (select id from annual_plan_transformative where trans_id = {$trans->id} and typ_semester_objective_id ={$annual_plan['second']['typ_objective_id'][$objective->id]->id} and annual_plan_id = {$an_id} )");
  459. Log::info("lol");
  460. if (count($annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  461. Log::info("entró");
  462. $annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id] = $annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id][0];
  463. }
  464. }*/
  465. }
  466. }
  467. return json_encode($annual_plan);
  468. }
  469. public function postAnnualPlan()
  470. {
  471. $criteria = Input::get('criteria') + 0;
  472. $typ_course_id = Input::get('typ_course_id') + 0;
  473. $annual_plan = Input::get('annual_plan') + 0;
  474. $old_criteria = Input::get('old_criteria') + 0;
  475. $message = '';
  476. $query = DB::select("select * from annual_plan_objective where annual_plan_id ={$annual_plan} and typ_semester_course_id = {$typ_course_id} and criteria_id ={$old_criteria}");
  477. if (!count($query)) {
  478. $query = DB::select("select * from annual_plan_objective where annual_plan_id ={$annual_plan} and typ_semester_course_id = {$typ_course_id} and criteria_id ={$criteria}");
  479. if (!count($query)) {
  480. DB::insert("insert into `annual_plan_objective` (`annual_plan_id`, `typ_semester_course_id`, `criteria_id`) values ({$annual_plan}, {$typ_course_id}, {$criteria})");
  481. $message = "inserting was a success";
  482. } else {
  483. $message = "Duplicate entry, please choose another criteria.";
  484. }
  485. } else {
  486. $query = DB::select("select * from annual_plan_objective where annual_plan_id ={$annual_plan} and typ_semester_course_id = {$typ_course_id} and criteria_id ={$criteria}");
  487. if (!count($query)) {
  488. DB::update("update `annual_plan_objective` set criteria_id = {$criteria} where annual_plan_id = {$annual_plan} and typ_semester_course_id ={$typ_course_id} and criteria_id = {$old_criteria} ");
  489. $message = "Updating was a success";
  490. } else {
  491. $message = "Duplicate entry, please choose another criteria.";
  492. }
  493. }
  494. return $message;
  495. }
  496. public function create(Program $program)
  497. {
  498. $title = 'New Annual Plan for ' . $program->name;
  499. $user = Auth::user();
  500. $outcomes = Outcome::orderBy('name')->get();
  501. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  502. ->where('end_date', '>=', date('Y-m-d'))
  503. ->first();
  504. $courses = Course::select('id', 'code', 'number', 'name')
  505. ->where('program_id', $program->id)
  506. ->groupBy('name')
  507. ->orderBy('code', 'ASC')
  508. ->orderBy('number', 'ASC')
  509. ->orderBy('name', 'ASC')
  510. ->get();
  511. // Check if user can create a plan
  512. if (!$this->userHasAccess($program->id)) {
  513. return View::make('global.403');
  514. }
  515. return View::make('local.managers.shared.create_annual_plan', compact('title', 'program', 'current_quinquennium', 'outcomes', 'courses'));
  516. }
  517. function fetchAnnualReport()
  518. {
  519. $program_id = Input::get('program_id');
  520. $annual_plan_id = Input::get('annual_plan_id');
  521. $semester_start = Input::get('semester_start');
  522. $semester_end = Input::get('semester_end');
  523. $academic_year = Input::get('academic_year');
  524. $academic_year = (int) explode(",", $academic_year)[0];
  525. $course_codes = DB::table('annual_plan_objective as apo')
  526. ->join('typ_semester_courses as tyc', 'apo.typ_semester_course_id', '=', 'tyc.id')
  527. ->join('courses', 'tyc.course_id', '=', 'courses.id')
  528. ->where('annual_plan_id', $annual_plan_id)
  529. ->select('courses.code', 'courses.number')
  530. ->distinct()
  531. ->get();
  532. Log::info($course_codes);
  533. $all_courses_info = [];
  534. foreach ($course_codes as $index => $course_code) {
  535. //$all_courses_info['course_code'][] = $course_code->code . '_' . $course_code->number;
  536. $courses = Course::where(function ($query) use (&$semester_end, &$semester_start) {
  537. $query->where('semester_id', $semester_end)
  538. ->orWhere('semester_id', $semester_start);
  539. })
  540. ->where('code', $course_code->code)
  541. ->where('number', $course_code->number)
  542. ->where('program_id', $program_id)
  543. ->get();
  544. Log::info("run number " . $index);
  545. Log::info($courses);
  546. foreach ($courses as $course) {
  547. $all_courses_info[$course_code->code . '_' . $course_code->number][] = $course->getReportObject();
  548. }
  549. }
  550. /*$course_codes = DB::table('typ_semester_courses')
  551. ->join('typ_semester_objectives as tso', 'tso.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  552. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  553. ->join('typ_semester_outcome as typ_out', 'typ_out.id', '=', 'tso.typ_semester_outcome_id')
  554. ->join('typ_program', 'typ_out.typ_program_id', '=', 'typ_program.id')
  555. ->where(function ($query) use (&$semester_start, &$semester_end) {
  556. $query->where('typ_out.semester_id', $semester_start)
  557. ->orWhere('typ_out.semester_id', $semester_end);
  558. })
  559. ->where('typ_program.program_id', $program_id)
  560. ->select('courses.code', 'courses.number', 'typ_semester_courses.id as typ_sem_cou_id')
  561. ->distinct()
  562. ->get();*/
  563. /*foreach ($course_codes as $course_code) {
  564. $course_code->sections = DB::table('courses')
  565. ->join('activities', 'activities.course_id', '=', 'courses.id')
  566. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  567. ->join('annual_plan_objective', 'annual_plan_objective.criteria_id', '=', 'activity_criterion.criterion_id')
  568. ->join('typ_semester_courses', 'typ_semester_courses.id', '=', 'annual_plan_objective.typ_semester_course_id')
  569. ->where('courses.code', $course_code->code)
  570. ->where('courses.number', $course_code->number)
  571. ->where('annual_plan_id', $annual_plan_id)
  572. ->where('annual_plan_objective.typ_semester_course_id', $course_code->typ_sem_cou_id)
  573. ->toSql();
  574. Log::info($course_code->sections);
  575. }*/
  576. return $all_courses_info;
  577. }
  578. public function selectProgramPlan()
  579. {
  580. $title = "Program Annual Reports";
  581. $programs = Auth::user()->school->programs;
  582. return View::make('local.managers.shared.annual_select', compact('title', 'programs'));
  583. }
  584. //Fetch report in annual_plan_report
  585. public function fetchReportWithOutcome()
  586. {
  587. $program_id = Input::get('program_id');
  588. $semester_id = Input::get('semester_id');
  589. $annual_plan_id = Input::get('annual_plan_id');
  590. $outcome_id = Input::get('outcome_id');
  591. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  592. $outcome = Outcome::where('id', $outcome_id)->first();
  593. $outcome->objectives = $outcome->fetchObjectivesReport($semester_id, $program_id);
  594. $outcome->outcome_program_goal = DB::table('target_outcomes_program')
  595. ->where('program_id', $program_id)
  596. ->where('semester_id', $semester_id)
  597. ->first();
  598. $outcome->transforming_actions = DB::table('transformative_typ_outcome')
  599. ->join('transformative_actions', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  600. ->leftJoin('transformative_action_status', 'transformative_actions.id', '=', 'transformative_action_status.trans_id')
  601. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  602. ->select('transformative_actions.*', 'transformative_action_status.*', 'transformative_actions.id as trans_id')
  603. ->get();
  604. $outcome->semester_info = DB::table('semesters')
  605. ->where('id', $semester_id)
  606. ->first();
  607. $outcome->comments = DB::table('typ_outcome_report_comments')
  608. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  609. ->get();
  610. $outcome->transformative_actions_categories_html = TransformativeAction::getCategoriesHtml($program_id);
  611. foreach ($outcome->objectives as $index => $objective) {
  612. $objective->courses = Objective::getPlanReport($objective);
  613. }
  614. return $outcome;
  615. }
  616. public function fetchObjectiveInfo()
  617. {
  618. $typ_objective_id = Input::get('typ_objective_id');
  619. $courses = DB::table('typ_semester_courses')
  620. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  621. ->select('courses.code', 'courses.number', 'courses.name', 'typ_semester_courses.id as typ_semester_course_id')
  622. ->where('typ_semester_objective_id', $typ_objective_id)
  623. ->distinct()
  624. ->get();
  625. foreach ($courses as $course) {
  626. /*$course->criteria_scale = DB::table('annual_plan_objective')
  627. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  628. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  629. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  630. ->select('criterion_scale.*', 'scales.*')
  631. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  632. ->orderBy('position', 'ASC')
  633. ->get();*/
  634. $course->criteria = DB::table('annual_plan_objective')
  635. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  636. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  637. ->select('criteria.*')
  638. ->get();
  639. foreach ($course->criteria as $criterion) {
  640. $criterion->scales = DB::table('criteria')
  641. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  642. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  643. ->select('criterion_scale.*', 'scales.*')
  644. ->where('criteria.id', $criterion->id)
  645. ->orderBy('position', 'ASC')
  646. ->get();
  647. }
  648. }
  649. return $courses;
  650. }
  651. /* public function submitAnnualPlan()
  652. {
  653. $annual_plan_id = Input::get('annual_plan_id');
  654. DB::table('annual_plans')->where('id', $annual_plan_id)->update(array(
  655. 'is_submitted' => 1,
  656. 'submitted_on' => date('Y-m-d H:i:s')
  657. ));
  658. return;
  659. }*/
  660. public function futureTransformative()
  661. {
  662. $at_text = Input::get('at_text');
  663. $description = Input::get('description');
  664. $future_typ_course_id = Input::get('future_typ_course_id');
  665. $future_semesters = Input::get('future_semesters');
  666. $type_of_ta = Input::get('type_of_TA');
  667. $is_custom = Input::get('is_custom');
  668. $program_id = Input::get('program_id');
  669. //$annual_plan_id = Input::get('annual_plan_id');
  670. $objective_id = Input::get('objective_id');
  671. $course_code = Input::get('course_code');
  672. $course_number = Input::get('course_number');
  673. $edit_ta_id = Input::get('edit_ta_id');
  674. if ($edit_ta_id) {
  675. DB::table('transformative_actions')
  676. ->where('id', $edit_ta_id)->update(array(
  677. 'is_custom' => $is_custom,
  678. 'at_text' => $at_text,
  679. 'description' => $description,
  680. 'type_of_TA' => $type_of_ta,
  681. 'user_id' => Auth::user()->id,
  682. 'program_id' => $program_id,
  683. //'by_professor' => 0,
  684. //'created_at' => date('Y-m-d H:i:s'),
  685. 'updated_at' => date('Y-m-d H:i:s')
  686. ));
  687. DB::table('annual_plan_transformative')
  688. ->where('trans_id', $edit_ta_id)
  689. ->delete();
  690. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  691. $annual_plan = DB::table('annual_cycle')
  692. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  693. ->where('program_id', $program_id)
  694. ->where(function ($query) use (&$future_semesters, &$index) {
  695. $query->where('semester_start', $future_semesters[$index])
  696. ->orWhere('semester_end', $future_semesters[$index]);
  697. })->first();
  698. DB::table('annual_plan_transformative')
  699. ->insert(array(
  700. 'annual_plan_id' => $annual_plan->id,
  701. 'trans_id' => $edit_ta_id,
  702. 'typ_semester_course_id' => $typ_future_course_id,
  703. 'proposing_coordinator_id' => Auth::user()->id,
  704. 'proposed_date' => date('Y-m-d H:i:s')
  705. ));
  706. }
  707. $transformative_action = TransformativeAction::getTypCoursesWithSemesters($edit_ta_id);
  708. $transformative_action[0]->updated = 1;
  709. return $transformative_action;
  710. } else {
  711. $newTransId = DB::table('transformative_actions')
  712. ->insertGetId(array(
  713. 'is_custom' => $is_custom,
  714. 'at_text' => $at_text,
  715. 'description' => $description,
  716. 'type_of_TA' => $type_of_ta,
  717. 'user_id' => Auth::user()->id,
  718. 'program_id' => $program_id,
  719. 'by_professor' => 0,
  720. 'created_at' => date('Y-m-d H:i:s'),
  721. 'updated_at' => date('Y-m-d H:i:s')
  722. ));
  723. DB::table('ta_course')->insert(array(
  724. 'ta_id' => $newTransId,
  725. 'course_number' => $course_number,
  726. 'course_code' => $course_code
  727. ));
  728. DB::table('transformative_objective')->insert(array(
  729. 'ta_id' => $newTransId,
  730. 'objective_id' => $objective_id
  731. ));
  732. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  733. $annual_plan = DB::table('annual_cycle')
  734. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  735. ->where('program_id', $program_id)
  736. ->where(function ($query) use (&$future_semesters, &$index) {
  737. $query->where('semester_start', $future_semesters[$index])
  738. ->orWhere('semester_end', $future_semesters[$index]);
  739. })->first();
  740. DB::table('annual_plan_transformative')
  741. ->insert(array(
  742. 'annual_plan_id' => $annual_plan->id,
  743. 'trans_id' => $newTransId,
  744. 'typ_semester_course_id' => $typ_future_course_id,
  745. 'proposing_coordinator_id' => Auth::user()->id,
  746. 'proposed_date' => date('Y-m-d H:i:s')
  747. ));
  748. }
  749. return TransformativeAction::getTypCoursesWithSemesters($newTransId);
  750. }
  751. }
  752. public function fetchTheAnnualPlan()
  753. {
  754. $outcome_id = Input::get('id');
  755. $semester_id = Input::get('semester');
  756. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  757. $program_id = Input::get('program_id');
  758. $outcome = Outcome::find($outcome_id);
  759. //El nombre es annual_plan_objective, fue cambiado como mil veces por Arlene y su combo
  760. // Así que está mal escrito. Sorry future programmer
  761. $array_to_send = [];
  762. $array_to_send['typ_objectives'] = DB::table('typ_semester_objectives')
  763. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  764. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  765. ->select('objectives.*', 'typ_semester_outcome_id', 'typ_semester_objectives.id as typ_semester_objective_id')
  766. ->get();
  767. $array_to_send['typ_courses'] = DB::table('typ_semester_objectives')
  768. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  769. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  770. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  771. ->select('courses.*', 'typ_semester_objective_id', 'typ_semester_courses.id as typ_semester_course_id')
  772. ->get();
  773. $array_to_send['courses_criteria'] = DB::table('typ_semester_objectives')
  774. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  775. ->join('annual_plan_objective', 'annual_plan_objective.typ_semester_course_id', '=', 'typ_semester_courses.id')
  776. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  777. ->select('typ_semester_course_id', 'annual_plan_objective.*', 'criteria.*')
  778. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  779. ->groupBy('typ_semester_course_id')
  780. ->get();
  781. $array_to_send['courses_transformative_actions'] = DB::table('typ_semester_objectives')
  782. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  783. ->join('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  784. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  785. ->select('typ_semester_course_id', 'annual_plan_transformative.*', 'transformative_actions.*')
  786. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  787. ->groupBy('typ_semester_course_id')
  788. ->get();
  789. $array_to_send['transformative_outcome'] = DB::table('transformative_actions')
  790. ->join('transformative_typ_outcome', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  791. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  792. ->get();
  793. $array_to_send['expected_target'] = DB::table('target_outcomes_program')
  794. ->where('program_id', $program_id)
  795. ->where('semester_id', $semester_id)
  796. ->first();
  797. return $array_to_send;
  798. }
  799. public function addCommentsToOutcome()
  800. {
  801. $edit_id = Input::get('edit_id');
  802. $typ_semester_outcome_id = Input::get('typ_outcome_semester_id');
  803. $comments = Input::get('comments');
  804. Log::info(Input::all());
  805. if ($edit_id) {
  806. DB::table('typ_outcome_report_comments')
  807. ->where('id', $edit_id)->update(array(
  808. 'user_id' => Auth::user()->id,
  809. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  810. 'comments' => $comments
  811. ));
  812. } else {
  813. $edit_id = DB::table('typ_outcome_report_comments')->insertGetId(array(
  814. 'user_id' => Auth::user()->id,
  815. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  816. 'comments' => $comments
  817. ));
  818. }
  819. return $edit_id;
  820. }
  821. public function deleteCommentsFromOutcome()
  822. {
  823. $comment_id = Input::get('id');
  824. DB::table('typ_outcome_report_comments')->where('id', $comment_id)->delete();
  825. return;
  826. }
  827. //Print annual report
  828. public function printAnnualReport($annual_id = null)
  829. {
  830. //$download = 0;
  831. $annualPlan = AnnualPlan::find($annual_id);
  832. //$pdf = new PDF();
  833. /*$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  834. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan', 'download'))
  835. ->setOrientation("landscape")
  836. ->setPaper('legal', 'landscape');
  837. $pdf->save(app_path() . '/storage/annual_pdfs/' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  838. return $pdf->download(date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  839. */ //pdf = $pdf->setOrientation("landscape");
  840. return View::make('local.managers.shared.print_annual_report', compact('annualPlan'));
  841. }
  842. public function postAnnualReport($annual_id)
  843. {
  844. $annualPlan = AnnualPlan::findOrFail($annual_id);
  845. $user_id = Auth::user()->id;
  846. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  847. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  848. ->setOrientation("landscape")
  849. ->setPaper('legal', 'landscape');
  850. $path = app_path() . '/storage/annual_pdfs/' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '-by-' . $user_id . '.pdf';
  851. $pdf->save($path);
  852. $name = date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf';
  853. $pdf->download($name);
  854. //is a path already there
  855. $it_exists = DB::table("paths_for_annual_plans")
  856. ->where('path_to_pdf', $path)
  857. ->first();
  858. if (isset($it_exists)) {
  859. return '200';
  860. }
  861. //$user_id = Auth::user()->id;
  862. DB::table("paths_for_annual_plans")
  863. ->where('annual_plan_id', $annual_id)
  864. ->where('user_id', $user_id)
  865. ->where('report', 1)
  866. ->update(array(
  867. 'last' => 0
  868. ));
  869. DB::table('paths_for_annual_plans')->insert(array(
  870. "path_to_pdf" => $path,
  871. 'annual_plan_id' => $annual_id,
  872. 'last' => 1,
  873. 'report' => 1,
  874. 'user_id' => $user_id,
  875. 'date_posted' => date('Y-m-d')
  876. ));
  877. return '200';
  878. }
  879. public function annualPlansShow($annual_report_or_plan, $program_id)
  880. {
  881. $role = Auth::user()->role;
  882. switch ($role) {
  883. case 1:
  884. case 2:
  885. case 3:
  886. $last = [1, 0];
  887. break;
  888. case 4:
  889. $last = [1];
  890. break;
  891. default:
  892. App::abort('404');
  893. }
  894. if ($annual_report_or_plan == "report") {
  895. $report = 1;
  896. } else if ($annual_report_or_plan == "plan") {
  897. $report = 0;
  898. } else {
  899. App::abort('404');
  900. }
  901. $title = "Annual Plans for " . Program::findOrFail($program_id)->name;
  902. $paths_with_users = DB::table('paths_for_annual_plans')
  903. ->join('annual_plans', 'annual_plans.id', '=', 'paths_for_annual_plans.annual_plan_id')
  904. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  905. ->join('users', 'users.id', '=', 'paths_for_annual_plans.user_id')
  906. ->where('report', $report)
  907. ->whereIn('last', $last)
  908. ->where('annual_plans.program_id', $program_id)
  909. ->orderBy('date_posted', 'desc')
  910. ->select('paths_for_annual_plans.path_to_pdf', 'users.*', 'date_posted', 'annual_cycle.*', 'paths_for_annual_plans.last', 'paths_for_annual_plans.id as path_id')
  911. ->get();
  912. return View::make('local.managers.shared.new_view_annual_plans', compact('paths_with_users', 'title', 'report', 'last', 'annual_report_or_plan', 'program_id'));
  913. }
  914. public function downloadPDF($download, $path_id)
  915. {
  916. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  917. $queryToPath = DB::table('paths_for_annual_plans')
  918. ->where('id', $path_id)
  919. ->first();
  920. Log::info("ERES TU? creo que no");
  921. $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
  922. Log::info("ERES TU?");
  923. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  924. ->setOrientation("landscape")
  925. ->setPaper('legal', 'landscape');
  926. if ($download == "download")
  927. return $pdf->download(basename($queryToPath->path_to_pdf));
  928. else
  929. return $pdf->stream(basename($queryToPath->path_to_pdf));
  930. }
  931. public function checkIfPlanReady()
  932. {
  933. $annual_plan = AnnualPlan::findOrFail(Input::get("annual_id"));
  934. /*
  935. error = [
  936. [
  937. outcome, objective, course
  938. ]
  939. ]
  940. */
  941. $error_array = [];
  942. foreach ($annual_plan->courses as $index => $course) {
  943. Log::info('paired Criteria');
  944. Log::info($course->paired_criteria);
  945. if (count($course->paired_criteria) <= 0) {
  946. $outcome = $course->paired_objective->paired_outcome;
  947. $objective = $course->paired_objective;
  948. $array_to_be_appended = [
  949. "outcome_name" => $outcome->name,
  950. "objective_text" => $objective->text,
  951. "course_code" => $course->code . '-' . $course->number,
  952. 'typ_semester_course_id' => $course->typ_semester_course_id,
  953. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  954. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id
  955. ];
  956. $error_array[] = $array_to_be_appended;
  957. }
  958. }
  959. return $error_array;
  960. }
  961. public function checkIfReady()
  962. {
  963. $annual_plan = AnnualPlan::find(Input::get('annual_id'));
  964. /*Error message schema
  965. courses_where_missing_data = [
  966. course_1=>[
  967. info, info
  968. objective => {
  969. typ_semester_objective_id,
  970. objective_text
  971. }
  972. outcome => {
  973. typ_semester_outcome_id,
  974. outcome_name
  975. }
  976. ]
  977. ]
  978. */
  979. $courses_where_missing_data = [
  980. 'courses' => [],
  981. 'outcomes' => []
  982. ];
  983. Log::info($annual_plan->courses_with_transformative_actions);
  984. foreach ($annual_plan->courses_with_transformative_actions as $course) {
  985. foreach ($course->proposed_transformative_actions as $ta) {
  986. if (!isset($ta->status)) {
  987. $objective = $course->paired_objective;
  988. $objective_info = [
  989. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  990. 'text' => $objective->text
  991. ];
  992. $outcome = $objective->paired_outcome;
  993. $outcome_info = [
  994. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  995. 'name' => $outcome->name
  996. ];
  997. $array_to_be_appended = [
  998. 'course_name' => $course->code . '-' . $course->number,
  999. 'objective' => $objective_info,
  1000. 'outcome' => $outcome_info,
  1001. 'transformative_action_title' => $ta->at_text,
  1002. 'transformative_action_description' => $ta->description,
  1003. 'typ_semester_course_id' => $course->typ_semester_course_id
  1004. ];
  1005. $courses_where_missing_data['courses'][] = $array_to_be_appended;
  1006. }
  1007. }
  1008. }
  1009. foreach ($annual_plan->outcomes as $outcome) {
  1010. foreach ($outcome->program_transformative_actions as $ta) {
  1011. if (!isset($ta->status)) {
  1012. $array_to_be_appended = [
  1013. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  1014. 'outcome_name' => $outcome->name,
  1015. 'transformative_action_title' => $ta->at_text,
  1016. 'transformative_action_description' => $ta->description
  1017. ];
  1018. $courses_where_missing_data['outcomes'][] = $array_to_be_appended;
  1019. }
  1020. }
  1021. }
  1022. return $courses_where_missing_data;
  1023. }
  1024. function printAnnualPlan($annual_id)
  1025. {
  1026. $alphabet = range("A", "Z");
  1027. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1028. $small_alphabet = range('a', 'z');
  1029. return View::make('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet'));
  1030. }
  1031. function submitAnnualPlan($annual_id)
  1032. {
  1033. $alphabet = range("A", "Z");
  1034. $small_alphabet = range('a', 'z');
  1035. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1036. $user_id = Auth::user()->id;
  1037. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  1038. $pdf = $pdf->loadView('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet'))
  1039. ->setOrientation("landscape")
  1040. ->setPaper('legal', 'landscape');
  1041. $path = app_path() . '/storage/annual_pdfs/plan-on-' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '-by-' . $user_id . '.pdf';
  1042. $pdf->save($path);
  1043. $name = "plan-on-" . date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf';
  1044. $pdf->download($name);
  1045. //is a path already there
  1046. $it_exists = DB::table("paths_for_annual_plans")
  1047. ->where('path_to_pdf', $path)
  1048. ->first();
  1049. if (isset($it_exists)) {
  1050. return '200';
  1051. }
  1052. DB::table("paths_for_annual_plans")
  1053. ->where('annual_plan_id', $annual_id)
  1054. ->where('report', 0)
  1055. ->where('user_id', $user_id)
  1056. ->update(array(
  1057. 'last' => 0
  1058. ));
  1059. DB::table('paths_for_annual_plans')->insert(array(
  1060. "path_to_pdf" => $path,
  1061. 'annual_plan_id' => $annual_id,
  1062. 'last' => 1,
  1063. 'report' => 0,
  1064. 'user_id' => $user_id,
  1065. 'date_posted' => date('Y-m-d')
  1066. ));
  1067. return '200';
  1068. }
  1069. }