Sin descripción

AnnualPlansController.php 61KB

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