Keine Beschreibung

AnnualPlansController.php 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. use Illuminate\Support\Facades\Auth;
  3. use Illuminate\Support\Facades\Input;
  4. class AnnualPlansController extends \BaseController
  5. {
  6. /**
  7. * Checks whether a user has permission to view a page in this controller
  8. *
  9. * @var User $user Authenticated user
  10. */
  11. private function userHasAccess($program_id)
  12. {
  13. $user = Auth::user();
  14. switch ($user->role) {
  15. case '3':
  16. $programs = $user->programs->lists('id');
  17. // If program does not belong to user, show 403
  18. if (!in_array($program_id, $programs))
  19. return false;
  20. break;
  21. case '2':
  22. $programs = Program::where('school_id', $user->school_id)->lists('id');
  23. // If program is not in user's school, show 403
  24. if (!in_array($program_id, $programs))
  25. return false;
  26. break;
  27. case '4':
  28. return false;
  29. }
  30. return true;
  31. }
  32. public function viewAllPlans($program_id)
  33. {
  34. $title = "Annual Plans";
  35. $annual_plans = DB::select("select * from annual_plans where program_id ={$program_id} order by id desc");
  36. return View::make('local.managers.sCoords.view-annual-plans', compact('title', 'program_id', 'annual_plans'));
  37. }
  38. /**
  39. * Lists annual plans by year and program
  40. * @var string $title Title for page
  41. * @var Program $programs Collection of programs user has access to
  42. * @var User $user Authenticated user
  43. * @var Quinquennium $quinquenniums All current or past quinquenniums
  44. * @var Quinquennium $current_quinquennium Current quinquennium
  45. */
  46. public function postReport()
  47. {
  48. $program_id = Input::get('program_id') + 0;
  49. $realized = Input::get('realized');
  50. $logrado = Input::get('logrado');
  51. $continued = Input::get('continued');
  52. $semester = Input::get('semester');
  53. $typ_objective = Input::get('typ_objective');
  54. $transformative = Input::get('transformative');
  55. $annual_id = Input::get("annual_id") + 0;
  56. $id = Auth::user()['id'];
  57. for ($i = 0; $i < count($semester); $i++) {
  58. $real = $realized[$i] + 0;
  59. $logr = $logrado[$i] + 0;
  60. $cont = $continued[$i] + 0;
  61. $obj = $typ_objective[$i] + 0;
  62. $trans = $transformative[$i] + 0;
  63. $sem = $semester[$i] + 0;
  64. //if it was continued
  65. if ($real == 1) $real = 2;
  66. else $real = 1;
  67. if ($cont == 1) $cont = $sem + 1;
  68. else $cont = "NULL";
  69. $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;
  70. $queryUpdate = DB::select("select * from annual_report_transformative where annual_trans_id = {$annual_trans_id}");
  71. if (!count($queryUpdate)) {
  72. DB::insert("insert into annual_report_transformative (accomplished, cycle_of_life, semester_used, semester_continue, annual_trans_id, supervised_coordinator_id) values ({$logr},{$real},{$sem},{$cont},{$annual_trans_id}, {$id})");
  73. } else {
  74. DB::update("update annual_report_transformative set accomplished = {$logr}, cycle_of_life ={$real}, semester_used ={$sem}, semester_continue={$cont}, supervised_coordinator_id={$id} where annual_trans_id ={$annual_trans_id}");
  75. }
  76. }
  77. return;
  78. }
  79. public function index()
  80. {
  81. $title = 'Annual Plans';
  82. $user = Auth::user();
  83. $quinquenniums = Quinquennium::where('start_date', '<=', date('Y-m-d'))->get();
  84. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  85. ->where('end_date', '>=', date('Y-m-d'))
  86. ->first();
  87. switch ($user->role) {
  88. case '1':
  89. $programs = Program::all();
  90. break;
  91. case '2':
  92. $programs = Program::where('school_id', $user->school_id)->get();
  93. break;
  94. case 3:
  95. $programs = $user->programs;
  96. break;
  97. default:
  98. App::abort('404');
  99. break;
  100. }
  101. return View::make('local.managers.shared.index_annual_plans', compact('title', 'quinquenniums', 'programs', 'current_quinquennium'));
  102. }
  103. public function adminIndex($school_id)
  104. {
  105. $title = "Annual Plans";
  106. $programs = Program::where("school_id", $school_id)->get();
  107. return View::make('local.managers.admins.appraisal-program', compact('title', 'programs'));
  108. }
  109. public function showPlan($program_id, $typ_id = null)
  110. {
  111. $title = "Annual Plans";
  112. //$typ_parts = DB::select("select * from typ_parts");
  113. if (!$typ_id) {
  114. $current_typ = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'))[0];
  115. } else {
  116. $current_typ = DB::select("select * from three_year_plan where id ={$typ_id}")[0];
  117. }
  118. $program = Program::where('id', '=', $program_id)->first();
  119. $annual_plans = DB::select("select * from annual_plans where program_id = {$program_id} order by id desc limit 5");
  120. Log::info($annual_plans);
  121. $outcomes = array();
  122. $allSemesterOrder = array();
  123. foreach ($annual_plans as $an_plan) {
  124. Log::info($an_plan->id);
  125. $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} ))");
  126. $allSemesterOrder[$an_plan->id]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  127. $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} ))");
  128. $allSemesterOrder[$an_plan->id]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  129. }
  130. $alltyp = DB::select('select * from three_year_plan order by id desc');
  131. $current_typ = $current_typ->id;
  132. return View::make('local.managers.sCoords.annual-plans', compact('title', 'annual_plans', 'current_typ', 'program', 'outcomes', 'allSemesterOrder', 'alltyp'));
  133. }
  134. public function fetchInfo()
  135. {
  136. Log::info(Input::get('id'));
  137. $an_plan = DB::table("annual_plans")->where('id', '=', Input::get('id'))->first();
  138. $years = explode('-', $an_plan->academic_year);
  139. $current_typ_program = 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];
  140. $json_to_send = [];
  141. $json_to_send["annual_plans"] = $an_plan;
  142. $json_to_send["outcomes"]["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 = {$current_typ_program->id})");
  143. $json_to_send["allSemesterOrder"]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  144. $json_to_send["outcomes"]["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 = {$current_typ_program->id})");
  145. $json_to_send["allSemesterOrder"]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  146. return json_encode($json_to_send);
  147. }
  148. /**
  149. * Page to create a new plan for the current quinquennium
  150. * @var string $title Title for page
  151. * @var Program $programs Collection of programs user has access to
  152. * @var Outcome $outcomes List of outcomes ordered by name
  153. * @var User $user Currently logged user
  154. * @var Course $courses Courses for a particular program
  155. */
  156. public function fetchTYP($program_id)
  157. {
  158. $typ_info = array();
  159. $semester = DB::select("select * from semesters where id=?", array(Input::get('semester')))[0];
  160. //$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')));
  161. //foreach ($typ_info['courses'] as $course) {
  162. // $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}))");
  163. // foreach ($typ_info['courses_objective'][$course->id] as $objective) {
  164. // $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')));
  165. // }
  166. //}
  167. //$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')));
  168. //$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')));
  169. //foreach ($typ_info['unique_objective'] as $objective) {
  170. // $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')));
  171. // $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')));
  172. //}
  173. $annual_plan = DB::select("select id from annual_plans where (semester_start = {$semester->id} or semester_end ={$semester->id}) and program_id ={$program_id}")[0];
  174. $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')));
  175. $typ_info['transformative_actions'] = DB::select("select * from transformative_actions where by_professor =0 and is_custom=0");
  176. foreach ($typ_info['objectives'] as $objective) {
  177. $typ_info['courses'][$objective->id] = DB::select("select c.id, c.number, 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')));
  178. $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')));
  179. Log::info($typ_info['criteria'][$objective->id]);
  180. $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')));
  181. Log::info($typ_info['typ_objective_id'][$objective->id]);
  182. $typ_info['typ_objective_id'][$objective->id] = $typ_info['typ_objective_id'][$objective->id][0];
  183. Log::info($typ_info['typ_objective_id'][$objective->id]->id);
  184. Log::info($annual_plan->id);
  185. $typ_info['annual_plans_transformative'][$objective->id] = DB::select("select trans_id from annual_plan_transformative where annual_plan_id={$annual_plan->id} and typ_semester_objective_id ={$typ_info['typ_objective_id'][$objective->id]->id}");
  186. foreach ($typ_info['courses'][$objective->id] as $course) {
  187. $typ_info['selected_criteria'][$objective->id][$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} ");
  188. }
  189. $typ_info['custom_transformative'][$objective->id] = DB::select("select * from transformative_actions where is_custom =1 and by_professor=0 and id in (select ta_id from transformative_objective_program where objective_id = {$objective->id})");
  190. }
  191. $typ_info['annual_plan'] = $annual_plan;
  192. Log::info($typ_info);
  193. return json_encode($typ_info);
  194. }
  195. public function deleteTA()
  196. {
  197. $annual_id = Input::get('annual_id') + 0;
  198. $typ_id = Input::get('typ_id') + 0;
  199. $trans_id = Input::get('TA_id') + 0;
  200. DB::delete("delete from `annual_plan_transformative` where annual_plan_id ={$annual_id} and typ_semester_objective_id ={$typ_id} and trans_id={$trans_id}");
  201. return;
  202. }
  203. public function postTA()
  204. {
  205. $annual_id = Input::get('annual_id') + 0;
  206. $TA_id = Input::get('TA_id') + 0;
  207. $typ_id = Input::get('typ_id') + 0;
  208. $old_ta = Input::get('old_ta') + 0;
  209. $id = Auth::user()['id'];
  210. $date = date('Y-m-d');
  211. $date = strtotime($date);
  212. $query = DB::select("select * from annual_plan_transformative where annual_plan_id ={$annual_id} and trans_id ={$old_ta} and typ_semester_objective_id ={$typ_id}");
  213. if (!count($query)) {
  214. DB::insert("insert into `annual_plan_transformative` (`annual_plan_id`,`trans_id`, `typ_semester_objective_id`, `proposing_coordinator_id`, `proposed_date`) values({$annual_id},{$TA_id},{$typ_id}, {$id}, now() ) ");
  215. return "Insert Successful";
  216. } else {
  217. if ($TA_id == 0) {
  218. DB::delete("delete from annual_plan_transformative where trans_id={$TA_id} and annual_plan_id ={$annual_id} and typ_semester_objective_id ={$typ_id}");
  219. return "deleted";
  220. } else {
  221. 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_objective_id ={$typ_id}");
  222. return "updated";
  223. }
  224. }
  225. }
  226. public function transformativeReport()
  227. {
  228. $json_to_send = array();
  229. $annual_id = Input::get('an_id');
  230. $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}) ");
  231. foreach ($transformative_action_info as $trans) {
  232. $json_to_send['Trans_act'][$trans->id] = $trans;
  233. $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})))");
  234. foreach ($json_to_send['outcomes'][$trans->id] as $outcome) {
  235. $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})");
  236. foreach ($json_to_send['typ_objective'][$outcome->id][$trans->id] as $typ) {
  237. $json_to_send['objective'][$outcome->id][$typ->id][$trans->id] = DB::select("select * from objectives where id = {$typ->objective_id}")[0];
  238. $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];
  239. $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];
  240. $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];
  241. }
  242. }
  243. if ($trans->user_id) {
  244. $json_to_send['suggested'][$trans->id] = DB::select("select * from users where id = {$trans->user_id}");
  245. }
  246. }
  247. return json_encode($json_to_send);
  248. }
  249. public function deleteCriteria()
  250. {
  251. $criteria = Input::get('criteria') + 0;
  252. $typ_course_id = Input::get('typ_course_id') + 0;
  253. $annual_plan = Input::get('annual_plan') + 0;
  254. $old_criteria = Input::get('old_criteria') + 0;
  255. $message = '';
  256. 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}");
  257. return;
  258. }
  259. public function fetchAllTables()
  260. {
  261. $annual_plan = array();
  262. $an_id = Input::get('id');
  263. $program_id = Input::get('program_id');
  264. $an_semesters = DB::select("select semester_start, semester_end, program_id from annual_plans where id ={$an_id} and program_id ={$program_id}")[0];
  265. $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}))");
  266. $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}))");
  267. $annual_plan['first']['semester'] = array('id' => $an_semesters->semester_start);
  268. $annual_plan['second']['semester'] = array('id' => $an_semesters->semester_end);
  269. foreach ($annual_plan['first']['outcomes'] as $outcomes) {
  270. $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})))");
  271. Log::info($outcomes->id);
  272. Log::info($annual_plan['first']['objectives'][$outcomes->id]);
  273. foreach ($annual_plan['first']['objectives'][$outcomes->id] as $objective) {
  274. Log::info($objective->id);
  275. Log::info($an_semesters->semester_start);
  276. Log::info($an_semesters->program_id);
  277. Log::info(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})) "));
  278. $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];
  279. $annual_plan['first']['courses'][$objective->id] = DB::select("select typ.id typ_id, typ.course_id, c.code, c.number 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");
  280. foreach ($annual_plan['first']['courses'][$objective->id] as $course) {
  281. $annual_plan['first']['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_id} )");
  282. }
  283. Log::info($objective->id);
  284. $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})");
  285. foreach ($annual_plan['first']['trans_actions'][$objective->id] as $trans) {
  286. Log::info($annual_plan['first']['typ_objective_id'][$objective->id]->id);
  287. Log::info($trans->id);
  288. Log::info($an_id);
  289. $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} )");
  290. if (count($annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  291. Log::info("entró");
  292. $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];
  293. }
  294. }
  295. }
  296. }
  297. foreach ($annual_plan['second']['outcomes'] as $outcomes) {
  298. $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})))");
  299. foreach ($annual_plan['second']['objectives'][$outcomes->id] as $objective) {
  300. $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];
  301. $annual_plan['second']['courses'][$objective->id] = DB::select("select typ.id typ_id, typ.course_id, c.code, c.number 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");
  302. foreach ($annual_plan['second']['courses'][$objective->id] as $course) {
  303. $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_id})");
  304. }
  305. $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})");
  306. Log::info($annual_plan['second']['typ_objective_id'][$objective->id]->id);
  307. foreach ($annual_plan['second']['trans_actions'][$objective->id] as $trans) {
  308. $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} )");
  309. Log::info("lol");
  310. if (count($annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  311. Log::info("entró");
  312. $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];
  313. }
  314. }
  315. }
  316. }
  317. return json_encode($annual_plan);
  318. }
  319. public function postAnnualPlan()
  320. {
  321. $criteria = Input::get('criteria') + 0;
  322. $typ_course_id = Input::get('typ_course_id') + 0;
  323. $annual_plan = Input::get('annual_plan') + 0;
  324. $old_criteria = Input::get('old_criteria') + 0;
  325. $message = '';
  326. $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}");
  327. if (!count($query)) {
  328. $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}");
  329. if (!count($query)) {
  330. DB::insert("insert into `annual_plan_objective` (`annual_plan_id`, `typ_semester_course_id`, `criteria_id`) values ({$annual_plan}, {$typ_course_id}, {$criteria})");
  331. $message = "inserting was a success";
  332. } else {
  333. $message = "Duplicate entry, please choose another criteria.";
  334. }
  335. } else {
  336. $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}");
  337. if (!count($query)) {
  338. 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} ");
  339. $message = "Updating was a success";
  340. } else {
  341. $message = "Duplicate entry, please choose another criteria.";
  342. }
  343. }
  344. return $message;
  345. }
  346. public function create(Program $program)
  347. {
  348. $title = 'New Annual Plan for ' . $program->name;
  349. $user = Auth::user();
  350. $outcomes = Outcome::orderBy('name')->get();
  351. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  352. ->where('end_date', '>=', date('Y-m-d'))
  353. ->first();
  354. $courses = Course::select('id', 'code', 'number', 'name')
  355. ->where('program_id', $program->id)
  356. ->groupBy('name')
  357. ->orderBy('code', 'ASC')
  358. ->orderBy('number', 'ASC')
  359. ->orderBy('name', 'ASC')
  360. ->get();
  361. // Check if user can create a plan
  362. if (!$this->userHasAccess($program->id)) {
  363. return View::make('global.403');
  364. }
  365. return View::make('local.managers.shared.create_annual_plan', compact('title', 'program', 'current_quinquennium', 'outcomes', 'courses'));
  366. }
  367. }