1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054 |
- <?php
-
- use Illuminate\Support\Facades\Auth;
-
- class Objective2Controller extends \BaseController
- {
-
-
-
- // display index Objectives
-
- public function viewObjectives()
- {
-
-
- $title = "Learning Objectives and Criteria";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->get();
-
-
- return View::make('global.view-objectives-criteria', compact('title', 'outcomes'));
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return Response
- */
-
- public function fetchObjectivesForOutcome()
- {
-
- $outcome = Outcome::find(Input::get('id'));
-
-
- $role = Auth::user()->role;
- switch ($role) {
- case 1:
- $programs = DB::table('programs')->lists('id');
- break;
-
- case 2:
- $programs = DB::table('programs')
- ->where('school_id', Auth::user()->school_id)
- ->lists('id');
- break;
- case 3:
- case 4:
- $programs = DB::table('program_user')
- ->where("user_id", Auth::user()->id)
- ->lists('program_id');
- }
- Log::info("bad?");
- $objectives = $outcome->objectivesFromProgram($programs)->get();
-
- return $objectives;
- }
-
- public function deletePCOBO()
- {
- $pcobo_id = Input::get('pcobo_id');
- $criterion_id = Input::get('criterion_id');
- $objective_id = Input::get('objective_id');
- $outcome_id = Input::get('outcome_id');
- $program_id = Input::get('program_id');
- $old_cobo_id = Input::get('cobo_id');
-
- //criterio de holder.
-
-
- $cri_hol_dom = DB::table('criterion_objective_outcome')
- ->where('objective_id', 0)
- ->where('criterion_id', $criterion_id)
- ->where('outcome_id', $outcome_id)
- ->first();
-
- //si el criterio NO esta pareado a algun holder,
- if (!isset($cri_hol_dom)) {
- //entonces parealo para mantener la relacion de criterio domino
- $cri_obj_out_id = DB::table('criterion_objective_outcome')->insertGetId(
- array(
- 'objective_id' => 0,
- 'outcome_id' => $outcome_id,
- 'criterion_id' => $criterion_id
- )
- );
- }
- //si el criterio esta pareado a holder,
- else {
- $cri_obj_out_id = $cri_hol_dom->id;
- }
- //no creo que esto pase pero
-
- $exists_pair = DB::table("program_criterion_objective_outcome")
- ->where('program_id', $program_id)
- ->where('cri_obj_out_id', $cri_obj_out_id)
- ->first();
-
- if (isset($exists_pair)) {
- //se puede borrar la entrada
- //porque el pareo de programa-criterio-dominio-holder ya existe, so borrar esta entrada borra duplicados.
-
- DB::table('program_criterion_objective_outcome')
- ->where('id', $pcobo_id)
- ->delete();
- return 200;
- }
-
- //ahora como sabemos que existe el pareo de criterio y dominio con holder, podemos borrar criterio-objetivo-outcome
- //si y solo si no hay otro programa que tenga este cobo_id
-
- $otherPairing = DB::table("program_criterion_objective_outcome as pcobo")
- ->where('program_id', '<>', $program_id)
- ->where('cri_obj_out_id', $old_cobo_id)
- ->first();
- if (!isset($otherPairing)) {
- DB::table('criterion_objective_outcome')
- ->where('criterion_objective_outcome.id', $old_cobo_id)
- ->delete();
- }
-
-
-
-
- DB::table('program_criterion_objective_outcome')
- ->where('id', $pcobo_id)->update(array(
- 'cri_obj_out_id' => $cri_obj_out_id
- ));
-
-
-
- return 200;
- }
-
- public function isObjectiveUnique($input, $existing_Objective = NULL)
- {
-
- Log::info('isObjectiveUnique');
-
- if (Input::get('program_id') != 0)
- $program_id = $input['program_id'];
- else
- $program_id = NULL;
-
- $saved_Objective = DB::table('objectives')->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->where('objectives.text', '=', $input['text'])
- ->whereIn('objective_outcome.outcome_id', $input['outcome_id'])
- ->whereIn('objective_program.program_id', $input['program_id'])
-
- ->get();
-
-
-
- if (count($saved_Objective))
- return false;
- else
- return true;
- }
-
- //edit == true or edit == false
- private function makeValidator($clean_input, $edit)
- {
- /** Validation rules */
-
- if ($edit) {
- return Validator::make(
- array(
- //'text' => $clean_input['text'],
-
- 'outcome_id' => $clean_input['outcome_id'],
- 'program_id' => $clean_input['program_id']
-
- ),
- array(
-
- 'outcome_id' => 'required|array',
- 'program_id' => 'required|array'
-
- )
-
- );
- } else {
- return Validator::make(
- array(
- 'text' => $clean_input['text'],
-
- 'outcome_id' => $clean_input['outcome_id'],
- 'program_id' => $clean_input['program_id']
-
- ),
- array(
- 'text' => 'required|string|unique:objectives,text',
-
- 'outcome_id' => 'required|array',
- 'program_id' => 'required|array'
-
- )
-
- );
- }
- }
-
-
-
- private function cleanInput()
- {
- $clean_input = array();
-
- $clean_input['text'] = trim(preg_replace('/\t+/', '', Input::get('text')));
-
-
- $clean_input['outcome_id'] = Input::get('outcome');
- $counter = Input::get('counter') + 0;
- // Log::info($clean_input);
-
- foreach ($clean_input['outcome_id'] as $index => $outcome_id) {
- $clean_input['outcome_id'][$index] = trim(preg_replace('/\t+/', '', $clean_input['outcome_id'][$index]));
- }
-
- $clean_input['program_id'] = Input::get('program_id');
- // Log::info(Input::get('program_id'));
-
- $clean_input['agreement'] = Input::get("agreement");
-
- return $clean_input;
- }
-
- private function cleanAssocInput()
- {
- $clean_input = array();
-
- $clean_input['text'] = trim(preg_replace('/\t+/', '', Input::get('text')));
-
-
- $clean_input['outcome_id'] = Input::get('assoc_outcome');
- Log::info(Input::all());
-
-
- $clean_input['program_id'] = Input::get('program_id');
- $clean_input['pair_criteria'] = Input::get('pair_every_criteria_with_objective');
- $clean_input['agreement'] = Input::get('agreement');
-
-
- return $clean_input;
- }
- public function fetchObjective()
- {
- return Objective::find(Input::get('id'));
- }
-
- public function fetchProgramCriteria()
- {
- $outcome_id = Input::get("outcome_id");
- $objective = Objective::findOrFail(Input::get('objective_id'));
-
-
-
-
- $user_objective_programs_query = DB::table('objective_program');
-
- //Si es admin o school, puede ver todos los criterios de los programas pareados
- //Si es program_coordinator depende.
- if (Auth::user()->role == 3) {
- $user_objective_programs_query = $user_objective_programs_query
- ->join("program_user", 'program_user.program_id', '=', 'objective_program.program_id')
- ->where('user_id', Auth::user()->id);
- } elseif (Auth::user()->role == 2) {
- $user_objective_programs_query = $user_objective_programs_query
- ->join('programs', 'programs.id', '=', 'objective_program.program_id')
- ->where("programs.school_id", Auth::user()->school->id);
- }
- $program_ids = $user_objective_programs_query->where('objective_id', $objective->id)
- ->select('objective_program.program_id')
- ->lists('objective_program.program_id');
-
- Log::info("PRogram");
- //Log::info();
-
- //$array_to_send = [];
- //$array_to_send["programs"] = Program::whereIn('id', $program_ids)->with('criteria')->get();
- //$array_to_send['selected_criteria'] = $objective->pairedCriteria();
-
- //Program
- return Program::whereIn('id', $program_ids)
- ->select(DB::raw("programs.*, {$outcome_id} as outcome_id"))
-
- ->get();
- }
-
- public function updatePCOBO()
- {
- //aqui entra si cambia el viejo al nuevo
-
- $criterion_id = Input::get('criterion_id');
- $pcobo_id = Input::get("pcobo_id");
- $cobo_id = Input::get("cobo_id");
- $objective_id = Input::get("objective_id");
- $outcome_id = Input::get("outcome_id");
- $program_id = Input::get("program_id");
- $old_crit = Input::get('old_crit');
- $old_cobo_id = Input::get('old_cobo');
- $old_pcobo_id = Input::get('old_pcobo');
- $old_outcome_id = Input::get('old_outcome');
-
-
-
-
-
- //Existe el pareo de este criterio, este dominio y este objetivo?
-
- $existing_cobo_id = DB::table('criterion_objective_outcome')
- ->where('objective_id', $objective_id)
- ->where('outcome_id', $outcome_id)
- ->where('criterion_id', $criterion_id)
- ->first();
-
- if (!isset($existing_cobo_id)) {
- $insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
- 'criterion_id' => $criterion_id,
- 'outcome_id' => $outcome_id,
- 'objective_id' => $objective_id
-
- ));
- } else $insert_cobo_id = $existing_cobo_id->id;
-
- $it_exists = DB::table('program_criterion_objective_outcome')
- ->where('program_id', $program_id)
- ->where('cri_obj_out_id', $insert_cobo_id)
- ->first();
-
- if (isset($it_exists)) {
- return "DUPLICATE";
- }
-
- DB::table('program_criterion_objective_outcome')
- ->where("program_id", $program_id)
- ->where('cri_obj_out_id', $old_cobo_id)
- ->update(array(
- //'program_id' => $program_id,
- 'cri_obj_out_id' => $insert_cobo_id
- ));
-
-
-
- //now check if old criterion_objective_outcome is being used
-
- $other_pcobo_exist = DB::table('program_criterion_objective_outcome')
- ->where("cri_obj_out_id", $old_cobo_id)
- ->first();
-
-
- //si ningun otro programa tiene el pareo de este criterio con ese objetivo y ese dominio
- //lo puedes borrar
- if (!isset($other_pcobo_exist)) {
- DB::table('criterion_objective_outcome')
-
- ->where('id', $old_cobo_id)
- ->delete();
- }
-
-
-
- //Ahora hay que ver que la relacion de program, crit y dominio existe.
-
- $relationship_exists = DB::table('criterion_objective_outcome as cobo')
- ->join('program_criterion_objective_outcome as pcobo', 'pcobo.cri_obj_out_id', '=', 'cobo.id')
- ->where('criterion_id', $old_crit)
- ->where('outcome_id', $old_outcome_id)
- ->where('program_id', $program_id)
- ->first();
-
- if (!isset($relationship_exists)) {
- $new_cobo_id = DB::table('criterion_objective_outcome')
- ->insertGetId(array(
- 'criterion_id' => $old_crit,
- 'outcome_id' => $old_outcome_id,
- 'objective_id' => 0
- ));
- DB::table('program_criterion_objective_outcome')
- ->insert(array(
- 'program_id' => $program_id,
- 'cri_obj_out_id' => $new_cobo_id
- ));
- }
-
-
-
-
-
-
-
-
-
- return 200;
-
-
- //Aqui es insertar
-
-
- }
-
- public function insertPCOBO()
- {
- //aqui entra si le da a add criterio, y escoje uno nuevo
-
- $criterion_id = Input::get('criterion_id');
- $pcobo_id = Input::get("pcobo_id");
- $cobo_id = Input::get("cobo_id");
- $objective_id = Input::get("objective_id");
- $outcome_id = Input::get("outcome_id");
- $program_id = Input::get("program_id");
- Log::info(Input::all());
-
-
- //doc se esta usando? ie, objetivo_id == 0?
-
- //Existe el pareo de este criterio, este dominio y este objetivo?
-
-
-
- $old_cobo_id = DB::table('criterion_objective_outcome')
- ->where('objective_id', $objective_id)
- ->where('outcome_id', $outcome_id)
- ->where('criterion_id', $criterion_id)
- ->first();
-
- if (!isset($old_cobo_id)) {
- $insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
- 'criterion_id' => $criterion_id,
- 'outcome_id' => $outcome_id,
- 'objective_id' => $objective_id
-
- ));
- } else $insert_cobo_id = $old_cobo_id->id;
-
- $it_exists = DB::table('program_criterion_objective_outcome')
- ->where('program_id', $program_id)
- ->where('cri_obj_out_id', $insert_cobo_id)
- ->first();
-
- if (isset($it_exists)) {
- return "DUPLICATE";
- }
-
- DB::table('program_criterion_objective_outcome')
- ->insert(array(
- 'program_id' => $program_id,
- 'cri_obj_out_id' => $insert_cobo_id
- ));
-
-
-
- return 200;
-
-
- //Aqui es insertar
-
-
- }
-
- public function fetchObjectiveWithTrashed()
- {
- $json = array();
-
- $json['program'] = DB::select("select program_id from objective_program where objective_id = ?", array(Input::get('id')));
-
- //$json['outcome'] = DB::select("select outcome_id from objective_outcome outc where outc.objective_id = ?", array(Input::get('id')));
- $json['objective'] = DB::select("select text, id from objectives where id =?", array(Input::get('id')));
- $json['assessment'] = DB::select("select * from assessments where activity_criterion_id in (select id from activity_criterion where criterion_id in (select criterion_id from criterion_objective_outcome where objective_id = ?))", array(Input::get('id')));
- /*
- select objective_outcome.*, typ_semester_outcome.id as typ_semester_outcome_id,count(criterion_id) from objectives join objective_outcome on objective_outcome.objective_id = objectives.id left join criterion_objective_outcome on criterion_objective_outcome.objective_id = objectives.id and objective_outcome.outcome_id = criterion_objective_outcome.outcome_id
- left join typ_semester_objectives on typ_semester_objectives.objective_id = objectives.id left join typ_semester_outcome on typ_semester_outcome.outcome_id = objective_outcome.outcome_id and typ_semester_outcome.id = typ_semester_objectives.typ_semester_outcome_id group by objectives.id, objective_outcome.outcome_id
-
- */
- $json['outcome'] = DB::table('objective_outcome')
-
- ->leftJoin('criterion_objective_outcome', function ($j) {
- $j->on('criterion_objective_outcome.objective_id', '=', 'objective_outcome.objective_id')
- ->on('criterion_objective_outcome.outcome_id', '=', 'objective_outcome.outcome_id');
- })
- ->leftJoin('typ_semester_objectives', 'typ_semester_objectives.objective_id', '=', 'objective_outcome.objective_id')
- ->leftJoin('typ_semester_outcome', function ($j) {
- $j->on('typ_semester_outcome.outcome_id', '=', 'objective_outcome.outcome_id')
- ->on('typ_semester_outcome.id', '=', 'typ_semester_objectives.typ_semester_outcome_id');
- })
- ->groupBy("objective_outcome.objective_id", 'objective_outcome.outcome_id')
- ->where('objective_outcome.objective_id', Input::get('id'))
- ->select(
- 'objective_outcome.*',
- DB::raw("count(criterion_id) as count_criterion_id"),
- 'typ_semester_outcome.id as typ_semester_outcome_id'
- )
- ->get();
-
-
- $json['typ_semester_objectives'] = DB::table('typ_semester_objectives')
- ->where('objective_id', Input::get('id'))
- ->get();
-
- $json['assoc_criteria'] = DB::select("select name from criteria where id in(select criterion_id from criterion_objective_outcome where objective_id =?)", array(Input::get('id')));
- Log::info('is here');
- // Log::info(json_encode($json));
- return json_encode($json);
- }
- public function fetchAllobjectives()
- {
- $program_id = Input::get('program_fetch');
- $outcome_id = Input::get('outcome_fetch');
- $json = array();
-
-
- $json['objective'] = DB::select("SELECT * FROM `objectives` where id in (select objective_id from objective_outcome where outcome_id ={$outcome_id}) and id in (select objective_id from objective_program where program_id = {$program_id} and objective_id <> 0)");
- Log::info('En mi sueño');
- Log::info($json);
- return json_encode($json);
- }
-
- public function delete()
- {
- DB::delete("delete from objectives where id = ?", array(Input::get('deleteObj')));
- return Redirect::to('objectives')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('objectives')->withInput();
-
- case 2:
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return Redirect::to('program-objective')->withInput();
- }*/
- }
- /**
- * Create a new Objective.
- *
- * @return Redirect Redirect back to form page
- */
- public function create()
- {
-
- $clean_input = $this->cleanInput();
- Log::info($clean_input);
- /** Validation rules */
- $validator = $this->makeValidator($clean_input, false);
-
- /** If validation fails */
- if ($validator->fails()) {
- /** Prepare error message */
- $message = '<p>Error(s) creating a new Objective:</p><ul>';
-
- foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
- $message .= $validationError;
- }
-
- $message .= '</ul>';
-
- /** Send error message and old data */
- Session::flash('status', 'danger');
- Session::flash('message', $message);
- return Redirect::to('objectives')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('objective')->withInput();
-
- case 2:
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return Redirect::to('program-objective')->withInput();
- }*/
- } else {
- // Check Objective uniqueness
- if (!$this->isObjectiveUnique($clean_input)) {
- /** Send error message and old data */
- Session::flash('status', 'danger');
- Session::flash('message', "This objective is a duplicate of an already saved Objective because it's and associated program are the same.");
- return Redirect::to('objectives')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('objective')->withInput();
-
- case 2:
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return Redirect::to('program-objective')->withInput();
- }*/
- }
-
- /** Instantiate new Objective */
- $objective = new Objective;
- $objective->text = $clean_input['text'];
-
-
-
-
-
-
-
- /** If Objective is saved, send success message */
- if ($objective->save()) {
- $objectiveId = $objective->id;
-
- Log::info($clean_input['outcome_id']);
-
-
-
-
- foreach ($clean_input['program_id'] as $program_id) {
- DB::insert("insert into objective_program (objective_id, program_id) values({$objectiveId},{$program_id})");
- }
- foreach ($clean_input['outcome_id'] as $outcome_id) {
- DB::insert("insert into `objective_outcome` (objective_id, outcome_id) values ({$objectiveId}, {$outcome_id})");
- //DB::raw("insert ignore into `objective_outcome` (objective_id, outcome_id) values ({$objectiveId}, {$outcome_id})");
- /*if (!($objectiveOutcome->save())) {
- Session::flash('status', 'danger');
- Session::flash('message', '<p>Error creating objective. Please try again later.</p>');
- return Redirect::to('objective')->withInput();
- }*/
- }
- if ($clean_input['agreement']) {
- DB::table('criterion_objective_outcome')
- ->join('program_criterion', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion.criterion_id')
- ->whereIn('program_id', $clean_input['program_id'])
- ->whereIn('outcome_id', $clean_input['outcome_id'])
- ->where('objective_id', '=', 0)
- ->update(array('objective_id' => $objectiveId));
- }
- // update("update criterion_objective_outcome coo join program_criterion pc on coo.criterion_id=pc.criterion_id set
- // objective_id= {$objectiveId} where program_id in (".$clean_input['program_id'].") and objective_id=0 and outcome_id in (".$clean_input['outcome_id'].")");
-
- Session::flash('status', 'success');
- Session::flash('message', 'Objective created: "' . $objective->text . '".');
- return Redirect::to('objectives')->withInput(Input::only('outcome_id'));
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('objective')->withInput(Input::only('outcome_id'));
-
- case 2:
- return Redirect::to('school-objective')->withInput(Input::only('outcome_id'));
-
- case 3:
- return Redirect::to('program-objective')->withInput(Input::only('outcome_id'));
- }*/
- }
-
- /** If saving fails, send error message and old data */
- else {
- Session::flash('status', 'danger');
- Session::flash('message', '<p>Error creating objective. Please try again later.</p>');
- return Redirect::to('objectives')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('objective')->withInput();
-
- case 2:
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return Redirect::to('program-objective')->withInput();
- }*/
- }
- }
- }
- /**
- * Store a newly created resource in storage.
- *
- * @return Response
- */
- public function store()
- {
- //
- }
-
-
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function show($id)
- {
- //
- }
-
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return Response
- */
- public function edit()
- {
- $title = "Objective";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->get();
-
- $role = Auth::user()->role;
-
- switch ($role) {
- case 1:
- $program_ids = DB::table("programs")
- ->lists('id');
- break;
-
- case 2:
- $program_ids = DB::table('programs')
- ->where('school_id', Auth::user()->school_id)
- ->lists('id');
-
- break;
- case 3:
- $program_ids = DB::table('program_user')
- ->where('user_id', Auth::user()->id)
- ->lists('program_id');
-
-
- break;
- }
- $objectives_from_program = DB::table('objective_program')
- ->where('program_id', $program_ids)
- ->where('objective_program.objective_id', "<>", 0)
- ->lists('objective_id');
- $objectives = Objective::withTrashed()->whereIn('id', $objectives_from_program)->orderBy('text', 'ASC')->get();
- $programs = Program::whereIn('id', $program_ids)->orderBy('name', 'ASC')->get();
-
- return View::make('local.managers.shared.objectives', compact('title', 'outcomes', 'objectives', 'programs'));
- }
-
- public function editProgram()
- {
- $userProgram = Auth::user()['id'];
- Log::info(Auth::user());
-
- $userProgram = DB::select("select program_user.program_id from program_user where user_id = {$userProgram}");
-
- $title = "Objective";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->get();
- $objectives_from_program = DB::table('objective_program')
- ->where('program_id', $userProgram[0]->program_id)
- ->where('objective_program.objective_id', "<>", 0)
- ->lists('objective_id');
- $objectives = Objective::withTrashed()->orderBy('text', 'ASC')->whereIn('id', $objectives_from_program)->get();
-
- $programs = Program::where("id", '=', $userProgram[0]->program_id)->get();
-
-
-
-
- return View::make('local.managers.pCoords.objectives', compact('title', 'outcomes', 'objectives', 'programs'));
- }
-
- public function editSchool()
- {
- $userSchool = Auth::user()['school_id'];
- Log::info($userSchool);
- $title = "Objective";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->get();
-
- $objectives_from_school = DB::table('programs')
- ->join('objective_program', 'objective_program.program_id', '=', 'programs.id')
- ->where('programs.school_id', $userSchool)
- ->where('objective_program.objective_id', "<>", 0)
- ->lists('objective_id');
- $objectives = Objective::withTrashed()->orderBy('text', 'ASC')->whereIn('id', $objectives_from_school)->get();
- $programs = Program::where("school_id", "=", $userSchool)->orderBy('name', 'ASC')->get();
-
-
-
- return View::make('local.managers.sCoords.objectives', compact('title', 'outcomes', 'objectives', 'programs'));
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param int $id
- * @return Response
- */
-
- /*pasos que sigue
- 1. edita el texto del objetivo, si alguno,
- 2. escoge los criteri
- */
-
- public function update()
-
- {
-
- $Objective = Objective::withTrashed()->find(Input::get('id'));
-
- $clean_input = $this->cleanAssocInput();
-
-
- //Log::info(print_r($clean_input, true));
-
- /** Validation rules */
- if ($clean_input['text'] == $Objective->text) {
- $validator = $this->makeValidator($clean_input, true);
- } else
- $validator = $this->makeValidator($clean_input, false);
-
- /** If validation fails */
- if ($validator->fails()) {
- /** Prepare error message */
- $message = 'Error(s) updating the Objective: <ul>';
-
- foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
- $message .= $validationError;
- }
-
- $message .= '</ul>';
-
- /** Send error message and old data */
- //Session::flash('status', 'danger');
- //Session::flash('message', $message);
- $MessageArray = array('status' => 'danger', 'message' => $message);
- return $MessageArray;
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return $MessageArray;
- return Redirect::to('objective')->withInput();
-
- case 2:
- return $MessageArray;
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return $MessageArray;
- return Redirect::to('program-objective')->withInput();
- }*/
- } else {
-
-
-
- /** Set info */
- Log::info($clean_input);
- $Objective->text = $clean_input['text'];
-
-
-
-
- // Set status
-
-
- /** If Objective is updated, send success message */
- if ($Objective->save()) {
-
- //TODO
-
- $objectiveId = $Objective->id;
-
-
- //criteria_assoc, si le dan a 1, parea todos los criterios que esten pareado a este objetivo,
- // a todos los criterios asociados de su programa
-
- $criteria_assoc = DB::table('criterion_objective_outcome')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
- //->join('program_criterion', 'program_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
- ->whereIn('program_id', $clean_input['program_id'])
- ->where('objective_id', $objectiveId)
- ->groupBy('criterion_objective_outcome.criterion_id')
- ->select('criterion_objective_outcome.criterion_id')
- ->lists('criterion_objective_outcome.criterion_id');
- //DB::delete("delete from `objective_outcome` where objective_id ={$objectiveId}");
-
-
- DB::delete("delete from objective_program where objective_id = {$objectiveId}");
-
- foreach ($clean_input['program_id'] as $program_id) {
- DB::insert("insert into `objective_program`(objective_id, program_id) values ({$objectiveId},{$program_id})");
- }
-
- //$cri_obj_out_ids = DB::table('criterion_objective_outcome as cobo')
- //->where('objective_id', $objectiveId)
- //->lists('cobo.id')
- //Todos los criterios, que están pareados a este objetivo, pero
- // están pareados a otros dominios que no son los seleccionados, ponlos en holder.
- DB::table('criterion_objective_outcome as cobo')
- //->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
-
- //->whereIn('program_id', $clean_input['program_id'])
- ->where('objective_id', $objectiveId)
- ->whereNotIn('outcome_id', $clean_input['outcome_id'])
- ->update(array(
- 'objective_id' => 0
- ));
-
- //borra todos los pareos de este objetivo con programas que no están en los programas que el usuario escogió
-
-
- //DB::table("program_criterion_objective_outcome as poco")
- // ->join("criterion_objective_outcome as cobo", 'poco.cri_obj_out_id', '=', 'cobo.id')
- // ->where('objective_id',$objectiveId)
- // ->whereNotIn('program_id', $clean_input['program_id'])
- // ->delete();
-
-
-
- Log::info($clean_input);
-
-
-
- /*$cri_obj_out = DB::table('criterion_objective_outcome')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
- ->whereIn('program_id', $clean_input['program_id'])
- ->where('objective_id', $objectiveId)
- ->update(array(
- 'objective_id' => 0
- ));*/
-
- //Luego por cada dominio que haya, chequea si existe ya el pareo
- //si no existe insertalo.
- //si insertaste, y pair_criteria == 1, parea todos los criterios bajo este programa con
- // ese dominio y outcome
- // Luego por cada criterio que esta pareado a objetivo 0, en ese programa
- //y en ese dominio, cambiale el objetivo a este.
-
-
-
- //los que se crearon nue
- foreach ($clean_input['outcome_id'] as $outcome_id) {
- $check_if_already_inserted = DB::table('objective_outcome')
- ->where('objective_id', $objectiveId)
- ->where('outcome_id', $outcome_id)
- ->first();
- if (!isset($check_if_already_inserted)) {
- DB::insert("insert into `objective_outcome` (objective_id, outcome_id) values ({$objectiveId}, {$outcome_id})");
- if ($clean_input['pair_criteria'] == '1') {
- foreach ($criteria_assoc as $criterion_id) {
-
- $cob_id = DB::table('criterion_objective_outcome')
- ->where('criterion_id', $criterion_id)
- ->where('objective_id', $objectiveId)
- ->where('outcome_id', $outcome_id)
- ->first();
- if (!isset($cob_id)) {
- $cob_id = DB::table('criterion_objective_outcome')
- ->insertGetId(array(
- "criterion_id" => $criterion_id,
- "objective_id" => $objectiveId,
- "outcome_id" => $outcome_id
- ));
- } else
- $cob_id = $cob_id->id;
- //inserta los. criterios asociados a los nuevos dominios y parealos a estos programas_id
-
- foreach ($clean_input['program_id'] as $program_id) {
- $poco_id = DB::table('program_criterion_objective_outcome')
- ->where("cri_obj_out_id", $cob_id)
- ->where('program_id', $program_id)
- ->first();
- if (!isset($poco_id)) {
- DB::table('program_criterion_objective_outcome')
- ->insert(array(
- "program_id" => $program_id,
- "cri_obj_out_id" => $cob_id
- ));
- } else {
- DB::table('program_criterion_objective_outcome')
- ->where('id', $poco_id->id)
- ->update(array(
- 'cri_obj_out_id' => $cob_id
- ));
- }
- }
- }
- }
- }
- }
-
- if ($clean_input["agreement"] == 1) {
- DB::table('criterion_objective_outcome')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
- ->whereIn('program_id', $clean_input['program_id'])
- ->where('objective_id', 0)
- ->whereIn('outcome_id', $clean_input['outcome_id'])
-
- ->update(array(
- 'objective_id' => $objectiveId
- ));
- }
-
-
- //Borra los objective outcomes que no estan pareado a nada
-
- DB::table('objective_outcome')
- ->where('objective_id', $objectiveId)
- ->whereNotIn('outcome_id', $clean_input['outcome_id'])->delete();
-
- //Session::flash('status', 'success');
- //Session::flash('message', 'Updated Objective: "' . $Objective->text . '"');
- $MessageArray = array('status' => 'success', 'message' => 'Updated Objective: "' . $Objective->text . '"');
- return $MessageArray;
- /*$role = Auth::user()['role'];
-
- switch ($role) {
- case 1:
- return $MessageArray;
- return Redirect::to('objective')->withInput();
-
- case 2:
- return $MessageArray;
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return $MessageArray;
- return Redirect::to('program-objective')->withInput();
- }*/
- }
-
- /** If saving fails, send error message and old data */
- else {
- //Session::flash('status', 'danger');
- ////Session::flash('message', 'Error updating the Objective. Please try again later.');
- $MessageArray = array('status' => 'danger', 'message' => 'Error updating the Objective. Please try again later.');
- return $MessageArray;
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return $MessageArray;
- return Redirect::to('objectives')->withInput();
-
- case 2:
- return $MessageArray;
- return Redirect::to('school-objective')->withInput();
-
- case 3:
- return $MessageArray;
- return Redirect::to('program-objective')->withInput();
- }
- }
- }
- }
-
-
-
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return Response
- */
- public function destroy($id)
- {
- //
- }
- }
|