Нет описания

AnnualPlansController.php 65KB

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