Brak opisu

AnnualPlansController.php 49KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. $program = Program::find($program_id);
  35. $title = "Annual Plans for " . $program->name;
  36. $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");
  37. return View::make('local.managers.shared.view-annual-plans', compact('title', 'program_id', 'annual_plans'));
  38. }
  39. /**
  40. * Lists annual plans by year and program
  41. * @var string $title Title for page
  42. * @var Program $programs Collection of programs user has access to
  43. * @var User $user Authenticated user
  44. * @var Quinquennium $quinquenniums All current or past quinquenniums
  45. * @var Quinquennium $current_quinquennium Current quinquennium
  46. */
  47. public function postReport()
  48. {
  49. $program_id = Input::get('program_id') + 0;
  50. $realized = Input::get('realized');
  51. $logrado = Input::get('logrado');
  52. $continued = Input::get('continued');
  53. $semester = Input::get('semester');
  54. $typ_objective = Input::get('typ_objective');
  55. $transformative = Input::get('transformative');
  56. $comments = Input::get("comments");
  57. $annual_id = Input::get("annual_id") + 0;
  58. $id = Auth::user()['id'];
  59. for ($i = 0; $i < count($semester); $i++) {
  60. $real = $realized[$i] + 0;
  61. $logr = $logrado[$i] + 0;
  62. $cont = $continued[$i] + 0;
  63. $obj = $typ_objective[$i] + 0;
  64. $trans = $transformative[$i] + 0;
  65. $sem = $semester[$i] + 0;
  66. $comment = $comments[$i];
  67. //if it was continued
  68. if ($real == 1) $real = 2;
  69. else $real = 1;
  70. if ($cont == 1) $cont = $sem + 1;
  71. else $cont = "NULL";
  72. $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;
  73. $queryUpdate = DB::select("select * from annual_report_transformative where annual_trans_id = {$annual_trans_id}");
  74. if (!count($queryUpdate)) {
  75. 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}')");
  76. } else {
  77. 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}");
  78. }
  79. }
  80. return;
  81. }
  82. /*public function index()
  83. {
  84. $title = 'Annual Plans';
  85. $user = Auth::user();
  86. $quinquenniums = Quinquennium::where('start_date', '<=', date('Y-m-d'))->get();
  87. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  88. ->where('end_date', '>=', date('Y-m-d'))
  89. ->first();
  90. switch ($user->role) {
  91. case '1':
  92. $programs = Program::all();
  93. break;
  94. case '2':
  95. $programs = Program::where('school_id', $user->school_id)->get();
  96. break;
  97. case 3:
  98. $programs = $user->programs;
  99. break;
  100. default:
  101. App::abort('404');
  102. break;
  103. }
  104. return View::make('local.managers.shared.index_annual_plans', compact('title', 'quinquenniums', 'programs', 'current_quinquennium'));
  105. }*/
  106. public function adminIndex($school_id)
  107. {
  108. $title = "Annual Plans";
  109. $programs = Program::where("school_id", $school_id)->get();
  110. return View::make('local.managers.admins.appraisal-program', compact('title', 'programs'));
  111. }
  112. public function showPlan($program_id, $typ_id = null)
  113. {
  114. $program = Program::find($program_id);
  115. $title = "Annual Plans for " . $program->name;
  116. //$typ_parts = DB::select("select * from typ_parts");
  117. // $current_typ = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'))[0];
  118. $current_typ_arr = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'));
  119. // var_dump($current_typ);exit();
  120. if (!empty($current_typ_arr)) $current_typ = $current_typ_arr[0];
  121. else {
  122. $current_typ = new stdClass();
  123. $current_typ->id = 0;
  124. }
  125. //$program = Program::where('id', '=', $program_id)->first();
  126. //Dame los annual plans que esten dentro del three year plan
  127. $annual_plans = DB::table('annual_cycle')
  128. ->join('annual_plans', 'annual_cycle_id', '=', 'annual_cycle.id')
  129. ->where('program_id', $program_id)
  130. ->orderBy('semester_start', 'desc')
  131. ->get();
  132. /*$annual_plans = DB::select("
  133. select
  134. academic_year,
  135. semester_start,
  136. semester_end,
  137. program_id,
  138. annual_plans.id as id
  139. from annual_plans
  140. join annual_cycle on annual_cycle_id = annual_cycle.id
  141. where program_id = {$program_id}
  142. and(
  143. semester_start in(
  144. select semester_id
  145. from typ_semester_outcome
  146. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  147. where program_id = {$program_id} )
  148. or semester_end in(
  149. select semester_id
  150. from typ_semester_outcome
  151. join typ_program on typ_semester_outcome.typ_program_id = typ_program.id
  152. where program_id = {$program_id} )
  153. )
  154. order by semester_start desc");*/
  155. // $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 ");
  156. // Log::info($annual_plans);
  157. $outcomes = array();
  158. $allSemesterOrder = array();
  159. Log::info($annual_plans);
  160. /*foreach ($annual_plans as $an_plan) {
  161. Log::info($an_plan->id);
  162. $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} ))");
  163. $allSemesterOrder[$an_plan->id]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  164. $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} ))");
  165. $allSemesterOrder[$an_plan->id]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  166. }*/
  167. //$alltyp = DB::select('select * from three_year_plan order by id desc');
  168. //$current_typ = $current_typ->id;
  169. return View::make('local.managers.shared.annual-plans', compact('title', 'annual_plans', 'current_typ', 'program', 'outcomes', 'allSemesterOrder', 'alltyp'));
  170. }
  171. public function fetchInfo()
  172. {
  173. Log::info(Input::get('id'));
  174. $an_plan = DB::table("annual_plans")
  175. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  176. ->where('annual_plans.id', '=', Input::get('id'))
  177. ->select('annual_plans.id as id', 'program_id', 'academic_year', 'semester_start', 'semester_end', 'is_submitted')
  178. ->first();
  179. $years = explode('-', $an_plan->academic_year);
  180. $current_typ_program = DB::table('typ_program')
  181. ->join('typ_semester_outcome', 'typ_semester_outcome.typ_program_id', '=', 'typ_program.id')
  182. ->where('program_id', $an_plan->program_id)
  183. ->where(function ($query) use (&$an_plan) {
  184. $query->where('semester_id', $an_plan->semester_start)
  185. ->orWhere('semester_id', $an_plan->semester_end);
  186. })
  187. ->select('typ_program.*')
  188. ->first();
  189. Log::info(array($an_plan));
  190. Log::info(array($current_typ_program));
  191. //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];
  192. $json_to_send = [];
  193. $json_to_send["annual_plans"] = $an_plan;
  194. $json_to_send["outcomes"]["first"] = DB::table('outcomes')
  195. ->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  196. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  197. ->join('typ_semester_courses', 'typ_semester_objectives.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  198. ->where('semester_id', $an_plan->semester_start)
  199. ->where('typ_program_id', $current_typ_program->id)
  200. ->select('outcomes.*', 'typ_semester_outcome.id as typ_semester_outcome_id')
  201. ->groupBy('typ_semester_outcome_id')
  202. ->get();
  203. //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})");
  204. $json_to_send["allSemesterOrder"]["first"] = DB::select("select * from semesters where id = {$an_plan->semester_start}")[0];
  205. $json_to_send["outcomes"]["second"] = DB::table('outcomes')
  206. ->join('typ_semester_outcome', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
  207. ->join('typ_semester_objectives', 'typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id')
  208. ->join('typ_semester_courses', 'typ_semester_objectives.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  209. ->where('semester_id', $an_plan->semester_end)
  210. ->where('typ_program_id', $current_typ_program->id)
  211. ->select('outcomes.*', 'typ_semester_outcome.id as typ_semester_outcome_id')
  212. ->groupBy('typ_semester_outcome_id')
  213. ->get();
  214. //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})");
  215. $json_to_send["allSemesterOrder"]["second"] = DB::select("select * from semesters where id = {$an_plan->semester_end}")[0];
  216. return json_encode($json_to_send);
  217. }
  218. /**
  219. * Page to create a new plan for the current quinquennium
  220. * @var string $title Title for page
  221. * @var Program $programs Collection of programs user has access to
  222. * @var Outcome $outcomes List of outcomes ordered by name
  223. * @var User $user Currently logged user
  224. * @var Course $courses Courses for a particular program
  225. */
  226. public function fetchTYP($program_id)
  227. {
  228. $typ_info = array();
  229. $semester = DB::select("select * from semesters where id=?", array(Input::get('semester')))[0];
  230. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  231. //$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')));
  232. //foreach ($typ_info['courses'] as $course) {
  233. // $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}))");
  234. // foreach ($typ_info['courses_objective'][$course->id] as $objective) {
  235. // $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')));
  236. // }
  237. //}
  238. //$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')));
  239. //$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')));
  240. //foreach ($typ_info['unique_objective'] as $objective) {
  241. // $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')));
  242. // $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')));
  243. //}
  244. $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];
  245. //$typ_info['expected_target'] = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester->id}");
  246. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  247. ->where('program_id', $program_id)
  248. ->where('semester_id', $semester->id)
  249. ->first();
  250. if (!$typ_info['expected_target']) {
  251. DB::beginTransaction();
  252. DB::table('target_outcomes_program')->insert(
  253. array(
  254. 'program_id' => $program_id,
  255. 'semester_id' => $semester->id,
  256. 'expected_target' => 70.00
  257. )
  258. );
  259. DB::commit();
  260. $typ_info['expected_target'] = DB::table('target_outcomes_program')
  261. ->where('program_id', $program_id)
  262. ->where('semester_id', $semester->id)
  263. ->first();
  264. }
  265. $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')));
  266. $typ_info['transformative_actions'] = DB::select("select * from transformative_actions where by_professor =0 and is_custom=0");
  267. foreach ($typ_info['objectives'] as $objective) {
  268. $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')));
  269. $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')));
  270. Log::info($typ_info['criteria'][$objective->id]);
  271. $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')));
  272. Log::info($typ_info['typ_objective_id'][$objective->id]);
  273. $typ_info['typ_objective_id'][$objective->id] = $typ_info['typ_objective_id'][$objective->id][0];
  274. Log::info($typ_info['typ_objective_id'][$objective->id]->id);
  275. Log::info($annual_plan->id);
  276. // $typ_info['annual_plans_transformative'][$objective->id] = DB::select(
  277. // "select trans_id from annual_plan_transformative
  278. // where annual_plan_id={$annual_plan->id}
  279. // and typ_semester_objective_id ={$typ_info['typ_objective_id'][$objective->id]->id}"
  280. // );
  281. foreach ($typ_info['courses'][$objective->id] as $course) {
  282. $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} ");
  283. $typ_info['annual_plans_transformative'][$objective->id][$course->typ_course_id] = DB::table('annual_plan_transformative')
  284. ->select('trans_id')
  285. ->where('annual_plan_id', $annual_plan->id)
  286. ->where('typ_semester_course_id', $course->typ_course_id)
  287. ->get();
  288. //Log::info($course->typ_course_id);
  289. $typ_info['custom_transformative'][$objective->id][$course->id] = DB::table('transformative_actions')
  290. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  291. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  292. ->where('is_custom', 1)
  293. ->where('by_professor', 0)
  294. ->where('ta_course.course_number', $course->number)
  295. ->where('ta_course.course_code', $course->code)
  296. ->where('transformative_objective.objective_id', $objective->id)
  297. ->get();
  298. }
  299. }
  300. $typ_info['annual_plan'] = $annual_plan;
  301. Log::info($typ_info);
  302. $typ_info['transformative_actions_for_outcome'] = DB::table('transformative_actions')
  303. ->join('transformative_typ_outcome', 'transformative_typ_outcome.trans_id', '=', 'transformative_actions.id')
  304. ->where('transformative_typ_outcome.typ_semester_outcome_id', $typ_semester_outcome_id)
  305. ->get();
  306. $typ_info['categories'] = "<option value='0'>Nothing Selected</option>";
  307. $types = DB::table('transformative_actions')
  308. ->select('type_of_TA', 'is_custom')
  309. ->where('type_of_TA', '<>', '')
  310. ->where(function ($query) use (&$program_id) {
  311. $query->whereNull('program_id')
  312. ->orWhere('program_id', $program_id);
  313. })
  314. ->where('by_professor', 0)
  315. ->groupBy('type_of_TA')
  316. ->get();
  317. $optGroupGeneral = "<optgroup label='General Transformative Actions'>";
  318. $optGroupCustom = "<optgroup label ='Program Custom Actions'>";
  319. foreach ($types as $type) {
  320. if ($type->is_custom) {
  321. $optGroupCustom .= "<option value = '" . $type->type_of_TA . "' data-is-custom = '1'>" . $type->type_of_TA . "</option>";
  322. } else {
  323. $optGroupGeneral .= "<option value = '" . $type->type_of_TA . "' data-is-custom = '0'>" . $type->type_of_TA . "</option>";
  324. }
  325. }
  326. $typ_info['categories'] .= $optGroupGeneral . '</optgroup>';
  327. $typ_info['categories'] .= $optGroupCustom . '</optgroup>';
  328. $typ_info['categories'] .= '<option value ="new"> New Type of Transformative Action</option>';
  329. return json_encode($typ_info);
  330. }
  331. public function deleteTA()
  332. {
  333. $annual_id = Input::get('annual_id') + 0;
  334. $typ_id = Input::get('typ_id') + 0;
  335. $trans_id = Input::get('TA_id') + 0;
  336. 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}");
  337. return;
  338. }
  339. public function postTA()
  340. {
  341. $annual_id = Input::get('annual_id') + 0;
  342. $TA_id = Input::get('TA_id') + 0;
  343. $typ_id = Input::get('typ_course_id') + 0;
  344. $old_ta = Input::get('old_ta') + 0;
  345. $id = Auth::user()['id'];
  346. $date = date('Y-m-d');
  347. $date = strtotime($date);
  348. $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}");
  349. if (!count($query)) {
  350. 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() ) ");
  351. return "Insert Successful";
  352. } else {
  353. if ($TA_id == 0) {
  354. 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}");
  355. return "deleted";
  356. } else {
  357. 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}");
  358. return "updated";
  359. }
  360. }
  361. }
  362. public function CreateOrEdit($program_id)
  363. {
  364. $semester_id = Input::get('semester_id');
  365. $expected_target = Input::get('expected_target');
  366. $exist = DB::select("select * from target_outcomes_program where program_id = {$program_id} and semester_id = {$semester_id}");
  367. if ($exist) {
  368. //update
  369. DB::update("update target_outcomes_program set expected_target = {$expected_target}, updated_at = now() where program_id = {$program_id} and semester_id = {$semester_id}");
  370. } else {
  371. //create a new one
  372. 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()}')");
  373. }
  374. return;
  375. }
  376. public function transformativeReport()
  377. {
  378. $json_to_send = array();
  379. $annual_id = Input::get('an_id');
  380. $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}) ");
  381. foreach ($transformative_action_info as $trans) {
  382. $json_to_send['Trans_act'][$trans->id] = $trans;
  383. $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})))");
  384. foreach ($json_to_send['outcomes'][$trans->id] as $outcome) {
  385. $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})");
  386. foreach ($json_to_send['typ_objective'][$outcome->id][$trans->id] as $typ) {
  387. $json_to_send['objective'][$outcome->id][$typ->id][$trans->id] = DB::select("select * from objectives where id = {$typ->objective_id}")[0];
  388. $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];
  389. $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];
  390. $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];
  391. }
  392. }
  393. if ($trans->user_id) {
  394. $json_to_send['suggested'][$trans->id] = DB::select("select * from users where id = {$trans->user_id}");
  395. }
  396. }
  397. return json_encode($json_to_send);
  398. }
  399. public function deleteCriteria()
  400. {
  401. $criteria = Input::get('criteria') + 0;
  402. $typ_course_id = Input::get('typ_course_id') + 0;
  403. $annual_plan = Input::get('annual_plan') + 0;
  404. $old_criteria = Input::get('old_criteria') + 0;
  405. $message = '';
  406. 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}");
  407. return;
  408. }
  409. public function fetchAllTables()
  410. {
  411. $annual_plan = array();
  412. $an_id = Input::get('id');
  413. $program_id = Input::get('program_id');
  414. $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];
  415. $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}))");
  416. $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}))");
  417. $annual_plan['first']['semester'] = array('id' => $an_semesters->semester_start);
  418. $annual_plan['second']['semester'] = array('id' => $an_semesters->semester_end);
  419. foreach ($annual_plan['first']['outcomes'] as $outcomes) {
  420. $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})))");
  421. Log::info($outcomes->id);
  422. Log::info($annual_plan['first']['objectives'][$outcomes->id]);
  423. foreach ($annual_plan['first']['objectives'][$outcomes->id] as $objective) {
  424. $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];
  425. $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");
  426. foreach ($annual_plan['first']['courses'][$objective->id] as $course) {
  427. $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} )");
  428. $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})");
  429. }
  430. Log::info($objective->id);
  431. /*$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})");
  432. foreach ($annual_plan['first']['trans_actions'][$objective->id] as $trans) {
  433. Log::info($annual_plan['first']['typ_objective_id'][$objective->id]->id);
  434. Log::info($trans->id);
  435. Log::info($an_id);
  436. $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} )");
  437. if (count($annual_plan['fill_info'][$annual_plan['first']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  438. Log::info("entró");
  439. $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];
  440. }
  441. }*/
  442. }
  443. }
  444. foreach ($annual_plan['second']['outcomes'] as $outcomes) {
  445. $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})))");
  446. foreach ($annual_plan['second']['objectives'][$outcomes->id] as $objective) {
  447. $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];
  448. $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");
  449. foreach ($annual_plan['second']['courses'][$objective->id] as $course) {
  450. $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})");
  451. $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})");
  452. }
  453. /*
  454. $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})");
  455. Log::info($annual_plan['second']['typ_objective_id'][$objective->id]->id);
  456. foreach ($annual_plan['second']['trans_actions'][$objective->id] as $trans) {
  457. $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} )");
  458. Log::info("lol");
  459. if (count($annual_plan['fill_info'][$annual_plan['second']['typ_objective_id'][$objective->id]->id][$trans->id])) {
  460. Log::info("entró");
  461. $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];
  462. }
  463. }*/
  464. }
  465. }
  466. return json_encode($annual_plan);
  467. }
  468. public function postAnnualPlan()
  469. {
  470. $criteria = Input::get('criteria') + 0;
  471. $typ_course_id = Input::get('typ_course_id') + 0;
  472. $annual_plan = Input::get('annual_plan') + 0;
  473. $old_criteria = Input::get('old_criteria') + 0;
  474. $message = '';
  475. $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}");
  476. if (!count($query)) {
  477. $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}");
  478. if (!count($query)) {
  479. DB::insert("insert into `annual_plan_objective` (`annual_plan_id`, `typ_semester_course_id`, `criteria_id`) values ({$annual_plan}, {$typ_course_id}, {$criteria})");
  480. $message = "inserting was a success";
  481. } else {
  482. $message = "Duplicate entry, please choose another criteria.";
  483. }
  484. } else {
  485. $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}");
  486. if (!count($query)) {
  487. 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} ");
  488. $message = "Updating was a success";
  489. } else {
  490. $message = "Duplicate entry, please choose another criteria.";
  491. }
  492. }
  493. return $message;
  494. }
  495. public function create(Program $program)
  496. {
  497. $title = 'New Annual Plan for ' . $program->name;
  498. $user = Auth::user();
  499. $outcomes = Outcome::orderBy('name')->get();
  500. $current_quinquennium = Quinquennium::where('start_date', '<=', date('Y-m-d'))
  501. ->where('end_date', '>=', date('Y-m-d'))
  502. ->first();
  503. $courses = Course::select('id', 'code', 'number', 'name')
  504. ->where('program_id', $program->id)
  505. ->groupBy('name')
  506. ->orderBy('code', 'ASC')
  507. ->orderBy('number', 'ASC')
  508. ->orderBy('name', 'ASC')
  509. ->get();
  510. // Check if user can create a plan
  511. if (!$this->userHasAccess($program->id)) {
  512. return View::make('global.403');
  513. }
  514. return View::make('local.managers.shared.create_annual_plan', compact('title', 'program', 'current_quinquennium', 'outcomes', 'courses'));
  515. }
  516. function fetchAnnualReport()
  517. {
  518. $program_id = Input::get('program_id');
  519. $annual_plan_id = Input::get('annual_plan_id');
  520. $semester_start = Input::get('semester_start');
  521. $semester_end = Input::get('semester_end');
  522. $academic_year = Input::get('academic_year');
  523. $academic_year = (int) explode(",", $academic_year)[0];
  524. $course_codes = DB::table('annual_plan_objective as apo')
  525. ->join('typ_semester_courses as tyc', 'apo.typ_semester_course_id', '=', 'tyc.id')
  526. ->join('courses', 'tyc.course_id', '=', 'courses.id')
  527. ->where('annual_plan_id', $annual_plan_id)
  528. ->select('courses.code', 'courses.number')
  529. ->distinct()
  530. ->get();
  531. Log::info($course_codes);
  532. $all_courses_info = [];
  533. foreach ($course_codes as $index => $course_code) {
  534. //$all_courses_info['course_code'][] = $course_code->code . '_' . $course_code->number;
  535. $courses = Course::where(function ($query) use (&$semester_end, &$semester_start) {
  536. $query->where('semester_id', $semester_end)
  537. ->orWhere('semester_id', $semester_start);
  538. })
  539. ->where('code', $course_code->code)
  540. ->where('number', $course_code->number)
  541. ->where('program_id', $program_id)
  542. ->get();
  543. Log::info("run number " . $index);
  544. Log::info($courses);
  545. foreach ($courses as $course) {
  546. $all_courses_info[$course_code->code . '_' . $course_code->number][] = $course->getReportObject();
  547. }
  548. }
  549. /*$course_codes = DB::table('typ_semester_courses')
  550. ->join('typ_semester_objectives as tso', 'tso.id', '=', 'typ_semester_courses.typ_semester_objective_id')
  551. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  552. ->join('typ_semester_outcome as typ_out', 'typ_out.id', '=', 'tso.typ_semester_outcome_id')
  553. ->join('typ_program', 'typ_out.typ_program_id', '=', 'typ_program.id')
  554. ->where(function ($query) use (&$semester_start, &$semester_end) {
  555. $query->where('typ_out.semester_id', $semester_start)
  556. ->orWhere('typ_out.semester_id', $semester_end);
  557. })
  558. ->where('typ_program.program_id', $program_id)
  559. ->select('courses.code', 'courses.number', 'typ_semester_courses.id as typ_sem_cou_id')
  560. ->distinct()
  561. ->get();*/
  562. /*foreach ($course_codes as $course_code) {
  563. $course_code->sections = DB::table('courses')
  564. ->join('activities', 'activities.course_id', '=', 'courses.id')
  565. ->join('activity_criterion', 'activity_criterion.activity_id', '=', 'activities.id')
  566. ->join('annual_plan_objective', 'annual_plan_objective.criteria_id', '=', 'activity_criterion.criterion_id')
  567. ->join('typ_semester_courses', 'typ_semester_courses.id', '=', 'annual_plan_objective.typ_semester_course_id')
  568. ->where('courses.code', $course_code->code)
  569. ->where('courses.number', $course_code->number)
  570. ->where('annual_plan_id', $annual_plan_id)
  571. ->where('annual_plan_objective.typ_semester_course_id', $course_code->typ_sem_cou_id)
  572. ->toSql();
  573. Log::info($course_code->sections);
  574. }*/
  575. return $all_courses_info;
  576. }
  577. public function selectProgramPlan()
  578. {
  579. $title = "Program Annual Reports";
  580. $programs = Auth::user()->school->programs;
  581. return View::make('local.managers.shared.annual_select', compact('title', 'programs'));
  582. }
  583. //Fetch report in annual_plan_report
  584. public function fetchReportWithOutcome()
  585. {
  586. $program_id = Input::get('program_id');
  587. $semester_id = Input::get('semester_id');
  588. $annual_plan_id = Input::get('annual_plan_id');
  589. $outcome_id = Input::get('outcome_id');
  590. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  591. $outcome = Outcome::where('id', $outcome_id)->first();
  592. $outcome->objectives = $outcome->fetchObjectivesReport($semester_id, $program_id);
  593. $outcome->outcome_program_goal = DB::table('target_outcomes_program')
  594. ->where('program_id', $program_id)
  595. ->where('semester_id', $semester_id)
  596. ->first();
  597. $outcome->transforming_actions = DB::table('transformative_typ_outcome')
  598. ->join('transformative_actions', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  599. ->leftJoin('transformative_action_status', 'transformative_actions.id', '=', 'transformative_action_status.trans_id')
  600. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  601. ->select('transformative_actions.*', 'transformative_action_status.*', 'transformative_actions.id as trans_id')
  602. ->get();
  603. $outcome->semester_info = DB::table('semesters')
  604. ->where('id', $semester_id)
  605. ->first();
  606. $outcome->comments = DB::table('typ_outcome_report_comments')
  607. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  608. ->get();
  609. $outcome->transformative_actions_categories_html = TransformativeAction::getCategoriesHtml($program_id);
  610. foreach ($outcome->objectives as $index => $objective) {
  611. $objective->courses = Objective::getPlanReport($objective);
  612. }
  613. return $outcome;
  614. }
  615. public function fetchObjectiveInfo()
  616. {
  617. $typ_objective_id = Input::get('typ_objective_id');
  618. $courses = DB::table('typ_semester_courses')
  619. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  620. ->select('courses.code', 'courses.number', 'courses.name', 'typ_semester_courses.id as typ_semester_course_id')
  621. ->where('typ_semester_objective_id', $typ_objective_id)
  622. ->distinct()
  623. ->get();
  624. foreach ($courses as $course) {
  625. /*$course->criteria_scale = DB::table('annual_plan_objective')
  626. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  627. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  628. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  629. ->select('criterion_scale.*', 'scales.*')
  630. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  631. ->orderBy('position', 'ASC')
  632. ->get();*/
  633. $course->criteria = DB::table('annual_plan_objective')
  634. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  635. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  636. ->select('criteria.*')
  637. ->get();
  638. foreach ($course->criteria as $criterion) {
  639. $criterion->scales = DB::table('criteria')
  640. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  641. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  642. ->select('criterion_scale.*', 'scales.*')
  643. ->where('criteria.id', $criterion->id)
  644. ->orderBy('position', 'ASC')
  645. ->get();
  646. }
  647. }
  648. return $courses;
  649. }
  650. public function submitAnnualPlan()
  651. {
  652. $annual_plan_id = Input::get('annual_plan_id');
  653. DB::table('annual_plans')->where('id', $annual_plan_id)->update(array(
  654. 'is_submitted' => 1,
  655. 'submitted_on' => date('Y-m-d H:i:s')
  656. ));
  657. return;
  658. }
  659. public function futureTransformative()
  660. {
  661. $at_text = Input::get('at_text');
  662. $description = Input::get('description');
  663. $future_typ_course_id = Input::get('future_typ_course_id');
  664. $future_semesters = Input::get('future_semesters');
  665. $type_of_ta = Input::get('type_of_TA');
  666. $is_custom = Input::get('is_custom');
  667. $program_id = Input::get('program_id');
  668. //$annual_plan_id = Input::get('annual_plan_id');
  669. $objective_id = Input::get('objective_id');
  670. $course_code = Input::get('course_code');
  671. $course_number = Input::get('course_number');
  672. $newTransId = DB::table('transformative_actions')
  673. ->insertGetId(array(
  674. 'is_custom' => $is_custom,
  675. 'at_text' => $at_text,
  676. 'description' => $description,
  677. 'type_of_TA' => $type_of_ta,
  678. 'user_id' => Auth::user()->id,
  679. 'program_id' => $program_id,
  680. 'by_professor' => 0,
  681. 'created_at' => date('Y-m-d H:i:s'),
  682. 'updated_at' => date('Y-m-d H:i:s')
  683. ));
  684. DB::table('ta_course')->insert(array(
  685. 'ta_id' => $newTransId,
  686. 'course_number' => $course_number,
  687. 'course_code' => $course_code
  688. ));
  689. DB::table('transformative_objective')->insert(array(
  690. 'ta_id' => $newTransId,
  691. 'objective_id' => $objective_id
  692. ));
  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' => $newTransId,
  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. }
  711. public function fetchTheAnnualPlan()
  712. {
  713. $outcome_id = Input::get('id');
  714. $semester_id = Input::get('semester');
  715. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  716. $program_id = Input::get('program_id');
  717. $outcome = Outcome::find($outcome_id);
  718. //El nombre es annual_plan_objective, fue cambiado como mil veces por Arlene y su combo
  719. // Así que está mal escrito. Sorry future programmer
  720. $array_to_send = [];
  721. $array_to_send['typ_objectives'] = DB::table('typ_semester_objectives')
  722. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  723. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  724. ->select('objectives.*', 'typ_semester_outcome_id', 'typ_semester_objectives.id as typ_semester_objective_id')
  725. ->get();
  726. $array_to_send['typ_courses'] = DB::table('typ_semester_objectives')
  727. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  728. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  729. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  730. ->select('courses.*', 'typ_semester_objective_id', 'typ_semester_courses.id as typ_semester_course_id')
  731. ->get();
  732. $array_to_send['courses_criteria'] = DB::table('typ_semester_objectives')
  733. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  734. ->join('annual_plan_objective', 'annual_plan_objective.typ_semester_course_id', '=', 'typ_semester_courses.id')
  735. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  736. ->select('typ_semester_course_id', 'annual_plan_objective.*', 'criteria.*')
  737. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  738. ->groupBy('typ_semester_course_id')
  739. ->get();
  740. $array_to_send['courses_transformative_actions'] = DB::table('typ_semester_objectives')
  741. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  742. ->join('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  743. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  744. ->select('typ_semester_course_id', 'annual_plan_transformative.*', 'transformative_actions.*')
  745. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  746. ->groupBy('typ_semester_course_id')
  747. ->get();
  748. $array_to_send['transformative_outcome'] = DB::table('transformative_actions')
  749. ->join('transformative_typ_outcome', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  750. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  751. ->get();
  752. $array_to_send['expected_target'] = DB::table('target_outcomes_program')
  753. ->where('program_id', $program_id)
  754. ->where('semester_id', $semester_id)
  755. ->first();
  756. return $array_to_send;
  757. }
  758. public function addCommentsToOutcome()
  759. {
  760. $edit_id = Input::get('edit_id');
  761. $typ_semester_outcome_id = Input::get('typ_outcome_semester_id');
  762. $comments = Input::get('comments');
  763. Log::info(Input::all());
  764. if ($edit_id) {
  765. DB::table('typ_outcome_report_comments')
  766. ->where('id', $edit_id)->update(array(
  767. 'user_id' => Auth::user()->id,
  768. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  769. 'comments' => $comments
  770. ));
  771. } else {
  772. $edit_id = DB::table('typ_outcome_report_comments')->insertGetId(array(
  773. 'user_id' => Auth::user()->id,
  774. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  775. 'comments' => $comments
  776. ));
  777. }
  778. return $edit_id;
  779. }
  780. public function deleteCommentsFromOutcome()
  781. {
  782. $comment_id = Input::get('id');
  783. DB::table('typ_outcome_report_comments')->where('id', $comment_id)->delete();
  784. return;
  785. }
  786. }