暫無描述

AnnualPlansController.php 57KB

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