id; // 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 Plans Planning"; $outcomes = Outcome::orderBy('name', 'ASC') ->where('deactivation_date', '=', '0000-00-00') ->orWhereNull('deactivation_date') ->get(); $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; // se annadio la nueva variable return View::make('global.view-three-year-plan', compact('title', 'outcomes', 'typs', 'criteria', 'semesters', 'program_id')); } 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) // ->select('semesters.*') ->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, ); } 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 = DB::table('program_user') ->where('user_id', $user_id) ->select('program_id') ->get(); $program_id = $program_id[0]->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; } 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) ); } public function section2_on_change() { $typ_id = Input::get('typ_id'); // typ_id: (typ_id), $outcome_id = Input::get('outcome_id'); // outcome_id: (outcome_id), $semester_id = Input::get('semester_id'); // semester_id: (semester_id), $previous_objective_id = Input::get('previous_objective_id'); // previous_objective_id: (previous_objective_id), $new_objective_id = Input::get('new_objective_id'); // new_objective_id: (new_objective_id) // get program_id $user_id = auth::user()->id; $program_id = DB::table('program_user') ->where('user_id', $user_id) ->select('program_id') ->get(); $program_id = $program_id[0]->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; //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'; } public function section2_arrive() { // get program_id $user_id = auth::user()->id; $program_id = DB::table('program_user') ->where('user_id', $user_id) ->select('program_id') ->get(); $program_id = $program_id[0]->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') ->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) ->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; } public function section3_arrive() { // get program_id $user_id = auth::user()->id; $program_id = DB::table('program_user') ->where('user_id', $user_id) ->select('program_id') ->get(); $program_id = $program_id[0]->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') ->get(); // buscar info sobre selected_semsters $outcome_->selected_semesters = array(); foreach ($result_semesters as $semesters_) { $semester_id = $semesters_->semester_id; $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_) { $objective_id = $objectives_->objective_id; $program_id = $objectives_->program_id; $result_courses = DB::table('objective_program') ->join('objectives', 'objectives.id', '=', 'objective_program.objective_id') ->join('courses', 'courses.program_id', '=', 'objective_program.program_id') ->where('objective_program.objective_id', $objective_id) ->where('objective_program.program_id', $program_id) ->where('courses.semester_id', $semester_id) ->distinct('courses.name', 'courses.code') ->select('courses.id as course_id', 'courses.name', 'courses.code', 'objective_program.objective_id', 'objective_program.program_id') ->orderBy('courses.name', 'asc') ->groupBy('courses.name', 'courses.code') ->get(); $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; } public function section3_on_change() { $typ_id = Input::get('typ_id'); // typ_id: (typ_id), $outcome_id = Input::get('outcome_id'); // outcome_id: (outcome_id), $semester_id = Input::get('semester_id'); // semester_id: (semester_id), $objective_id = Input::get('objective_id'); // objective_id: (objective_id), $previous_course_id = Input::get('previous_course_id'); // previous_course_id: (previous_course_id), $new_course_id = Input::get('new_course_id'); // new_course_id: (new_course_id) // get program_id $user_id = auth::user()->id; $program_id = DB::table('program_user') ->where('user_id', $user_id) ->select('program_id') ->get(); $program_id = $program_id[0]->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 createAnnualPlan($program_id) { $current_typ = DB::select("select * from three_year_plan where year_start <=" . date('Y') . " and year_end >=" . date('Y'))[0]; $count = 0; $yearStartPlusOne = $current_typ->year_start + 1; $yearStart = $current_typ->year_start; 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)) { $query = DB::select("select * from annual_plans where semester_start ={$firstSemester[0]->id} and semester_end ={$secondSemester[0]->id} and program_id = {$program_id}"); if (!count($query)) { DB::insert("insert into annual_plans (academic_year, semester_start, semester_end, program_id) values ('{$yearStart}-{$yearStartPlusOne}', {$firstSemester->id}, {$secondSemester->id}, {$program_id})"); } $count++; $yearStart++; $yearStartPlusOne++; } else { $count++; $yearStart++; $yearStartPlusOne++; continue; } } } }