Nav apraksta

AnnualPlansController.php 61KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  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 where outcome_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)->first();
  596. $outcome->objectives = $outcome->fetchObjectivesReport($semester_id, $program_id);
  597. $outcome->outcome_program_goal = DB::table('target_outcomes_program')
  598. ->where('program_id', $program_id)
  599. ->where('semester_id', $semester_id)
  600. ->first();
  601. $outcome->transforming_actions = DB::table('transformative_typ_outcome')
  602. ->join('transformative_actions', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  603. ->leftJoin('transformative_action_status', 'transformative_actions.id', '=', 'transformative_action_status.trans_id')
  604. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  605. ->select('transformative_actions.*', 'transformative_action_status.*', 'transformative_actions.id as trans_id')
  606. ->get();
  607. $outcome->semester_info = DB::table('semesters')
  608. ->where('id', $semester_id)
  609. ->first();
  610. $outcome->comments = DB::table('typ_outcome_report_comments')
  611. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  612. ->get();
  613. $outcome->transformative_actions_categories_html = TransformativeAction::getCategoriesHtml($program_id);
  614. foreach ($outcome->objectives as $index => $objective) {
  615. $objective->courses = Objective::getPlanReport($objective);
  616. }
  617. return $outcome;
  618. }
  619. public function fetchObjectiveInfo()
  620. {
  621. $typ_objective_id = Input::get('typ_objective_id');
  622. $courses = DB::table('typ_semester_courses')
  623. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  624. ->select('courses.code', 'courses.number', 'courses.name', 'typ_semester_courses.id as typ_semester_course_id')
  625. ->where('typ_semester_objective_id', $typ_objective_id)
  626. ->distinct()
  627. ->get();
  628. foreach ($courses as $course) {
  629. /*$course->criteria_scale = DB::table('annual_plan_objective')
  630. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  631. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  632. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  633. ->select('criterion_scale.*', 'scales.*')
  634. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  635. ->orderBy('position', 'ASC')
  636. ->get();*/
  637. $course->criteria = DB::table('annual_plan_objective')
  638. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  639. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  640. ->select('criteria.*')
  641. ->get();
  642. foreach ($course->criteria as $criterion) {
  643. $criterion->scales = DB::table('criteria')
  644. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  645. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  646. ->select('criterion_scale.*', 'scales.*')
  647. ->where('criteria.id', $criterion->id)
  648. ->orderBy('position', 'ASC')
  649. ->get();
  650. }
  651. }
  652. return $courses;
  653. }
  654. /* public function submitAnnualPlan()
  655. {
  656. $annual_plan_id = Input::get('annual_plan_id');
  657. DB::table('annual_plans')->where('id', $annual_plan_id)->update(array(
  658. 'is_submitted' => 1,
  659. 'submitted_on' => date('Y-m-d H:i:s')
  660. ));
  661. return;
  662. }*/
  663. public function futureTransformative()
  664. {
  665. $at_text = Input::get('at_text');
  666. $description = Input::get('description');
  667. $future_typ_course_id = Input::get('future_typ_course_id');
  668. $future_semesters = Input::get('future_semesters');
  669. $type_of_ta = Input::get('type_of_TA');
  670. $is_custom = Input::get('is_custom');
  671. $program_id = Input::get('program_id');
  672. //$annual_plan_id = Input::get('annual_plan_id');
  673. $objective_id = Input::get('objective_id');
  674. $course_code = Input::get('course_code');
  675. $course_number = Input::get('course_number');
  676. $edit_ta_id = Input::get('edit_ta_id');
  677. if ($edit_ta_id) {
  678. DB::table('transformative_actions')
  679. ->where('id', $edit_ta_id)->update(array(
  680. 'is_custom' => $is_custom,
  681. 'at_text' => $at_text,
  682. 'description' => $description,
  683. 'type_of_TA' => $type_of_ta,
  684. 'user_id' => Auth::user()->id,
  685. 'program_id' => $program_id,
  686. //'by_professor' => 0,
  687. //'created_at' => date('Y-m-d H:i:s'),
  688. 'updated_at' => date('Y-m-d H:i:s')
  689. ));
  690. DB::table('annual_plan_transformative')
  691. ->where('trans_id', $edit_ta_id)
  692. ->delete();
  693. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  694. $annual_plan = DB::table('annual_cycle')
  695. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  696. ->where('program_id', $program_id)
  697. ->where(function ($query) use (&$future_semesters, &$index) {
  698. $query->where('semester_start', $future_semesters[$index])
  699. ->orWhere('semester_end', $future_semesters[$index]);
  700. })->first();
  701. DB::table('annual_plan_transformative')
  702. ->insert(array(
  703. 'annual_plan_id' => $annual_plan->id,
  704. 'trans_id' => $edit_ta_id,
  705. 'typ_semester_course_id' => $typ_future_course_id,
  706. 'proposing_coordinator_id' => Auth::user()->id,
  707. 'proposed_date' => date('Y-m-d H:i:s')
  708. ));
  709. }
  710. $transformative_action = TransformativeAction::getTypCoursesWithSemesters($edit_ta_id);
  711. $transformative_action[0]->updated = 1;
  712. return $transformative_action;
  713. } else {
  714. $newTransId = DB::table('transformative_actions')
  715. ->insertGetId(array(
  716. 'is_custom' => $is_custom,
  717. 'at_text' => $at_text,
  718. 'description' => $description,
  719. 'type_of_TA' => $type_of_ta,
  720. 'user_id' => Auth::user()->id,
  721. 'program_id' => $program_id,
  722. 'by_professor' => 0,
  723. 'created_at' => date('Y-m-d H:i:s'),
  724. 'updated_at' => date('Y-m-d H:i:s')
  725. ));
  726. DB::table('ta_course')->insert(array(
  727. 'ta_id' => $newTransId,
  728. 'course_number' => $course_number,
  729. 'course_code' => $course_code
  730. ));
  731. DB::table('transformative_objective')->insert(array(
  732. 'ta_id' => $newTransId,
  733. 'objective_id' => $objective_id
  734. ));
  735. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  736. $annual_plan = DB::table('annual_cycle')
  737. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  738. ->where('program_id', $program_id)
  739. ->where(function ($query) use (&$future_semesters, &$index) {
  740. $query->where('semester_start', $future_semesters[$index])
  741. ->orWhere('semester_end', $future_semesters[$index]);
  742. })->first();
  743. DB::table('annual_plan_transformative')
  744. ->insert(array(
  745. 'annual_plan_id' => $annual_plan->id,
  746. 'trans_id' => $newTransId,
  747. 'typ_semester_course_id' => $typ_future_course_id,
  748. 'proposing_coordinator_id' => Auth::user()->id,
  749. 'proposed_date' => date('Y-m-d H:i:s')
  750. ));
  751. }
  752. return TransformativeAction::getTypCoursesWithSemesters($newTransId);
  753. }
  754. }
  755. public function fetchTheAnnualPlan()
  756. {
  757. $outcome_id = Input::get('id');
  758. $semester_id = Input::get('semester');
  759. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  760. $program_id = Input::get('program_id');
  761. $outcome = Outcome::find($outcome_id);
  762. //El nombre es annual_plan_objective, fue cambiado como mil veces por Arlene y su combo
  763. // Así que está mal escrito. Sorry future programmer
  764. $array_to_send = [];
  765. $array_to_send['typ_objectives'] = DB::table('typ_semester_objectives')
  766. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  767. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  768. ->select('objectives.*', 'typ_semester_outcome_id', 'typ_semester_objectives.id as typ_semester_objective_id')
  769. ->get();
  770. $array_to_send['typ_courses'] = DB::table('typ_semester_objectives')
  771. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  772. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  773. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  774. ->select('courses.*', 'typ_semester_objective_id', 'typ_semester_courses.id as typ_semester_course_id')
  775. ->get();
  776. $array_to_send['courses_criteria'] = DB::table('typ_semester_objectives')
  777. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  778. ->join('annual_plan_objective', 'annual_plan_objective.typ_semester_course_id', '=', 'typ_semester_courses.id')
  779. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  780. ->select('typ_semester_course_id', 'annual_plan_objective.*', 'criteria.*')
  781. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  782. ->groupBy('typ_semester_course_id')
  783. ->get();
  784. $array_to_send['courses_transformative_actions'] = DB::table('typ_semester_objectives')
  785. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  786. ->join('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  787. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  788. ->select('typ_semester_course_id', 'annual_plan_transformative.*', 'transformative_actions.*')
  789. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  790. ->groupBy('typ_semester_course_id')
  791. ->get();
  792. $array_to_send['transformative_outcome'] = DB::table('transformative_actions')
  793. ->join('transformative_typ_outcome', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  794. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  795. ->get();
  796. $array_to_send['expected_target'] = DB::table('target_outcomes_program')
  797. ->where('program_id', $program_id)
  798. ->where('semester_id', $semester_id)
  799. ->first();
  800. return $array_to_send;
  801. }
  802. public function addCommentsToOutcome()
  803. {
  804. $edit_id = Input::get('edit_id');
  805. $typ_semester_outcome_id = Input::get('typ_outcome_semester_id');
  806. $comments = Input::get('comments');
  807. Log::info(Input::all());
  808. if ($edit_id) {
  809. DB::table('typ_outcome_report_comments')
  810. ->where('id', $edit_id)->update(array(
  811. 'user_id' => Auth::user()->id,
  812. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  813. 'comments' => $comments
  814. ));
  815. } else {
  816. $edit_id = DB::table('typ_outcome_report_comments')->insertGetId(array(
  817. 'user_id' => Auth::user()->id,
  818. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  819. 'comments' => $comments
  820. ));
  821. }
  822. return $edit_id;
  823. }
  824. public function deleteCommentsFromOutcome()
  825. {
  826. $comment_id = Input::get('id');
  827. DB::table('typ_outcome_report_comments')->where('id', $comment_id)->delete();
  828. return;
  829. }
  830. //Print annual report
  831. public function printAnnualReport($annual_id = null)
  832. {
  833. //$download = 0;
  834. $annualPlan = AnnualPlan::find($annual_id);
  835. //$pdf = new PDF();
  836. /*$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  837. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan', 'download'))
  838. ->setOrientation("landscape")
  839. ->setPaper('legal', 'landscape');
  840. $pdf->save(app_path() . '/storage/annual_pdfs/' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  841. return $pdf->download(date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  842. */ //pdf = $pdf->setOrientation("landscape");
  843. return View::make('local.managers.shared.print_annual_report', compact('annualPlan'));
  844. }
  845. public function postAnnualReport($annual_id)
  846. {
  847. $annualPlan = AnnualPlan::findOrFail($annual_id);
  848. $user_id = Auth::user()->id;
  849. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  850. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  851. ->setOrientation("landscape")
  852. ->setPaper('legal', 'landscape');
  853. $path = app_path() . '/storage/annual_pdfs/' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '-by-' . $user_id . '.pdf';
  854. $pdf->save($path);
  855. $name = date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf';
  856. $pdf->download($name);
  857. //is a path already there
  858. $it_exists = DB::table("paths_for_annual_plans")
  859. ->where('path_to_pdf', $path)
  860. ->first();
  861. if (isset($it_exists)) {
  862. return '200';
  863. }
  864. //$user_id = Auth::user()->id;
  865. DB::table("paths_for_annual_plans")
  866. ->where('annual_plan_id', $annual_id)
  867. ->where('user_id', $user_id)
  868. ->where('report', 1)
  869. ->update(array(
  870. 'last' => 0
  871. ));
  872. DB::table('paths_for_annual_plans')->insert(array(
  873. "path_to_pdf" => $path,
  874. 'annual_plan_id' => $annual_id,
  875. 'last' => 1,
  876. 'report' => 1,
  877. 'user_id' => $user_id,
  878. 'date_posted' => date('Y-m-d')
  879. ));
  880. return '200';
  881. }
  882. public function annualPlansShow($annual_report_or_plan, $program_id)
  883. {
  884. $role = Auth::user()->role;
  885. switch ($role) {
  886. case 1:
  887. case 2:
  888. case 3:
  889. $last = [1, 0];
  890. break;
  891. case 4:
  892. $last = [1];
  893. break;
  894. default:
  895. App::abort('404');
  896. }
  897. if ($annual_report_or_plan == "report") {
  898. $report = 1;
  899. } else if ($annual_report_or_plan == "plan") {
  900. $report = 0;
  901. } else {
  902. App::abort('404');
  903. }
  904. $title = "Annual Plans for " . Program::findOrFail($program_id)->name;
  905. $paths_with_users = DB::table('paths_for_annual_plans')
  906. ->join('annual_plans', 'annual_plans.id', '=', 'paths_for_annual_plans.annual_plan_id')
  907. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  908. ->join('users', 'users.id', '=', 'paths_for_annual_plans.user_id')
  909. ->where('report', $report)
  910. ->whereIn('last', $last)
  911. ->where('annual_plans.program_id', $program_id)
  912. ->orderBy('date_posted', 'desc')
  913. ->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')
  914. ->get();
  915. return View::make('local.managers.shared.new_view_annual_plans', compact('paths_with_users', 'title', 'report', 'last', 'annual_report_or_plan', 'program_id'));
  916. }
  917. public function adminReportIndex()
  918. {
  919. }
  920. public function downloadPDF($download, $path_id)
  921. {
  922. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  923. $queryToPath = DB::table('paths_for_annual_plans')
  924. ->where('id', $path_id)
  925. ->first();
  926. //Log::info("ERES TU? creo que no");
  927. $path = storage_path($queryToPath->path_to_pdf);
  928. if ($download != "download") {
  929. return Response::make(file_get_contents($queryToPath->path_to_pdf), 200, [
  930. 'Content-type' => 'application/pdf',
  931. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  932. ]);
  933. } else {
  934. return Response::download(
  935. file_get_contents($queryToPath->path_to_pdf),
  936. 200,
  937. [
  938. 'Content-type' => 'application/pdf',
  939. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  940. ]
  941. );
  942. }
  943. /*
  944. [
  945. 'Content-type' => 'application/pdf',
  946. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  947. ]
  948. */
  949. $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
  950. Log::info("ERES TU?");
  951. //return View::make('local.managers.shared.print_annual_report', compact('annualPlan'));
  952. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  953. ->setOrientation("landscape")
  954. ->setPaper('legal', 'landscape');
  955. if ($download == "download")
  956. return $pdf->download(basename($queryToPath->path_to_pdf));
  957. else
  958. return $pdf->stream(basename($queryToPath->path_to_pdf));
  959. }
  960. public function checkIfPlanReady()
  961. {
  962. $annual_plan = AnnualPlan::findOrFail(Input::get("annual_id"));
  963. Log::info('annual_plan' . $annual_plan->courses);
  964. /*
  965. error = [
  966. [
  967. outcome, objective, course
  968. ]
  969. ]
  970. */
  971. $error_array = [];
  972. foreach ($annual_plan->courses as $index => $course) {
  973. Log::info('paired Criteria');
  974. Log::info($course->paired_criteria);
  975. if (count($course->paired_criteria) <= 0) {
  976. $outcome = $course->paired_objective->paired_outcome;
  977. $objective = $course->paired_objective;
  978. $array_to_be_appended = [
  979. "outcome_name" => $outcome->name,
  980. "objective_text" => $objective->text,
  981. "course_code" => $course->code . '-' . $course->number,
  982. 'typ_semester_course_id' => $course->typ_semester_course_id,
  983. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  984. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id
  985. ];
  986. $error_array[] = $array_to_be_appended;
  987. }
  988. }
  989. return $error_array;
  990. }
  991. public function checkIfReady()
  992. {
  993. $annual_plan = AnnualPlan::find(Input::get('annual_id'));
  994. /*Error message schema
  995. courses_where_missing_data = [
  996. course_1=>[
  997. info, info
  998. objective => {
  999. typ_semester_objective_id,
  1000. objective_text
  1001. }
  1002. outcome => {
  1003. typ_semester_outcome_id,
  1004. outcome_name
  1005. }
  1006. ]
  1007. ]
  1008. */
  1009. $courses_where_missing_data = [
  1010. 'courses' => [],
  1011. 'outcomes' => []
  1012. ];
  1013. Log::info($annual_plan->courses_with_transformative_actions);
  1014. foreach ($annual_plan->courses_with_transformative_actions as $course) {
  1015. foreach ($course->proposed_transformative_actions as $ta) {
  1016. if (!isset($ta->status)) {
  1017. $objective = $course->paired_objective;
  1018. $objective_info = [
  1019. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  1020. 'text' => $objective->text
  1021. ];
  1022. $outcome = $objective->paired_outcome;
  1023. $outcome_info = [
  1024. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  1025. 'name' => $outcome->name
  1026. ];
  1027. $array_to_be_appended = [
  1028. 'course_name' => $course->code . '-' . $course->number,
  1029. 'objective' => $objective_info,
  1030. 'outcome' => $outcome_info,
  1031. 'transformative_action_title' => $ta->at_text,
  1032. 'transformative_action_description' => $ta->description,
  1033. 'typ_semester_course_id' => $course->typ_semester_course_id
  1034. ];
  1035. $courses_where_missing_data['courses'][] = $array_to_be_appended;
  1036. }
  1037. }
  1038. }
  1039. foreach ($annual_plan->outcomes as $outcome) {
  1040. foreach ($outcome->program_transformative_actions as $ta) {
  1041. if (!isset($ta->status)) {
  1042. $array_to_be_appended = [
  1043. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  1044. 'outcome_name' => $outcome->name,
  1045. 'transformative_action_title' => $ta->at_text,
  1046. 'transformative_action_description' => $ta->description
  1047. ];
  1048. $courses_where_missing_data['outcomes'][] = $array_to_be_appended;
  1049. }
  1050. }
  1051. }
  1052. return $courses_where_missing_data;
  1053. }
  1054. function printAnnualPlan($annual_id)
  1055. {
  1056. $alphabet = range("A", "Z");
  1057. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1058. $small_alphabet = range('a', 'z');
  1059. return View::make('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet'));
  1060. }
  1061. function submitAnnualPlan($annual_id)
  1062. {
  1063. $alphabet = range("A", "Z");
  1064. $small_alphabet = range('a', 'z');
  1065. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1066. $user_id = Auth::user()->id;
  1067. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  1068. $pdf = $pdf->loadView('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet'))
  1069. ->setOrientation("landscape")
  1070. ->setPaper('legal', 'landscape');
  1071. $path = app_path() . '/storage/annual_pdfs/plan-on-' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '-by-' . $user_id . '.pdf';
  1072. $pdf->save($path);
  1073. $name = "plan-on-" . date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf';
  1074. $pdf->download($name);
  1075. //is a path already there
  1076. $it_exists = DB::table("paths_for_annual_plans")
  1077. ->where('path_to_pdf', $path)
  1078. ->first();
  1079. if (isset($it_exists)) {
  1080. return '200';
  1081. }
  1082. DB::table("paths_for_annual_plans")
  1083. ->where('annual_plan_id', $annual_id)
  1084. ->where('report', 0)
  1085. ->where('user_id', $user_id)
  1086. ->update(array(
  1087. 'last' => 0
  1088. ));
  1089. DB::table('paths_for_annual_plans')->insert(array(
  1090. "path_to_pdf" => $path,
  1091. 'annual_plan_id' => $annual_id,
  1092. 'last' => 1,
  1093. 'report' => 0,
  1094. 'user_id' => $user_id,
  1095. 'date_posted' => date('Y-m-d')
  1096. ));
  1097. return '200';
  1098. }
  1099. }