123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- <?php
-
- use Illuminate\Database\Eloquent\Collection;
-
- class ThreeYearPlanController extends \BaseController
- {
-
- // load the Three year Plan page
- public function threeYearsReport()
- {
- $user_id = auth::user()->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'));
-
- }
-
-
- //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 = 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;
- }
-
- // 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');
-
- // 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';
- }
-
- // load the corresponding info after associating semesters with outcomes
- 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;
- }
-
- // load the corresponding info after associating objectives to semesters outcomes
- 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_) {
- $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.program_id')
- ->orderBy('courses.name', '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
- $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?';
- }
-
-
- }
|