Nav apraksta

AnnualPlansController.php 63KB

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