Nenhuma descrição

AnnualPlansController.php 71KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  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. // Log::info("Comments");
  634. Log::info('En AnnualPlansController antes'.json_encode($outcome->objectives)); //exit();
  635. unset($outcome->objectives);
  636. $outcome->objectives2 = $outcome->fetchObjectivesReport($semester_id, $program_id);
  637. Log::info("En AnnualPlansController".$semester_id." ". $program_id); //exit();
  638. Log::info('En AnnualPlansController'.json_encode($outcome->objectives2)); //exit();
  639. foreach ($outcome->objectives2 as $index => $objective) {
  640. // Log::info("Ella son besties");
  641. // Log::info(array($objective));
  642. $objective->courses = Objective::getPlanReport($objective);
  643. // $outcome->objectives[$index]->courses = Objective::getPlanReport($objective);
  644. }
  645. $outcome->outcome_program_goal = DB::table('target_outcomes_program')
  646. ->where('program_id', $program_id)
  647. ->where('semester_id', $semester_id)
  648. ->first();
  649. $outcome->transforming_actions = DB::table('transformative_typ_outcome')
  650. ->join('transformative_actions', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  651. ->leftJoin('transformative_action_status', 'transformative_actions.id', '=', 'transformative_action_status.trans_id')
  652. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  653. ->select('transformative_actions.*', 'transformative_action_status.*', 'transformative_actions.id as trans_id')
  654. ->get();
  655. $outcome->semester_info = DB::table('semesters')
  656. ->where('id', $semester_id)
  657. ->first();
  658. // Log::info($typ_semester_outcome_id);
  659. $outcome->comments = $outcome->getCommentsAttribute();
  660. // $outcome->comments = "COMMENT";
  661. //Log::info("Comments");
  662. //Log::info(DB::table('typ_outcome_report_comments')
  663. // ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  664. // ->toSql());
  665. //Log::info($outcome->comments);
  666. $outcome->transformative_actions_categories_html = TransformativeAction::getCategoriesHtml($program_id);
  667. // Log::info("Ella son besties".json_encode($outcome->objectives));
  668. // exit();
  669. return $outcome;
  670. }
  671. public function fetchObjectiveInfo()
  672. {
  673. $typ_objective_id = Input::get('typ_objective_id');
  674. $courses = DB::table('typ_semester_courses')
  675. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  676. ->select('courses.code', 'courses.number', 'courses.name', 'typ_semester_courses.id as typ_semester_course_id')
  677. ->where('typ_semester_objective_id', $typ_objective_id)
  678. ->distinct()
  679. ->get();
  680. foreach ($courses as $course) {
  681. /*$course->criteria_scale = DB::table('annual_plan_objective')
  682. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  683. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  684. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  685. ->select('criterion_scale.*', 'scales.*')
  686. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  687. ->orderBy('position', 'ASC')
  688. ->get();*/
  689. $course->criteria = DB::table('annual_plan_objective')
  690. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  691. ->where('typ_semester_course_id', $course->typ_semester_course_id)
  692. ->select('criteria.*')
  693. ->get();
  694. foreach ($course->criteria as $criterion) {
  695. $criterion->scales = DB::table('criteria')
  696. ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
  697. ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
  698. ->select('criterion_scale.*', 'scales.*')
  699. ->where('criteria.id', $criterion->id)
  700. ->orderBy('position', 'ASC')
  701. ->get();
  702. }
  703. }
  704. return $courses;
  705. }
  706. /* public function submitAnnualPlan()
  707. {
  708. $annual_plan_id = Input::get('annual_plan_id');
  709. DB::table('annual_plans')->where('id', $annual_plan_id)->update(array(
  710. 'is_submitted' => 1,
  711. 'submitted_on' => date('Y-m-d H:i:s')
  712. ));
  713. return;
  714. }*/
  715. public function futureTransformative()
  716. {
  717. $at_text = Input::get('at_text');
  718. $description = Input::get('description');
  719. $future_typ_course_id = Input::get('future_typ_course_id');
  720. $future_semesters = Input::get('future_semesters');
  721. $type_of_ta = Input::get('type_of_TA');
  722. $is_custom = Input::get('is_custom');
  723. $program_id = Input::get('program_id');
  724. //$annual_plan_id = Input::get('annual_plan_id');
  725. $objective_id = Input::get('objective_id');
  726. $course_code = Input::get('course_code');
  727. $course_number = Input::get('course_number');
  728. $edit_ta_id = Input::get('edit_ta_id');
  729. if ($edit_ta_id) {
  730. DB::table('transformative_actions')
  731. ->where('id', $edit_ta_id)->update(array(
  732. 'is_custom' => $is_custom,
  733. 'at_text' => $at_text,
  734. 'description' => $description,
  735. 'type_of_TA' => $type_of_ta,
  736. 'user_id' => Auth::user()->id,
  737. 'program_id' => $program_id,
  738. //'by_professor' => 0,
  739. //'created_at' => date('Y-m-d H:i:s'),
  740. 'updated_at' => date('Y-m-d H:i:s')
  741. ));
  742. DB::table('annual_plan_transformative')
  743. ->where('trans_id', $edit_ta_id)
  744. ->delete();
  745. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  746. $annual_plan = DB::table('annual_cycle')
  747. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  748. ->where('program_id', $program_id)
  749. ->where(function ($query) use (&$future_semesters, &$index) {
  750. $query->where('semester_start', $future_semesters[$index])
  751. ->orWhere('semester_end', $future_semesters[$index]);
  752. })->first();
  753. DB::table('annual_plan_transformative')
  754. ->insert(array(
  755. 'annual_plan_id' => $annual_plan->id,
  756. 'trans_id' => $edit_ta_id,
  757. 'typ_semester_course_id' => $typ_future_course_id,
  758. 'proposing_coordinator_id' => Auth::user()->id,
  759. 'proposed_date' => date('Y-m-d H:i:s')
  760. ));
  761. }
  762. $transformative_action = TransformativeAction::getTypCoursesWithSemesters($edit_ta_id);
  763. $transformative_action[0]->updated = 1;
  764. return $transformative_action;
  765. } else {
  766. $newTransId = DB::table('transformative_actions')
  767. ->insertGetId(array(
  768. 'is_custom' => $is_custom,
  769. 'at_text' => $at_text,
  770. 'description' => $description,
  771. 'type_of_TA' => $type_of_ta,
  772. 'user_id' => Auth::user()->id,
  773. 'program_id' => $program_id,
  774. 'by_professor' => 0,
  775. 'created_at' => date('Y-m-d H:i:s'),
  776. 'updated_at' => date('Y-m-d H:i:s')
  777. ));
  778. DB::table('ta_course')->insert(array(
  779. 'ta_id' => $newTransId,
  780. 'course_number' => $course_number,
  781. 'course_code' => $course_code
  782. ));
  783. DB::table('transformative_objective')->insert(array(
  784. 'ta_id' => $newTransId,
  785. 'objective_id' => $objective_id
  786. ));
  787. foreach ($future_typ_course_id as $index => $typ_future_course_id) {
  788. $annual_plan = DB::table('annual_cycle')
  789. ->join('annual_plans', 'annual_plans.annual_cycle_id', '=', 'annual_cycle.id')
  790. ->where('program_id', $program_id)
  791. ->where(function ($query) use (&$future_semesters, &$index) {
  792. $query->where('semester_start', $future_semesters[$index])
  793. ->orWhere('semester_end', $future_semesters[$index]);
  794. })->first();
  795. DB::table('annual_plan_transformative')
  796. ->insert(array(
  797. 'annual_plan_id' => $annual_plan->id,
  798. 'trans_id' => $newTransId,
  799. 'typ_semester_course_id' => $typ_future_course_id,
  800. 'proposing_coordinator_id' => Auth::user()->id,
  801. 'proposed_date' => date('Y-m-d H:i:s')
  802. ));
  803. }
  804. return TransformativeAction::getTypCoursesWithSemesters($newTransId);
  805. }
  806. }
  807. public function fetchTheAnnualPlan()
  808. {
  809. $outcome_id = Input::get('id');
  810. $semester_id = Input::get('semester');
  811. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  812. $program_id = Input::get('program_id');
  813. $outcome = Outcome::find($outcome_id);
  814. //El nombre es annual_plan_objective, fue cambiado como mil veces por Arlene y su combo
  815. // Así que está mal escrito. Sorry future programmer
  816. $array_to_send = [];
  817. $array_to_send['typ_objectives'] = DB::table('typ_semester_objectives')
  818. ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
  819. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  820. ->select('objectives.*', 'typ_semester_outcome_id', 'typ_semester_objectives.id as typ_semester_objective_id')
  821. ->get();
  822. $array_to_send['typ_courses'] = DB::table('typ_semester_objectives')
  823. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  824. ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
  825. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  826. ->select('courses.*', 'typ_semester_objective_id', 'typ_semester_courses.id as typ_semester_course_id')
  827. ->get();
  828. $array_to_send['courses_criteria'] = 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_objective', 'annual_plan_objective.typ_semester_course_id', '=', 'typ_semester_courses.id')
  831. ->join('criteria', 'criteria.id', '=', 'annual_plan_objective.criteria_id')
  832. ->select('typ_semester_course_id', 'annual_plan_objective.*', 'criteria.*')
  833. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  834. ->groupBy('typ_semester_course_id')
  835. ->get();
  836. $array_to_send['courses_transformative_actions'] = DB::table('typ_semester_objectives')
  837. ->join('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
  838. ->join('annual_plan_transformative', 'annual_plan_transformative.typ_semester_course_id', '=', 'typ_semester_courses.id')
  839. ->join('transformative_actions', 'transformative_actions.id', '=', 'annual_plan_transformative.trans_id')
  840. ->select('typ_semester_course_id', 'annual_plan_transformative.*', 'transformative_actions.*')
  841. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  842. ->groupBy('typ_semester_course_id')
  843. ->get();
  844. $array_to_send['transformative_outcome'] = DB::table('transformative_actions')
  845. ->join('transformative_typ_outcome', 'transformative_actions.id', '=', 'transformative_typ_outcome.trans_id')
  846. ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
  847. ->get();
  848. $array_to_send['expected_target'] = DB::table('target_outcomes_program')
  849. ->where('program_id', $program_id)
  850. ->where('semester_id', $semester_id)
  851. ->first();
  852. return $array_to_send;
  853. }
  854. public function addCommentsToOutcome()
  855. {
  856. $edit_id = Input::get('edit_id');
  857. $typ_semester_outcome_id = Input::get('typ_outcome_semester_id');
  858. $comments = Input::get('comments');
  859. // Log::info(Input::all());
  860. if ($edit_id) {
  861. DB::table('typ_outcome_report_comments')
  862. ->where('id', $edit_id)->update(array(
  863. 'user_id' => Auth::user()->id,
  864. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  865. 'comments' => $comments
  866. ));
  867. } else {
  868. $edit_id = DB::table('typ_outcome_report_comments')->insertGetId(array(
  869. 'user_id' => Auth::user()->id,
  870. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  871. 'comments' => $comments
  872. ));
  873. }
  874. return $edit_id;
  875. }
  876. public function deleteCommentsFromOutcome()
  877. {
  878. $comment_id = Input::get('id');
  879. DB::table('typ_outcome_report_comments')->where('id', $comment_id)->delete();
  880. return;
  881. }
  882. //Print annual report
  883. public function printAnnualReport($annual_id = null, $submit = null)
  884. {
  885. //$download = 0;
  886. $annualPlan = AnnualPlan::find($annual_id);
  887. //$pdf = new PDF();
  888. /*$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  889. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan', 'download'))
  890. ->setOrientation("landscape")
  891. ->setPaper('legal', 'landscape');
  892. $pdf->save(app_path() . '/storage/annual_pdfs/' . date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  893. return $pdf->download(date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf');
  894. */ //pdf = $pdf->setOrientation("landscape");
  895. // Log::info("submit");
  896. // Log::info($submit);
  897. return View::make('local.managers.shared.print_annual_report', compact('annualPlan', 'submit'));
  898. }
  899. public function postAnnualReport($annual_id)
  900. {
  901. $annualPlan = AnnualPlan::findOrFail($annual_id);
  902. $user_id = Auth::user()->id;
  903. //$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  904. //$pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  905. // ->setOrientation("landscape")
  906. // ->setPaper('legal', 'landscape');
  907. $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';
  908. //$pdf->save($path);
  909. //$name = date('d-m-Y') . '-for-' . $annualPlan->program->id . '.pdf';
  910. //$pdf->download($name);
  911. //is a path already there
  912. $it_exists = DB::table("paths_for_annual_plans")
  913. ->where('path_to_pdf', $path)
  914. ->first();
  915. if (isset($it_exists)) {
  916. return '200';
  917. }
  918. //$user_id = Auth::user()->id;
  919. DB::table("paths_for_annual_plans")
  920. ->where('annual_plan_id', $annual_id)
  921. ->where('user_id', $user_id)
  922. ->where('report', 1)
  923. ->update(array(
  924. 'last' => 0
  925. ));
  926. DB::table('paths_for_annual_plans')->insert(array(
  927. "path_to_pdf" => $path,
  928. 'annual_plan_id' => $annual_id,
  929. 'last' => 1,
  930. 'report' => 1,
  931. 'user_id' => $user_id,
  932. 'date_posted' => date('Y-m-d')
  933. ));
  934. return '200';
  935. }
  936. public function annualPlansShow($annual_report_or_plan, $program_id)
  937. {
  938. $role = Auth::user()->role;
  939. switch ($role) {
  940. case 1:
  941. case 2:
  942. case 3:
  943. $last = [1, 0];
  944. break;
  945. case 4:
  946. $last = [1];
  947. break;
  948. default:
  949. App::abort('404');
  950. }
  951. if ($annual_report_or_plan == "report") {
  952. $report = 1;
  953. } else if ($annual_report_or_plan == "plan") {
  954. $report = 0;
  955. } else {
  956. App::abort('404');
  957. }
  958. $title = "Annual Plans for " . Program::findOrFail($program_id)->name;
  959. $paths_with_users = DB::table('paths_for_annual_plans')
  960. ->join('annual_plans', 'annual_plans.id', '=', 'paths_for_annual_plans.annual_plan_id')
  961. ->join('annual_cycle', 'annual_cycle.id', '=', 'annual_plans.annual_cycle_id')
  962. ->join('users', 'users.id', '=', 'paths_for_annual_plans.user_id')
  963. ->where('report', $report)
  964. ->whereIn('last', $last)
  965. ->where('annual_plans.program_id', $program_id)
  966. ->orderBy('date_posted', 'desc')
  967. ->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')
  968. ->get();
  969. return View::make('local.managers.shared.new_view_annual_plans', compact('paths_with_users', 'title', 'report', 'last', 'annual_report_or_plan', 'program_id'));
  970. }
  971. public function findHTML($type_of_annual, $path_id)
  972. {
  973. $path = DB::table('paths_for_annual_plans')->where('id', $path_id)->first();
  974. if (isset($path)) {
  975. // Log::info($path->path_to_pdf);
  976. // Log::info(app_path()); //. "/views/annual_htmls/");
  977. //FALTA COMO HACER PAl REPORT.
  978. // Este problema esta bien algarete. So si le doy str_replace(app_path() . '/views/annual_htmls/'),
  979. // si yo añado '/' al substring "htmls/" , me borra '/pla'. For no reason.
  980. // so el plan, no se.
  981. //
  982. //
  983. //$path = str_replace(app_path() . '/views/annual_htmls/', '', $path->path_to_pdf);
  984. //$path = trim($path->path_to_pdf, app_path() . '/views/annual_');
  985. //$path = trim($path, "htmls");
  986. //$path = trim($path, '/'); //. "/views/annual_htmls/");
  987. //Log::info($path);
  988. //aqui tambien pasa una loquera
  989. $path = str_replace(app_path() . '/views/annual_htmls/', '', $path->path_to_pdf);
  990. $path = trim($path, ".blade.php");
  991. $dir = '';
  992. if ($type_of_annual == "plan") {
  993. $dir = 'annual_htmls.pla';
  994. } else {
  995. $dir = "annual_htmls.";
  996. }
  997. return View::make($dir . $path);
  998. }
  999. Session::flash('status', 'warning');
  1000. Session::flash('message', 'Error loading Annual Plan. Please try again later.');
  1001. return Redirect::back();
  1002. }
  1003. public function downloadPDF($download, $path_id)
  1004. {
  1005. $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  1006. $queryToPath = DB::table('paths_for_annual_plans')
  1007. ->where('id', $path_id)
  1008. ->first();
  1009. //Log::info("ERES TU? creo que no");
  1010. $path = storage_path($queryToPath->path_to_pdf);
  1011. if ($download != "download") {
  1012. return Response::make(file_get_contents($queryToPath->path_to_pdf), 200, [
  1013. 'Content-type' => 'application/pdf',
  1014. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  1015. ]);
  1016. } else {
  1017. return Response::download(
  1018. file_get_contents($queryToPath->path_to_pdf),
  1019. 200,
  1020. [
  1021. 'Content-type' => 'application/pdf',
  1022. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  1023. ]
  1024. );
  1025. }
  1026. /*
  1027. [
  1028. 'Content-type' => 'application/pdf',
  1029. 'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
  1030. ]
  1031. */
  1032. $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
  1033. // Log::info("ERES TU?");
  1034. //return View::make('local.managers.shared.print_annual_report', compact('annualPlan'));
  1035. $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
  1036. ->setOrientation("landscape")
  1037. ->setPaper('legal', 'landscape');
  1038. if ($download == "download")
  1039. return $pdf->download(basename($queryToPath->path_to_pdf));
  1040. else
  1041. return $pdf->stream(basename($queryToPath->path_to_pdf));
  1042. }
  1043. public function checkIfPlanReady()
  1044. {
  1045. $annual_plan = AnnualPlan::findOrFail(Input::get("annual_id"));
  1046. // Log::info('annual_plan' . $annual_plan->courses);
  1047. /*
  1048. error = [
  1049. [
  1050. outcome, objective, course
  1051. ]
  1052. ]
  1053. */
  1054. $error_array = [];
  1055. // Log::info("Esto devuelve?");
  1056. // Log::info($annual_plan->courses);
  1057. foreach ($annual_plan->courses as $index => $course) {
  1058. // Log::info('paired Criteria');
  1059. // Log::info($course->paired_criteria);
  1060. if (count($course->paired_criteria) <= 0) {
  1061. $outcome = $course->paired_objective->paired_outcome;
  1062. $objective = $course->paired_objective;
  1063. $array_to_be_appended = [
  1064. "outcome_name" => $outcome->name,
  1065. "objective_text" => $objective->text,
  1066. "course_code" => $course->code . '-' . $course->number,
  1067. 'typ_semester_course_id' => $course->typ_semester_course_id,
  1068. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  1069. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id
  1070. ];
  1071. $error_array[] = $array_to_be_appended;
  1072. }
  1073. }
  1074. return $error_array;
  1075. }
  1076. public function checkIfReady()
  1077. {
  1078. $annual_plan = AnnualPlan::find(Input::get('annual_id'));
  1079. /*Error message schema
  1080. courses_where_missing_data = [
  1081. course_1=>[
  1082. info, info
  1083. objective => {
  1084. typ_semester_objective_id,
  1085. objective_text
  1086. }
  1087. outcome => {
  1088. typ_semester_outcome_id,
  1089. outcome_name
  1090. }
  1091. ]
  1092. ]
  1093. */
  1094. $courses_where_missing_data = [
  1095. 'courses' => [],
  1096. 'outcomes' => []
  1097. ];
  1098. // Log::info($annual_plan->courses_with_transformative_actions);
  1099. foreach ($annual_plan->courses_with_transformative_actions as $course) {
  1100. foreach ($course->proposed_transformative_actions as $ta) {
  1101. if (!isset($ta->status)) {
  1102. $objective = $course->paired_objective;
  1103. $objective_info = [
  1104. 'typ_semester_objective_id' => $objective->typ_semester_objective_id,
  1105. 'text' => $objective->text
  1106. ];
  1107. $outcome = $objective->paired_outcome;
  1108. $outcome_info = [
  1109. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  1110. 'name' => $outcome->name
  1111. ];
  1112. $array_to_be_appended = [
  1113. 'course_name' => $course->code . '-' . $course->number,
  1114. 'objective' => $objective_info,
  1115. 'outcome' => $outcome_info,
  1116. 'transformative_action_title' => $ta->at_text,
  1117. 'transformative_action_description' => $ta->description,
  1118. 'typ_semester_course_id' => $course->typ_semester_course_id
  1119. ];
  1120. $courses_where_missing_data['courses'][] = $array_to_be_appended;
  1121. }
  1122. }
  1123. }
  1124. foreach ($annual_plan->outcomes as $outcome) {
  1125. foreach ($outcome->program_transformative_actions as $ta) {
  1126. if (!isset($ta->status)) {
  1127. $array_to_be_appended = [
  1128. 'typ_semester_outcome_id' => $outcome->typ_semester_outcome_id,
  1129. 'outcome_name' => $outcome->name,
  1130. 'transformative_action_title' => $ta->at_text,
  1131. 'transformative_action_description' => $ta->description
  1132. ];
  1133. $courses_where_missing_data['outcomes'][] = $array_to_be_appended;
  1134. }
  1135. }
  1136. }
  1137. return $courses_where_missing_data;
  1138. }
  1139. public function printAnnualPlan($annual_id, $submit = null)
  1140. {
  1141. $alphabet = range("A", "Z");
  1142. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1143. Log::info(json_encode($annualPlan));
  1144. $temp = $annualPlan->getCoursesAttribute();
  1145. Log::info("cursos plan");
  1146. Log::info(json_encode($temp));
  1147. Log::info("termina cursos plan");
  1148. $small_alphabet = range('a', 'z');
  1149. return View::make('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet', 'submit'));
  1150. }
  1151. public function submitAnnualPlan($annual_id)
  1152. {
  1153. $alphabet = range("A", "Z");
  1154. $small_alphabet = range('a', 'z');
  1155. $annualPlan = AnnualPlan::findOrFail($annual_id);
  1156. // Log::info(json_encode($annualPlan));
  1157. // Log::info($annualPlan->annual_cycle_id);
  1158. $user_id = Auth::user()->id;
  1159. //$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/plan_pdf');
  1160. //$pdf = $pdf->loadView('local.managers.shared.print_annual_plan', compact('annualPlan', 'alphabet', 'small_alphabet'))
  1161. // ->setOrientation("landscape")
  1162. // ->setPaper('legal', 'landscape');
  1163. $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';
  1164. //$pdf->save($path);
  1165. $name = "plan-on-" . date('d-m-Y') . 'ac' . $annualPlan->annual_cycle_id . '-for-' . $annualPlan->program->id . '.blade.php';
  1166. //$pdf->download($name);
  1167. //is a path already there
  1168. $submit = 1;
  1169. $it_exists = DB::table("paths_for_annual_plans")
  1170. ->where('path_to_pdf', $path)
  1171. ->first();
  1172. // Log::info(
  1173. if (isset($it_exists)) {
  1174. return '200';
  1175. }
  1176. DB::table("paths_for_annual_plans")
  1177. ->where('annual_plan_id', $annual_id)
  1178. ->where('report', 0)
  1179. ->where('user_id', $user_id)
  1180. ->update(array(
  1181. 'last' => 0
  1182. ));
  1183. DB::table('annual_plans')
  1184. ->where('id', $annual_id)
  1185. ->update(array(
  1186. 'is_submitted' => 1,
  1187. 'submitted_on' => date('Y-m-d H:i:s')
  1188. ));
  1189. DB::table('paths_for_annual_plans')->insert(array(
  1190. "path_to_pdf" => $path,
  1191. 'annual_plan_id' => $annual_id,
  1192. 'last' => 1,
  1193. 'report' => 0,
  1194. 'user_id' => $user_id,
  1195. 'date_posted' => date('Y-m-d')
  1196. ));
  1197. return '200';
  1198. }
  1199. //feature de import rubric
  1200. function fetchTemplatesForCriteria()
  1201. {
  1202. $outcome_id = Input::get("outcome_id");
  1203. $objective_id = Input::get('objective_id');
  1204. $program_id = Input::get("program_id");
  1205. $program = Program::find($program_id);
  1206. $criteria_list = DB::table("program_criterion_objective_outcome as poco")
  1207. ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'poco.cri_obj_out_id')
  1208. ->where('program_id', $program_id)
  1209. ->where('objective_id', $objective_id)
  1210. ->where('outcome_id', $outcome_id)
  1211. ->lists('criterion_id');
  1212. $templates = Template::join('template_criterion', 'templates.id', '=', 'template_criterion.template_id')
  1213. //where are available for this program
  1214. ->where(function ($q) use ($program) {
  1215. //donde sean rubricas de mi programa
  1216. $q->where(function ($q2) use ($program) {
  1217. $q2->where('school_id', $program->school->id)
  1218. ->where('program_id', $program->id);
  1219. })
  1220. //o sean exclusivamente de toda la escuela
  1221. ->orWhere(function ($q2) use ($program) {
  1222. $q2->where('school_id', $program->school->id)
  1223. ->whereNull('program_id');
  1224. })
  1225. //o de todos
  1226. ->orWhereNull("school_id");
  1227. })
  1228. ->whereIn('template_criterion.criterion_id', $criteria_list)
  1229. ->groupBy('templates.id')
  1230. ->select('templates.*')
  1231. ->get();
  1232. return $templates;
  1233. }
  1234. public function pairCriteriaFromTemplate()
  1235. {
  1236. $typ_objective_id = Input::get('typ_objective_id');
  1237. $template_id = Input::get("template_id");
  1238. $objective_id = Input::get('objective_id');
  1239. $program_id = Input::get('program_id');
  1240. $outcome_id = Input::get("outcome_id");
  1241. $annual_plan = Input::get('annual_plan');
  1242. $list_criterion = DB::table('template_criterion')
  1243. ->join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'template_criterion.criterion_id')
  1244. ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
  1245. ->where('program_id', $program_id)
  1246. ->where('cobo.outcome_id', $outcome_id)
  1247. ->where('cobo.objective_id', $objective_id)
  1248. ->where('template_id', $template_id)
  1249. ->groupBy('cobo.criterion_id')
  1250. ->select('cobo.criterion_id')
  1251. ->lists('criterion_id');
  1252. Log::info($list_criterion);
  1253. $courses = DB::table('typ_semester_courses')
  1254. ->where('typ_semester_objective_id', $typ_objective_id)
  1255. ->lists('id');
  1256. Log::info($courses);
  1257. //$insertable_array = [];
  1258. foreach ($list_criterion as $index => $criterion_id) {
  1259. foreach ($courses as $ind => $typ_course_id) {
  1260. $existing = DB::table("annual_plan_objective")
  1261. ->where('criteria_id', $criterion_id)
  1262. ->where('annual_plan_id', $annual_plan)
  1263. ->where('typ_semester_course_id', $typ_course_id)
  1264. ->first();
  1265. if (isset($existing)) {
  1266. Log::info('existe');
  1267. Log::info(array($existing));
  1268. continue;
  1269. }
  1270. DB::table('annual_plan_objective')
  1271. ->insert(array(
  1272. 'criteria_id' => $criterion_id,
  1273. 'annual_plan_id' => $annual_plan,
  1274. 'typ_semester_course_id' => $typ_course_id
  1275. ));
  1276. }
  1277. }
  1278. return 200;
  1279. }
  1280. function fetchOutcomesFromPlan()
  1281. {
  1282. $annual_plan = Input::get('annual_plan_id');
  1283. $annual_plan = AnnualPlan::where('id', $annual_plan)->first();
  1284. return $annual_plan->outcomes;
  1285. }
  1286. function fetchObjectivesFromPlan()
  1287. {
  1288. $program_id = Input::get('program_id');
  1289. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  1290. $outcome_id = Input::get('outcome_id');
  1291. $semester_id = Input::get("semester_id");
  1292. $outcome = Outcome::where('id', $outcome_id)
  1293. ->select('outcomes.*', DB::raw("{$semester_id} as semester_id, {$typ_semester_outcome_id} as typ_semester_outcome_id, {$program_id} as program_id"))
  1294. ->first();
  1295. Log::info(array($outcome));
  1296. return $outcome->annual_objectives;
  1297. }
  1298. function fetchSemestersFromPlan()
  1299. {
  1300. $annual_plan = Input::get('annual_plan_id');
  1301. $annual_plan = AnnualPlan::where('id', $annual_plan)->first();
  1302. return $annual_plan->semesters;
  1303. }
  1304. function fetchCoursesFromPlanForTemplate()
  1305. {
  1306. $annual_plan = Input::get('annual_plan_id');
  1307. $semester = Input::get('semester_id');
  1308. $annual_plan = AnnualPlan::select('annual_plans.*', DB::raw("{$semester} as for_template"))
  1309. ->where('id', $annual_plan)->first();
  1310. return $annual_plan->courses;
  1311. }
  1312. function fetchCriteriaFromPlan()
  1313. {
  1314. $course_id = Input::get('course_id');
  1315. $annual_plan_id = Input::get('annual_plan');
  1316. $max_score = Input::get('max_score');
  1317. $number_of_scales = Input::get('number_of_scales');
  1318. $criteria = DB::table('criteria')
  1319. ->join('annual_plan_objective', 'annual_plan_objective.criteria_id', '=', 'criteria.id')
  1320. ->join('typ_semester_courses', 'typ_semester_course_id', '=', 'typ_semester_courses.id')
  1321. ->where('typ_semester_courses.course_id', $course_id)
  1322. ->where('annual_plan_objective.annual_plan_id', $annual_plan_id)
  1323. ->where('criteria.max_score', $max_score)
  1324. ->where('criteria.num_scales', $number_of_scales)
  1325. ->groupBy('criteria.id')
  1326. ->select('criteria.*')
  1327. ->get();
  1328. return $criteria;
  1329. }
  1330. }