1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159 |
- <?php
-
- use Illuminate\Database\Eloquent\Collection;
- use Barryvdh\DomPDF\PDF as PDF;
- use Illuminate\Support\Facades\View;
-
- class ThreeYearPlanController extends \BaseController
- {
-
- public function create()
- {
- try {
- DB::beginTransaction();
- $yearStart = Input::get('years') + 0;
- $yearEnd = $yearStart + 3;
- $program_id = Input::get('program_id');
- DB::insert("insert into three_year_plan (`year_start`, `year_end`) values ({$yearStart}, {$yearEnd})");
-
- $typ = DB::table('three_year_plan')->where('year_start', '=', $yearStart)
- ->where('year_end', '=', $yearEnd)
- ->first();
- for ($i = $yearStart; $i < $yearEnd; $i++) {
- $string = 'First Semester ' . $i . '-' . ($i + 1);
- $string2 = 'Second Semester ' . $i . '-' . ($i + 1);
-
- $Firstsemester = DB::table('semesters')->where('name', '=', $string)->first();
- $secondSemester = DB::table('semesters')->where('name', '=', $string2)->first();
- Log::info($Firstsemester->id);
- Log::info($secondSemester->id);
- Log::info($typ->id);
- DB::insert("insert into typ_semesters (typ_id, semester_id) values ({$typ->id}, {$Firstsemester->id}), ({$typ->id}, {$secondSemester->id})");
- }
- DB::commit();
- Session::flash('status', 'success');
- Session::flash('message', '<p> Cycle created.</p>');
- return Redirect::to("three-years-plan/{$program_id}");
- } catch (Exception $e) {
- Session::flash('status', 'danger');
- Session::flash('message', "<p>Could not create cycle</p>");
- Log::info($e);
- DB::rollback();
- return Redirect::to("three-years-plan/{$program_id}");
- }
- }
- public function adminIndex()
- {
- Log::info("Entre" . json_encode($this));
-
- $title = "Three Years Plans";
- $programs = Program::orderBy('name', "ASC")->get();
- $typ = DB::table("three_year_plan")
- ->orderBy('year_start', "DESC")
- ->get();
-
- return View::make('local.managers.admins.show-typ-program', compact('title', 'programs', 'typ'));
- }
-
- public function fetchSubmitted()
- {
- $typ = Input::get('typ');
-
- return DB::table('typ_program')
-
-
- ->where('three_year_plan_id', $typ)
- ->get();
- }
-
- public function manageSemesterCycle()
- {
- // Log::info("Entre".json_encode($this));
-
- $title = "Semesters Cycles";
- // $programs = Program::get();
-
- return $this->adminIndex();
- // return View::make('local.managers.admins.show-typ-program', compact('title', 'programs'));
- }
-
- //submit
-
- public function submit($program_id)
- {
- $typ_id = Input::get('typ_id');
- $rows = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->update(array(
- "is_submitted" => 1
- ));
-
- if (isset($rows)) {
- return "estamos ready";
- } else {
- return 500;
- }
- }
-
- //busca los links de public y los loadea
- public function findHTML($path_id)
- {
-
- $path = DB::table('paths_for_three_year_plans')->where('id', $path_id)->first();
-
- if (isset($path)) {
-
- $path = trim($path->path_to_pdf, app_path() . "/views/three_year_plan_htmls/");
- $path = trim($path, ".blade.php");
- return View::make("three_year_plan_htmls." . $path);
- }
- Session::flash('status', 'warning');
- Session::flash('message', 'Error loading typ. Please try again later.');
- return Redirect::back();
- }
- // load the Three year Plan page
- public function threeYearsReport($program_id)
- {
- $user_id = Auth::user()->id;
-
- $last_year = DB::table('three_year_plan')->select('year_end')
- ->orderBy('year_end', 'desc')->first();
- if (!$last_year) {
- // $last_year = date('Y');
- $last_year = 2019;
- } else {
- $last_year = $last_year->year_end;
- }
-
- $program = Program::find($program_id);
- Log::info($program);
-
- // el ID de los semestres que el usuario tiene seleccionado.
- $semesters_ids = Session::get('semesters_ids');
- // buscar informacion de los semestres seleccionados
- $semesters = Semester::whereIn('id', $semesters_ids)->get();
-
- $title = "Three Year Plan for " . $program->name;
- $typs = DB::table('three_year_plan')
- ->orderBy('year_start', 'asc')
- ->get();
- $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
- /* $program_id = DB::table('program_user')
- ->where('user_id', $user_id)
- ->select('program_id')
- ->get();
- $program_id = $program_id[0]->program_id;*/
- if ($program->is_graduate == 0) {
- $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->orderBy('name', 'ASC')->get();
- } else {
- $outcomes = DB::table('outcomes')->where('deactivation_date', '=', null)->where('level', '=', 3)->orderBy('name', 'ASC')->get();
- }
-
- // se annadio la nueva variable
- return View::make('global.view-three-year-plan', compact('title', 'last_year', 'outcomes', 'typs', 'criteria', 'semesters', 'program_id'));
- }
-
-
- //when the user select a three year period from the left column, load the corresponding info
- public function fetchThreeYears()
- {
- $id = Input::get('id');
-
- $semesters = DB::table('typ_semesters')
- ->join('semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
- ->where('typ_semesters.typ_id', $id)
- ->orderBy('typ_semesters.semester_id', 'asc')
- ->get();
- $typs = DB::table('three_year_plan')
- ->where('id', $id)
- ->orderBy('year_start', 'asc')
- ->get();
-
- $typs = $typs[0];
- $typs->semesters = $semesters;
-
- return array(
- 'typ' => $typs,
- );
- }
-
- // add or remove a semester associated with an outcome when a user selects a checkbox
- public function update_typ_outcomes_semesters()
- {
- $outcomeSemesterArray = json_decode(Input::get('outcomeSemesterArray'), true);
- $typ_id = Input::get('typ_id');
-
- $user_id = auth::user()->id;
- $program_id = Input::get('program_id');
-
-
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
-
- // create the relation if it doesnt exist
- if (count($result) == 0) {
- $typ_program_id = DB::table('typ_program')->insertGetId(
- array(
- 'three_year_plan_id' => $typ_id,
- 'program_id' => $program_id
- )
- );
- } else {
- $typ_program_id = $result[0]->id;
- }
-
-
-
- //go through array
- foreach ($outcomeSemesterArray as $outcome_semester) {
-
- // foreach of the 6 semesters
- foreach ($outcome_semester["semesters"] as $semester) {
- $insert = $semester[1];
-
- $outcome_id = explode("-sem", $semester[0])[0];
-
- $semester_code = explode("-sem", $semester[0])[1];
- $result = DB::table('semesters')
- ->where('code', $semester_code)
- ->select('id')
- ->get();
- if (count($result) == 0) {
- continue;
- }
- $semester_id = $result[0]->id;
-
- // verify if it exists
- $result = DB::table('typ_semester_outcome')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester_id)
- ->where('outcome_id', $outcome_id)
- ->get();
-
- // if true, it should get inserted
- if ($insert == true) {
- // if == 0, then insert
- if (count($result) == 0) {
- $_ = DB::table('typ_semester_outcome')->insertGetId(
- array(
- 'typ_program_id' => $typ_program_id,
- 'semester_id' => $semester_id,
- 'outcome_id' => $outcome_id
- )
- );
- }
- //if exists, then do nothing
-
- }
- // if false, it should get deleted
- else { //value == false
-
- // if == 0, it doesnt exist. we do nothing
- if (count($result) == 0) {
- //pass
- }
- //if exists, then do nothing
- else {
- DB::table('typ_semester_outcome')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester_id)
- ->where('outcome_id', $outcome_id)
- ->delete();
- }
- }
- }
- }
- return;
- }
-
- // load semesters asociated with the outcomes if previously selected
- public function lookup_typ_semester_outcome()
- {
- $box_value = array();
-
- $info = Input::get('info');
-
- foreach ($info as $values) {
- $outcome_id = $values[0];
- $semester_code = $values[1];
- $program_id = $values[2];
- $box_id = $values[3];
- $typ_id = $values[4];
-
- //buscar id del typ
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
- $typ_program_id = $result[0]->id;
-
- // buscar si existe el outcome_semester
- $result = DB::table('typ_semester_outcome')
- ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
- ->where('typ_program_id', $typ_program_id)
- ->where('semesters.code', $semester_code)
- ->where('outcome_id', $outcome_id)
- ->get();
-
- // if it doesnt exist
- if (count($result) == 0) {
- array_push($box_value, array($box_id, 0));
- } else {
- array_push($box_value, array($box_id, 1));
- }
- }
- return array(
- 'box_value' => ($box_value)
- );
- }
-
- // save or delete Objectives associated with the outcomes and semsters
- public function section2_on_change()
- {
- $typ_id = Input::get('typ_id');
- $outcome_id = Input::get('outcome_id');
- $semester_id = Input::get('semester_id');
- $previous_objective_id = Input::get('previous_objective_id');
- $new_objective_id = Input::get('new_objective_id');
- $program_id = Input::get('program_id');
-
- // get program_id
- //$user_id = auth::user()->id;
- //Log::info(Input::all());
-
- // get typ_program_id
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
- $typ_program_id = $result[0]->id;
-
- // get typ_semester_outcome_id
- $result = DB::table('typ_semester_outcome')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester_id)
- ->where('outcome_id', $outcome_id)
- ->get();
- $typ_semester_outcome_id = $result[0]->id;
-
- //delete old objective relation if it exists
- if ($previous_objective_id != 'nothing_selected') {
- $result = DB::table('typ_semester_objectives')
- ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
- ->where('objective_id', $previous_objective_id)
- ->get();
- if (count($result) != 0) {
- DB::table('typ_semester_objectives')
- ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
- ->where('objective_id', $previous_objective_id)
- ->delete();
- }
- }
-
- //create new objective relation
- if ($new_objective_id != 'nothing_selected') {
- $result = DB::table('typ_semester_objectives')
- ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
- ->where('objective_id', $new_objective_id)
- ->get();
- if (count($result) == 0) {
- $_ = DB::table('typ_semester_objectives')->insertGetId(
- array(
- 'typ_semester_outcome_id' => $typ_semester_outcome_id,
- 'objective_id' => $new_objective_id
- )
- );
- }
- }
- return 'update was succes';
- }
-
- // load the corresponding info after associating semesters with outcomes
- public function section2_arrive()
- {
- // get program_id
- $user_id = auth::user()->id;
- $program_id = Input::get('program_id');
-
- // get typ_program_id
- $typ_id = Input::get('typ_id');
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
- $typ_program_id = $result[0]->id;
-
-
- //search selected outcomes,semesters and get their objectives
- $selected_outcomes = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
- ->distinct('typ_semester_outcome.outcome_id')
- ->select('typ_semester_outcome.outcome_id')
- ->orderBy('outcomes.name', 'asc')
- ->get();
-
- $selected_objectives_array = array();
- $outcomes_info_array = array();
- // $objectives_info_array = array();
- $semesters_array = array();
-
- $info = array();
- foreach ($selected_outcomes as $outcome) {
-
-
- $outcome_id = $outcome->outcome_id;
- $result_outcomes = DB::table('outcomes')
- ->where('outcomes.id', $outcome_id)
- ->orderBy('outcomes.name', 'asc')
- ->get();
-
- foreach ($result_outcomes as $outcome_) {
-
- $result_semesters = DB::table('typ_semester_outcome')
- ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
- ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
- ->where('typ_semester_outcome.outcome_id', $outcome_->id)
- ->select('typ_semester_outcome.id', 'typ_semester_outcome.semester_id', 'semesters.code', 'semesters.name')
- ->orderBy('semesters.code')
- ->get();
- // buscar info sobre selected_semsters
- $outcome_->selected_semesters = array();
- foreach ($result_semesters as $semesters_) {
- $typ_semester_outcome_id = $semesters_->id;
-
- // lookup previusly selected objectives
- $result_objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
- ->orderBy('typ_semester_objectives.id', 'asc')
- ->get();
-
- $semesters_->selected_objectives = array();
- foreach ($result_objectives as $objectives_) {
-
- array_push($semesters_->selected_objectives, $objectives_);
- }
-
- // lookup available objectives
- $result_objectives = DB::table('objective_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
- ->join('objectives', 'objectives.id', '=', 'objective_outcome.objective_id')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->where('objective_program.program_id', $program_id)
- ->where('objective_outcome.outcome_id', $outcome_id)
- ->where('objective_outcome.objective_id', "<>", 0)
- ->select('objectives.id', 'objectives.text', 'outcomes.name as outcome_name')
- ->orderBy('objectives.text', 'asc')
- ->get();
-
- $semesters_->available_objectives = array();
- foreach ($result_objectives as $objectives_) {
-
- array_push($semesters_->available_objectives, $objectives_);
- }
-
- array_push($outcome_->selected_semesters, $semesters_);
- }
- array_push($info, $outcome_);
- }
- }
- return $info;
- }
-
- // load the corresponding info after associating objectives to semesters outcomes
- public function section3_arrive()
- {
- // get program_id
- $user_id = auth::user()->id;
- $program_id = Input::get('program_id');
-
- // get typ_program_id
- $typ_id = Input::get('typ_id');
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
- $typ_program_id = $result[0]->id;
-
-
- //search selected outcomes,semesters and get their objectives
- $selected_outcomes = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
- ->distinct('typ_semester_outcome.outcome_id')
- ->select('typ_semester_outcome.outcome_id')
- ->orderBy('outcomes.name', 'asc')
- ->get();
-
- $selected_objectives_array = array();
- $outcomes_info_array = array();
- // $objectives_info_array = array();
- $semesters_array = array();
-
- $info = array();
- foreach ($selected_outcomes as $outcome) {
-
-
- $outcome_id = $outcome->outcome_id;
- $result_outcomes = DB::table('outcomes')
- ->where('outcomes.id', $outcome_id)
- ->get();
-
- foreach ($result_outcomes as $outcome_) {
-
- $result_semesters = DB::table('typ_semester_outcome')
- ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
- ->where('typ_semester_outcome.typ_program_id', $typ_program_id)
- ->where('typ_semester_outcome.outcome_id', $outcome_->id)
- ->select('typ_semester_outcome.id', 'typ_semester_outcome.semester_id', 'semesters.code', 'semesters.name')
- ->orderBy('semesters.code')
- ->get();
- // buscar info sobre selected_semsters
- $outcome_->selected_semesters = array();
- foreach ($result_semesters as $semesters_) {
- $typ_semester_outcome_id = $semesters_->id;
- $result_objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome_id)
- ->select('typ_semester_objectives.id as typ_semester_objectives_id', 'objectives.*', 'typ_semester_objectives.*')
- ->orderBy('typ_semester_objectives.id', 'asc')
- ->get();
-
- $semesters_->selected_objectives = array();
- foreach ($result_objectives as $objectives_) {
- // $result_courses = DB::table('courses')
- // ->where('courses.program_id', $program_id)
- // ->select('courses.id as course_id', 'courses.name', 'courses.code', 'courses.number', 'courses.program_id')
- // ->orderBy('courses.number', 'asc')
- // ->groupBy('courses.name', 'courses.code')
- // ->get();
-
- $result_courses = DB::table('courses')
- ->where('courses.program_id', $program_id)
- ->orWhereIn('courses.program_id', function ($q) use ($program_id) {
- $q->select('other_program_id')
- ->from('other_programs_courses_typ')
- ->where('program_id', $program_id);
- })
- ->select('courses.id as course_id', 'courses.name', 'courses.code', 'courses.number', 'courses.program_id')
- ->orderBy('courses.code', 'asc')
- ->orderBy('courses.number', 'asc')
- ->groupBy('courses.name', 'courses.code')
- ->get();
-
- #los cursos resultantes creo que deberian ser: todos los que se estan dando en mi programa
-
- $objectives_->available_courses = array();
- foreach ($result_courses as $courses_) {
- array_push($objectives_->available_courses, $courses_);
- }
-
- // search for previusly selected courses
- $typ_semester_objective_id = $objectives_->typ_semester_objectives_id;
- $result_courses = DB::table('typ_semester_courses')
- ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
- ->where('typ_semester_courses.typ_semester_objective_id', $typ_semester_objective_id)
- ->select('courses.id as course_id', 'courses.*', 'typ_semester_courses.*')
- ->orderBy('courses.name', 'asc')
- ->get();
-
- $objectives_->selected_courses = array();
- foreach ($result_courses as $courses_) {
- array_push($objectives_->selected_courses, $courses_);
- }
-
- array_push($semesters_->selected_objectives, $objectives_);
- }
-
- array_push($outcome_->selected_semesters, $semesters_);
- }
- array_push($info, $outcome_);
- }
- }
- return $info;
- }
-
- // save or delete courses associated with objectives
- public function section3_on_change()
- {
- $typ_id = Input::get('typ_id');
- $outcome_id = Input::get('outcome_id');
- $semester_id = Input::get('semester_id');
- $objective_id = Input::get('objective_id');
- $previous_course_id = Input::get('previous_course_id');
- $new_course_id = Input::get('new_course_id');
-
- // get program_id
- $program_id = Input::get('program_id');
-
- // get typ_program_id
- $result = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->get();
- $typ_program_id = $result[0]->id;
-
- // get typ_semester_outcome_id
- $result = DB::table('typ_semester_outcome')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester_id)
- ->where('outcome_id', $outcome_id)
- ->get();
- $typ_semester_outcome_id = $result[0]->id;
-
- // get typ_semester_objective_id
- $result = DB::table('typ_semester_objectives')
- ->where('typ_semester_outcome_id', $typ_semester_outcome_id)
- ->where('objective_id', $objective_id)
- ->get();
- $typ_semester_objective_id = $result[0]->id;
-
- //delete old objective relation if it exists
- if ($previous_course_id != 'nothing_selected') {
- $result = DB::table('typ_semester_courses')
- ->where('typ_semester_objective_id', $typ_semester_objective_id)
- ->where('course_id', $previous_course_id)
- ->get();
- if (count($result) != 0) {
- DB::table('typ_semester_courses')
- ->where('typ_semester_objective_id', $typ_semester_objective_id)
- ->where('course_id', $previous_course_id)
- ->delete();
- }
- }
-
- //create new objective relation
- if ($new_course_id != 'nothing_selected') {
- $result = DB::table('typ_semester_courses')
- ->where('typ_semester_objective_id', $typ_semester_objective_id)
- ->where('course_id', $new_course_id)
- ->get();
- if (count($result) == 0) {
- $_ = DB::table('typ_semester_courses')->insertGetId(
- array(
- 'typ_semester_objective_id' => $typ_semester_objective_id,
- 'course_id' => $new_course_id
- )
- );
- }
- }
- return 'update succes?';
- }
-
- public function verifyAndCreate($program_id)
- {
-
- $typ_id = Input::get("typ_id");
-
- $typ_program_id = DB::table('typ_program')
- ->where('three_year_plan_id', $typ_id)
- ->where('program_id', $program_id)
- ->first();
-
- $information_thats_missing = [];
-
- $objectives_missing = DB::table('typ_semester_outcome')
- ->leftJoin("typ_semester_objectives", 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
- ->join('semesters', 'semesters.id', '=', 'typ_semester_outcome.semester_id')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_program_id', $typ_program_id->id)
- ->whereNull('typ_semester_objectives.id')
- ->select('semesters.id as semester_id', 'semesters.name as semester_name', 'semesters.code', 'outcomes.name as outcome_name', 'outcomes.id as outcome_id')
- ->get();
-
- if (count($objectives_missing) != 0) {
-
- $objective_array = [];
-
- foreach ($objectives_missing as $ob) {
- if (!isset($objective_array[$ob->semester_id])) {
- $objective_array[$ob->semester_id] = array(
- 'semester_name' => $ob->semester_name . ' (' . $ob->code . ') ',
- 'outcome_text' => [],
-
- );
- }
- $objective_array[$ob->semester_id]['outcome_text'][] = $ob->outcome_name;
- }
-
- $information_thats_missing['objectives_missing'] = $objective_array;
- }
-
- $courses_missing = DB::table('typ_semester_outcome')
- ->join('typ_semester_objectives', 'typ_semester_objectives.typ_semester_outcome_id', '=', 'typ_semester_outcome.id')
- ->leftJoin('typ_semester_courses', 'typ_semester_courses.typ_semester_objective_id', '=', 'typ_semester_objectives.id')
- ->join('objectives', 'typ_semester_objectives.objective_id', '=', 'objectives.id')
- ->join('outcomes', 'typ_semester_outcome.outcome_id', '=', 'outcomes.id')
- ->join('semesters', 'typ_semester_outcome.semester_id', '=', 'semesters.id')
-
- ->where('typ_program_id', $typ_program_id->id)
- ->whereNull('typ_semester_courses.id')
- ->select('objectives.id as objective_id', 'objectives.text as objective_text')
- ->addSelect('outcomes.id as outcome_id', 'outcomes.name as outcome_name')
- ->addSelect('semesters.id as semester_id', 'semesters.name as semester_name', 'semesters.code as semester_code')
- ->get();
-
- if (count($courses_missing) != 0) {
-
- $courses_array = [];
-
- foreach ($courses_missing as $co) {
- if (!isset($courses_array[$co->semester_id])) {
- $courses_array[$co->semester_id] = array(
- 'semester_name' => $co->semester_name . ' (' . $co->semester_code . ') ',
- 'outcomes' => []
-
-
-
- );
- }
- if (!isset($courses_array[$co->semester_id]['outcomes'][$co->outcome_id])) {
- $courses_array[$co->semester_id]['outcomes'][$co->outcome_id] = array(
- 'outcome_name' => $co->outcome_name,
- 'objectives' => []
- );
- }
-
- $courses_array[$co->semester_id]['outcomes'][$co->outcome_id]['objectives'][] = $co->objective_text;
- }
- $information_thats_missing['courses_missing'] = $courses_array;
- }
-
- if (count($information_thats_missing) != 0) {
- return $information_thats_missing;
- } else {
- $this->createAnnualPlan($program_id);
- }
- }
- public function createAnnualPlan($program_id)
- {
- $input_id = Input::get('typ_id');
- $current_typ = DB::select("select * from three_year_plan where id = {$input_id}")[0];
- $count = 0;
- $yearStartPlusOne = $current_typ->year_start + 1;
- $yearStart = $current_typ->year_start;
- //Log::info($yearStart);
- //Log::info($yearStartPlusOne);
- while ($count < 3) {
-
-
-
- $firstSemester = DB::select("select * from semesters where name like 'First Semester {$yearStart}-{$yearStartPlusOne}'");
-
- $secondSemester = DB::select("select * from semesters where name like 'Second Semester {$yearStart}-{$yearStartPlusOne}'");
- if (count($firstSemester) && count($secondSemester)) {
- Log::info($firstSemester);
- Log::info($secondSemester);
- $query = DB::select("select * from annual_cycle where semester_start ={$firstSemester[0]->id} and semester_end ={$secondSemester[0]->id} ");
- if (!count($query)) {
- DB::insert("insert into annual_cycle (academic_year, semester_start, semester_end) values ('{$yearStart}-{$yearStartPlusOne}', {$firstSemester[0]->id}, {$secondSemester[0]->id})");
- }
- $an_cycle = DB::table('annual_cycle')->where('semester_start', '=', $firstSemester[0]->id)
- ->where('semester_end', '=', $secondSemester[0]->id)
- ->first();
- $query = DB::table('annual_plans')->where("annual_cycle_id", '=', $an_cycle->id)
- ->where('program_id', '=', $program_id)->first();
- if (!$query) {
- DB::insert("insert into annual_plans (`annual_cycle_id`, `program_id`) values ({$an_cycle->id}, {$program_id})");
- }
- }
- $count++;
- $yearStart++;
- $yearStartPlusOne++;
- }
- $this->createThreeYearPlanPdf($program_id, $input_id);
- }
-
- public function createThreeYearPlanPdf($program_id, $typ)
- {
-
- $program = DB::table('programs')->where('id', $program_id)->first();
- $three_year_plan = DB::table('three_year_plan')->where('id', $typ)->first();
-
- $typ_program_id = DB::table('typ_program')->where('three_year_plan_id', $three_year_plan->id)
- ->where('program_id', $program->id)
- ->first()->id;
-
-
- $typ_semesters = DB::table('semesters')
- ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
- ->where('typ_id', $three_year_plan->id)
- ->orderBy('semester_id')
- ->get();
-
- //Log::info("Stop 2");
-
-
- foreach ($typ_semesters as $semester) {
- $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester->semester_id)
- ->select('typ_semester_outcome.id as typ_id')
- ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
- ->get();
-
- foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
- $outcome->objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_outcome_id', $outcome->typ_id)
- ->select('typ_semester_objectives.id as typ_obj_id')
- ->addSelect('objectives.text', 'objectives.id as objective_id')
- ->get();
- foreach ($outcome->objectives as $objective) {
- $objective->courses = DB::table('typ_semester_courses')
- ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
- ->where('typ_semester_objective_id', $objective->typ_obj_id)
- ->get();
- }
- }
- }
-
- //html para salvar
-
- $submit = 1;
- $view = 0;
-
-
- //$pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/three_year_plan_pdfs');
-
-
- //$pdf = $pdf->loadView('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'))
- // ->setOrientation("landscape")
-
- // ->setPaper('legal', 'landscape');
-
-
- $path = app_path() . '/views/three_year_plan_htmls/' . date('d-m-Y') . '-for-' . $program->id . '-by-' . Auth::user()->id . '.blade.php';
-
-
-
- $name = date('d-m-Y') . '-for-' . $program->id . '-by-' . Auth::user()->id . '.blade.php';
-
-
-
- //is a path already there, if it is, leave the same path
-
- $it_exists = DB::table("paths_for_three_year_plans")
- ->where('path_to_pdf', $path)
- ->first();
- //Log::info("pero aqui?");
-
- if (isset($it_exists)) {
- return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view', 'app_path', 'submit'));
- }
-
- //else save the new path and update time
-
-
- DB::table("paths_for_three_year_plans")
- ->where('typ_program_id', $typ_program_id)
- ->where('user_id', Auth::user()->id)
-
- ->update(array(
- 'last' => 0
- ));
-
-
- DB::table('paths_for_three_year_plans')->insert(array(
- "path_to_pdf" => $path,
- 'typ_program_id' => $typ_program_id,
- 'last' => 1,
- 'user_id' => Auth::user()->id,
- 'date_posted' => date('Y-m-d')
- ));
- return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view', 'app_path', 'submit'));
- }
-
- public function printPlan($program_id, $typ, $submit = NULL)
- {
- $view = 0;
-
- $program = DB::table('programs')->where('id', $program_id)->first();
- $three_year_plan = DB::table('three_year_plan')->where('id', $typ)->first();
-
- $typ_program_id = DB::table('typ_program')->where('three_year_plan_id', $three_year_plan->id)
- ->where('program_id', $program->id)
- ->first()->id;
-
- $typ_semesters = DB::table('semesters')
- ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
- ->where('typ_id', $three_year_plan->id)
- ->orderBy('semester_id')
- ->get();
-
-
- foreach ($typ_semesters as $semester) {
- $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester->semester_id)
- ->select('typ_semester_outcome.id as typ_id')
- ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
- ->get();
-
- foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
- $outcome->objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_outcome_id', $outcome->typ_id)
- ->select('typ_semester_objectives.id as typ_obj_id')
- ->addSelect('objectives.text', 'objectives.id as objective_id')
- ->get();
- foreach ($outcome->objectives as $objective) {
- $objective->courses = DB::table('typ_semester_courses')
- ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
- ->where('typ_semester_objective_id', $objective->typ_obj_id)
- ->get();
- }
- }
- }
- //Log::info($typ_semester_outcome);
-
-
- //TEMP
-
- //$app_path = app_path() . '/jsPDF-master/src/jspdf.js';
- //$submit = 1;
- return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view', 'app_path', 'submit'));
- }
-
- public function viewPlan($program_id, $typ)
- {
- $view = 1;
- $program = DB::table('programs')->where('id', $program_id)->first();
- $three_year_plan = DB::table('three_year_plan')->where('id', $typ)->first();
-
- $typ_program_id = DB::table('typ_program')->where('three_year_plan_id', $three_year_plan->id)
- ->where('program_id', $program->id)
- ->first()->id;
-
- $typ_semesters = DB::table('semesters')
- ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
- ->where('typ_id', $three_year_plan->id)
- ->orderBy('semester_id')
- ->get();
-
-
- foreach ($typ_semesters as $semester) {
- $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester->semester_id)
- ->select('typ_semester_outcome.id as typ_id')
- ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
- ->get();
-
- foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
- $outcome->objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_outcome_id', $outcome->typ_id)
- ->select('typ_semester_objectives.id as typ_obj_id')
- ->addSelect('objectives.text', 'objectives.id as objective_id')
- ->get();
- foreach ($outcome->objectives as $objective) {
- $objective->courses = DB::table('typ_semester_courses')
- ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
- ->where('typ_semester_objective_id', $objective->typ_obj_id)
- ->get();
- }
- }
- }
- Log::info($typ_semester_outcome);
-
-
- return View::make('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome', 'view'));
- }
-
- public function showPDFs($program_id)
- {
-
- $role = Auth::user()->role;
- switch ($role) {
- case 1:
- case 2:
- case 3:
- $last = [1, 0];
- break;
-
- case 4:
- $last = [1];
-
- break;
- default:
- App::abort('404');
- }
-
-
- $title = "Three Year Plans for " . Program::findOrFail($program_id)->name;
- $paths_with_users = DB::table('paths_for_three_year_plans')
- ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
- ->join('three_year_plan', 'typ_program.three_year_plan_id', '=', 'three_year_plan.id')
- ->join('users', 'users.id', '=', 'paths_for_three_year_plans.user_id')
-
- ->whereIn('last', $last)
- ->where('typ_program.program_id', $program_id)
- ->orderBy('date_posted', 'desc')
- ->select('paths_for_three_year_plans.path_to_pdf', 'users.*', 'date_posted', 'three_year_plan.*', 'paths_for_three_year_plans.last', 'paths_for_three_year_plans.id as path_id')
- ->get();
-
- return View::make('local.managers.shared.new_view_three_year_plans', compact('paths_with_users', 'title', 'last', 'program_id'));
- }
-
- /*public function downloadPDF($download, $path_id)
- {
- $pdf = new PDF(app('config'), app("Filesystem"), app('view'), '/storage/three_year_plan_pdfs');
-
- $queryToPath = DB::table('paths_for_three_year_plans')
- ->join('typ_program', 'typ_program.id', '=', 'paths_for_three_year_plans.typ_program_id')
- ->where('paths_for_three_year_plans.id', $path_id)
- ->first();
-
- //Log::info("ERES TU? creo que no");
-
- // $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
-
-
- $program = Program::findOrFail($queryToPath->program_id);
-
-
- $typ_program_id = $queryToPath->typ_program_id;
-
- $three_year_plan = DB::table('three_year_plan')
- ->where('id', $queryToPath->three_year_plan_id)
- ->first();
-
- $typ_semesters = DB::table('semesters')
- ->join('typ_semesters', 'semesters.id', '=', 'typ_semesters.semester_id')
- ->where('typ_id', $queryToPath->three_year_plan_id)
- ->orderBy('semester_id')
- ->get();
-
-
- foreach ($typ_semesters as $semester) {
- $typ_semester_outcome[$semester->semester_id] = DB::table('typ_semester_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'typ_semester_outcome.outcome_id')
- ->where('typ_program_id', $typ_program_id)
- ->where('semester_id', $semester->semester_id)
- ->select('typ_semester_outcome.id as typ_id')
- ->addSelect('outcomes.id as outcome_id', 'outcomes.name')
- ->get();
-
- foreach ($typ_semester_outcome[$semester->semester_id] as $outcome) {
- $outcome->objectives = DB::table('typ_semester_objectives')
- ->join('objectives', 'objectives.id', '=', 'typ_semester_objectives.objective_id')
- ->where('typ_semester_outcome_id', $outcome->typ_id)
- ->select('typ_semester_objectives.id as typ_obj_id')
- ->addSelect('objectives.text', 'objectives.id as objective_id')
- ->get();
- foreach ($outcome->objectives as $objective) {
- $objective->courses = DB::table('typ_semester_courses')
- ->join('courses', 'courses.id', '=', 'typ_semester_courses.course_id')
- ->where('typ_semester_objective_id', $objective->typ_obj_id)
- ->get();
- }
- }
- }
- //Log::info("ERES TU?");
-
- $pdf = $pdf->loadView('global.print_three_year_plan', compact('typ_semesters', 'program', 'three_year_plan', 'typ_semesters', 'typ_semester_outcome'))
- ->setOrientation("landscape")
-
- ->setPaper('legal', 'landscape');
- if ($download == "download")
- return $pdf->download(basename($queryToPath->path_to_pdf));
-
- else
- return $pdf->stream(basename($queryToPath->path_to_pdf));
- }
- */
-
- ///////////////////
- //
- //Pair everything
- //
- ////////////////////
-
- public function pairEveryObjective()
- {
- Log::info(Input::all());
- $selected_objectives = Input::get('selected_objectives');
- $typ_id = Input::get('typ_id');
- $program_id = Input::get('program_id');
- for ($i = 0; $i < count($selected_objectives); $i += 3) {
- Input::replace([
- 'program_id' => $program_id,
- 'new_objective_id' => $selected_objectives[$i + 2],
- 'outcome_id' => $selected_objectives[$i],
- 'semester_id' => $selected_objectives[$i + 1],
- 'typ_id' => $typ_id,
- 'previous_objective_id' => 'nothing_selected'
-
-
- ]);
- if ($this->section2_on_change() != 'update was succes')
- return 0;
- }
- return 200;
- }
-
- public function pairEveryCourse()
- {
- Log::info(Input::all());
- $typ_id = Input::get('typ_id');
- $program_id = Input::get('program_id');
- $pairing_array = Input::get('pairing_array');
- $type_of_work = Input::get("type_of_work");
-
- //$typ_id = Input::get('typ_id');
- //$outcome_id = Input::get('outcome_id');
- //$semester_id = Input::get('semester_id');
- //$objective_id = Input::get('objective_id');
- //$previous_course_id = Input::get('previous_course_id');
- //$new_course_id = Input::get('new_course_id');
-
- // get program_id
- //$program_id = Input::get('program_id');
-
-
- if ($type_of_work == 'este_semestre') {
- foreach ($pairing_array as $course_array) {
- Input::replace([
- 'outcome_id' => $course_array[0],
- 'semester_id' => $course_array[1],
- 'objective_id' => $course_array[2],
- 'new_course_id' => $course_array[3],
- 'typ_id' => $typ_id,
- 'previous_course_id' => 'nothing_selected',
- 'program_id' => $program_id,
-
-
- ]);
- if ($this->section3_on_change() != 'update succes?')
- return 0;
- }
- } else {
- foreach ($pairing_array as $semester_array) {
- foreach ($semester_array as $course_array) {
- Input::replace([
- 'outcome_id' => $course_array[0],
- 'semester_id' => $course_array[1],
- 'objective_id' => $course_array[2],
- 'new_course_id' => $course_array[3],
- 'typ_id' => $typ_id,
- 'previous_course_id' => 'nothing_selected',
- 'program_id' => $program_id,
-
-
- ]);
- if ($this->section3_on_change() != 'update succes?')
- return 0;
- }
- }
- }
- return 200;
- }
- }
|