Sin descripción

AnnualPlansController.php 64KB

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