説明なし

AnnualPlansController.php 37KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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 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 id desc");
  36. return View::make('local.managers.shared.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. $comments = Input::get("comments");
  56. $annual_id = Input::get("annual_id") + 0;
  57. $id = Auth::user()['id'];
  58. for ($i = 0; $i < count($semester); $i++) {
  59. $real = $realized[$i] + 0;
  60. $logr = $logrado[$i] + 0;
  61. $cont = $continued[$i] + 0;
  62. $obj = $typ_objective[$i] + 0;
  63. $trans = $transformative[$i] + 0;
  64. $sem = $semester[$i] + 0;
  65. $comment = $comments[$i];
  66. //if it was continued
  67. if ($real == 1) $real = 2;
  68. else $real = 1;
  69. if ($cont == 1) $cont = $sem + 1;
  70. else $cont = "NULL";
  71. $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;
  72. $queryUpdate = DB::select("select * from annual_report_transformative where annual_trans_id = {$annual_trans_id}");
  73. if (!count($queryUpdate)) {
  74. 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}')");
  75. } else {
  76. 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}");
  77. }
  78. }
  79. return;
  80. }
  81. /*public function index()
  82. {
  83. $title = 'Annual Plans';
  84. $user = Auth::user();
  85. $quinquenniums = Quinquennium::where('start_date', '<=', date('Y-m-d'))->get();
  86. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  87. ->where('end_date', '>=', date('Y-m-d'))
  88. ->first();
  89. switch ($user->role) {
  90. case '1':
  91. $programs = Program::all();
  92. break;
  93. case '2':
  94. $programs = Program::where('school_id', $user->school_id)->get();
  95. break;
  96. case 3:
  97. $programs = $user->programs;
  98. break;
  99. default:
  100. App::abort('404');
  101. break;
  102. }
  103. return View::make('local.managers.shared.index_annual_plans', compact('title', 'quinquenniums', 'programs', 'current_quinquennium'));
  104. }*/
  105. public function adminIndex($school_id)
  106. {
  107. $title = "Annual Plans";
  108. $programs = Program::where("school_id", $school_id)->get();
  109. return View::make('local.managers.admins.appraisal-program', compact('title', 'programs'));
  110. }
  111. public function showPlan($program_id, $typ_id = null)
  112. {
  113. $title = "Annual Plans";
  114. //$typ_parts = DB::select("select * from typ_parts");
  115. // $current_typ = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'))[0];
  116. $current_typ_arr = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'));
  117. // var_dump($current_typ);exit();
  118. if (!empty($current_typ_arr)) $current_typ = $current_typ_arr[0];
  119. else {
  120. $current_typ = new stdClass();
  121. $current_typ->id = 0;
  122. }
  123. $program = Program::where('id', '=', $program_id)->first();
  124. //Dame los annual plans que esten dentro del three year plan
  125. $annual_plans = DB::table('annual_cycle')
  126. ->join('annual_plans', 'annual_cycle_id', '=', 'annual_cycle.id')
  127. ->where('program_id', $program_id)
  128. ->orderBy('semester_start')
  129. ->get();
  130. /*$annual_plans = DB::select("
  131. select
  132. academic_year,
  133. semester_start,
  134. semester_end,
  135. program_id,
  136. annual_plans.id as id
  137. from annual_plans
  138. join annual_cycle on annual_cycle_id = annual_cycle.id
  139. where program_id = {$program_id}
  140. and(
  141. semester_start in(
  142. select semester_id
  143. from typ_semester_outcome
  144. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  145. where program_id = {$program_id} )
  146. or semester_end in(
  147. select semester_id
  148. from typ_semester_outcome
  149. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  150. where program_id = {$program_id} )
  151. )
  152. order by semester_start desc");*/
  153. // $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 ");
  154. // Log::info($annual_plans);
  155. $outcomes = array();
  156. $allSemesterOrder = array();
  157. Log::info($annual_plans);
  158. /*foreach ($annual_plans as $an_plan) {
  159. Log::info($an_plan->id);
  160. $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} ))");
  161. $allSemesterOrder[$an_plan->id]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  162. $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} ))");
  163. $allSemesterOrder[$an_plan->id]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  164. }*/
  165. //$alltyp = DB::select('select * from three_year_plan order by id desc');
  166. //$current_typ = $current_typ->id;
  167. return View::make('local.managers.shared.annual-plans', compact('title', 'annual_plans', 'current_typ', 'program', 'outcomes', 'allSemesterOrder', 'alltyp'));
  168. }
  169. public function fetchInfo()
  170. {
  171. Log::info(Input::get('id'));
  172. $an_plan = DB::table("annual_plans")
  173. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  174. ->where('annual_plans.id', '=', Input::get('id'))
  175. ->select('annual_plans.id as id', 'program_id', 'academic_year', 'semester_start', 'semester_end')
  176. ->first();
  177. $years = explode('-', $an_plan->academic_year);
  178. $current_typ_program = DB::table('typ_program')
  179. ->join('typ_semester_outcome', 'typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  180. ->where('program_id', $an_plan->program_id)
  181. ->where('semester_id', $an_plan->semester_start)
  182. ->select('typ_program.*')
  183. ->first();
  184. Log::info(array($an_plan));
  185. Log::info(array($current_typ_program));
  186. //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];
  187. $json_to_send = [];
  188. $json_to_send["annual_plans"] = $an_plan;
  189. $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})");
  190. $json_to_send["allSemesterOrder"]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  191. $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})");
  192. $json_to_send["allSemesterOrder"]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  193. return json_encode($json_to_send);
  194. }
  195. /**
  196. * Page to create a new plan for the current quinquennium
  197. * @var string $title Title for page
  198. * @var Program $programs Collection of programs user has access to
  199. * @var Outcome $outcomes List of outcomes ordered by name
  200. * @var User $user Currently logged user
  201. * @var Course $courses Courses for a particular program
  202. */
  203. public function fetchTYP($program_id)
  204. {
  205. $typ_info = array();
  206. $semester = DB::select("select * from semesters where id=?", array(Input::get('semester')))[0];
  207. //$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')));
  208. //foreach ($typ_info['courses'] as $course) {
  209. // $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}))");
  210. // foreach ($typ_info['courses_objective'][$course->id] as $objective) {
  211. // $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')));
  212. // }
  213. //}
  214. //$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')));
  215. //$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')));
  216. //foreach ($typ_info['unique_objective'] as $objective) {
  217. // $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')));
  218. // $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')));
  219. //}
  220. $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];
  221. //$typ_info['expected_target'] = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester->id}");
  222. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  223. ->where('program_id', $program_id)
  224. ->where('semester_id', $semester->id)
  225. ->first();
  226. if (!$typ_info['expected_target']) {
  227. DB::beginTransaction();
  228. DB::table('target_outcomes_program')->insert(
  229. array(
  230. 'program_id' => $program_id,
  231. 'semester_id' => $semester->id,
  232. 'expected_target' => 70.00
  233. )
  234. );
  235. DB::commit();
  236. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  237. ->where('program_id', $program_id)
  238. ->where('semester_id', $semester->id)
  239. ->first();
  240. }
  241. $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')));
  242. $typ_info['transformative_actions'] = DB::select("select * from transformative_actions where by_professor =0 and is_custom=0");
  243. foreach ($typ_info['objectives'] as $objective) {
  244. $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')));
  245. $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')));
  246. Log::info($typ_info['criteria'][$objective->id]);
  247. $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')));
  248. Log::info($typ_info['typ_objective_id'][$objective->id]);
  249. $typ_info['typ_objective_id'][$objective->id] = $typ_info['typ_objective_id'][$objective->id][0];
  250. Log::info($typ_info['typ_objective_id'][$objective->id]->id);
  251. Log::info($annual_plan->id);
  252. // $typ_info['annual_plans_transformative'][$objective->id] = DB::select(
  253. // "select trans_id from annual_plan_transformative
  254. // where annual_plan_id={$annual_plan->id}
  255. // and typ_semester_objective_id ={$typ_info['typ_objective_id'][$objective->id]->id}"
  256. // );
  257. foreach ($typ_info['courses'][$objective->id] as $course) {
  258. $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} ");
  259. $typ_info['annual_plans_transformative'][$objective->id][$course->typ_course_id] = DB::table('annual_plan_transformative')
  260. ->select('trans_id')
  261. ->where('annual_plan_id', $annual_plan->id)
  262. ->where('typ_semester_course_id', $course->typ_course_id)
  263. ->get();
  264. $typ_info['custom_transformative'][$objective->id][$course->id] = DB::table('transformative_actions')
  265. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  266. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  267. ->where('is_custom', 1)
  268. ->where('by_professor', 0)
  269. ->where('ta_course.course_number', $course->number)
  270. ->where('ta_course.course_code', $course->code)
  271. ->where('transformative_objective.objective_id', $objective->id)
  272. ->get();
  273. }
  274. }
  275. $typ_info['annual_plan'] = $annual_plan;
  276. Log::info($typ_info);
  277. return json_encode($typ_info);
  278. }
  279. public function deleteTA()
  280. {
  281. $annual_id = Input::get('annual_id') + 0;
  282. $typ_id = Input::get('typ_id') + 0;
  283. $trans_id = Input::get('TA_id') + 0;
  284. 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}");
  285. return;
  286. }
  287. public function postTA()
  288. {
  289. $annual_id = Input::get('annual_id') + 0;
  290. $TA_id = Input::get('TA_id') + 0;
  291. $typ_id = Input::get('typ_course_id') + 0;
  292. $old_ta = Input::get('old_ta') + 0;
  293. $id = Auth::user()['id'];
  294. $date = date('Y-m-d');
  295. $date = strtotime($date);
  296. $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}");
  297. if (!count($query)) {
  298. 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() ) ");
  299. return "Insert Successful";
  300. } else {
  301. if ($TA_id == 0) {
  302. 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}");
  303. return "deleted";
  304. } else {
  305. 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}");
  306. return "updated";
  307. }
  308. }
  309. }
  310. public function CreateOrEdit($program_id)
  311. {
  312. $semester_id = Input::get('semester_id');
  313. $expected_target = Input::get('expected_target');
  314. $exist = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester_id}");
  315. if ($exist) {
  316. //update
  317. DB::update("update target_outcomes_program set expected_target = {$expected_target}, updated_at = now() where program_id = {$program_id} and semester_id = {$semester_id}");
  318. } else {
  319. //create a new one
  320. 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()}')");
  321. }
  322. return;
  323. }
  324. public function transformativeReport()
  325. {
  326. $json_to_send = array();
  327. $annual_id = Input::get('an_id');
  328. $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}) ");
  329. foreach ($transformative_action_info as $trans) {
  330. $json_to_send['Trans_act'][$trans->id] = $trans;
  331. $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})))");
  332. foreach ($json_to_send['outcomes'][$trans->id] as $outcome) {
  333. $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})");
  334. foreach ($json_to_send['typ_objective'][$outcome->id][$trans->id] as $typ) {
  335. $json_to_send['objective'][$outcome->id][$typ->id][$trans->id] = DB::select("select * from objectives where id = {$typ->objective_id}")[0];
  336. $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];
  337. $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];
  338. $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];
  339. }
  340. }
  341. if ($trans->user_id) {
  342. $json_to_send['suggested'][$trans->id] = DB::select("select * from users where id = {$trans->user_id}");
  343. }
  344. }
  345. return json_encode($json_to_send);
  346. }
  347. public function deleteCriteria()
  348. {
  349. $criteria = Input::get('criteria') + 0;
  350. $typ_course_id = Input::get('typ_course_id') + 0;
  351. $annual_plan = Input::get('annual_plan') + 0;
  352. $old_criteria = Input::get('old_criteria') + 0;
  353. $message = '';
  354. 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}");
  355. return;
  356. }
  357. public function fetchAllTables()
  358. {
  359. $annual_plan = array();
  360. $an_id = Input::get('id');
  361. $program_id = Input::get('program_id');
  362. $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];
  363. $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}))");
  364. $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}))");
  365. $annual_plan['first']['semester'] = array('id' => $an_semesters->semester_start);
  366. $annual_plan['second']['semester'] = array('id' => $an_semesters->semester_end);
  367. foreach ($annual_plan['first']['outcomes'] as $outcomes) {
  368. $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})))");
  369. Log::info($outcomes->id);
  370. Log::info($annual_plan['first']['objectives'][$outcomes->id]);
  371. foreach ($annual_plan['first']['objectives'][$outcomes->id] as $objective) {
  372. $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];
  373. $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");
  374. foreach ($annual_plan['first']['courses'][$objective->id] as $course) {
  375. $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} )");
  376. $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})");
  377. }
  378. Log::info($objective->id);
  379. /*$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})");
  380. foreach ($annual_plan['first']['trans_actions'][$objective->id] as $trans) {
  381. Log::info($annual_plan['first']['typ_objective_id'][$objective->id]->id);
  382. Log::info($trans->id);
  383. Log::info($an_id);
  384. $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} )");
  385. if (count($annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  386. Log::info("entró");
  387. $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];
  388. }
  389. }*/
  390. }
  391. }
  392. foreach ($annual_plan['second']['outcomes'] as $outcomes) {
  393. $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})))");
  394. foreach ($annual_plan['second']['objectives'][$outcomes->id] as $objective) {
  395. $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];
  396. $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");
  397. foreach ($annual_plan['second']['courses'][$objective->id] as $course) {
  398. $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})");
  399. $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})");
  400. }
  401. /*
  402. $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})");
  403. Log::info($annual_plan['second']['typ_objective_id'][$objective->id]->id);
  404. foreach ($annual_plan['second']['trans_actions'][$objective->id] as $trans) {
  405. $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} )");
  406. Log::info("lol");
  407. if (count($annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  408. Log::info("entró");
  409. $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];
  410. }
  411. }*/
  412. }
  413. }
  414. return json_encode($annual_plan);
  415. }
  416. public function postAnnualPlan()
  417. {
  418. $criteria = Input::get('criteria') + 0;
  419. $typ_course_id = Input::get('typ_course_id') + 0;
  420. $annual_plan = Input::get('annual_plan') + 0;
  421. $old_criteria = Input::get('old_criteria') + 0;
  422. $message = '';
  423. $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}");
  424. if (!count($query)) {
  425. $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}");
  426. if (!count($query)) {
  427. DB::insert("insert into `annual_plan_objective` (`annual_plan_id`, `typ_semester_course_id`, `criteria_id`) values ({$annual_plan}, {$typ_course_id}, {$criteria})");
  428. $message = "inserting was a success";
  429. } else {
  430. $message = "Duplicate entry, please choose another criteria.";
  431. }
  432. } else {
  433. $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}");
  434. if (!count($query)) {
  435. 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} ");
  436. $message = "Updating was a success";
  437. } else {
  438. $message = "Duplicate entry, please choose another criteria.";
  439. }
  440. }
  441. return $message;
  442. }
  443. public function create(Program $program)
  444. {
  445. $title = 'New Annual Plan for ' . $program->name;
  446. $user = Auth::user();
  447. $outcomes = Outcome::orderBy('name')->get();
  448. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  449. ->where('end_date', '>=', date('Y-m-d'))
  450. ->first();
  451. $courses = Course::select('id', 'code', 'number', 'name')
  452. ->where('program_id', $program->id)
  453. ->groupBy('name')
  454. ->orderBy('code', 'ASC')
  455. ->orderBy('number', 'ASC')
  456. ->orderBy('name', 'ASC')
  457. ->get();
  458. // Check if user can create a plan
  459. if (!$this->userHasAccess($program->id)) {
  460. return View::make('global.403');
  461. }
  462. return View::make('local.managers.shared.create_annual_plan', compact('title', 'program', 'current_quinquennium', 'outcomes', 'courses'));
  463. }
  464. function fetchAnnualReport()
  465. {
  466. $program_id = Input::get('program_id');
  467. $annual_plan_id = Input::get('annual_plan_id');
  468. $semester_start = Input::get('semester_start');
  469. $semester_end = Input::get('semester_end');
  470. $academic_year = Input::get('academic_year');
  471. $academic_year = (int) explode(",", $academic_year)[0];
  472. $course_codes = DB::table('annual_plan_objective as apo')
  473. ->join('typ_semester_courses as tyc', 'apo.typ_semester_course_id', '=', 'tyc.id')
  474. ->join('courses', 'tyc.course_id', '=', 'courses.id')
  475. ->where('annual_plan_id', $annual_plan_id)
  476. ->select('courses.code', 'courses.number')
  477. ->distinct()
  478. ->get();
  479. Log::info($course_codes);
  480. $all_courses_info = [];
  481. foreach ($course_codes as $index => $course_code) {
  482. //$all_courses_info['course_code'][] = $course_code->code . '_' . $course_code->number;
  483. $courses = Course::where(function ($query) use (&$semester_end, &$semester_start) {
  484. $query->where('semester_id', $semester_end)
  485. ->orWhere('semester_id', $semester_start);
  486. })
  487. ->where('code', $course_code->code)
  488. ->where('number', $course_code->number)
  489. ->where('program_id', $program_id)
  490. ->get();
  491. Log::info("run number " . $index);
  492. Log::info($courses);
  493. foreach ($courses as $course) {
  494. $all_courses_info[$course_code->code . '_' . $course_code->number][] = $course->getReportObject();
  495. }
  496. }
  497. /*$course_codes = DB::table('typ_semester_courses')
  498. ->join('typ_semester_objectives as tso', 'tso.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  499. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  500. ->join('typ_semester_outcome as typ_out', 'typ_out.id', '=', 'tso.typ_semester_outcome_id')
  501. ->join('typ_program', 'typ_out.typ_program_id', '=', 'typ_program.id')
  502. ->where(function ($query) use (&$semester_start, &$semester_end) {
  503. $query->where('typ_out.semester_id', $semester_start)
  504. ->orWhere('typ_out.semester_id', $semester_end);
  505. })
  506. ->where('typ_program.program_id', $program_id)
  507. ->select('courses.code', 'courses.number', 'typ_semester_courses.id as typ_sem_cou_id')
  508. ->distinct()
  509. ->get();*/
  510. /*foreach ($course_codes as $course_code) {
  511. $course_code->sections = DB::table('courses')
  512. ->join('activities', 'activities.course_id', '=', 'courses.id')
  513. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  514. ->join('annual_plan_objective', 'annual_plan_objective.criteria_id', '=', 'activity_criterion.criterion_id')
  515. ->join('typ_semester_courses', 'typ_semester_courses.id', '=', 'annual_plan_objective.typ_semester_course_id')
  516. ->where('courses.code', $course_code->code)
  517. ->where('courses.number', $course_code->number)
  518. ->where('annual_plan_id', $annual_plan_id)
  519. ->where('annual_plan_objective.typ_semester_course_id', $course_code->typ_sem_cou_id)
  520. ->toSql();
  521. Log::info($course_code->sections);
  522. }*/
  523. return $all_courses_info;
  524. }
  525. public function selectProgramPlan()
  526. {
  527. $title = "Program Annual Reports";
  528. $programs = Auth::user()->school->programs;
  529. return View::make('local.managers.shared.annual_select', compact('title', 'programs'));
  530. }
  531. public function fetchReportWithOutcome()
  532. {
  533. $program_id = Input::get('program_id');
  534. $semester_id = Input::get('semester_id');
  535. $annual_plan_id = Input::get('annual_plan_id');
  536. $outcome_id = Input::get('outcome_id');
  537. $outcome = Outcome::where('id', $outcome_id)->first();
  538. $outcome->objectives = $outcome->fetchObjectivesReport($semester_id, $program_id);
  539. $outcome->outcome_program_goal = DB::table('target_outcomes_program')
  540. ->where('program_id', $program_id)
  541. ->where('semester_id', $semester_id)
  542. ->first()->expected_target;
  543. foreach ($outcome->objectives as $index => $objective) {
  544. $objective->courses = Objective::getPlanReport($objective);
  545. }
  546. return $outcome;
  547. }
  548. }