1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261 |
- <?php
-
- use Illuminate\Support\Facades\Input;
-
- class CriteriaController extends \BaseController
- {
-
- /**
- * Display a listing of the resource.
- *
- *
- * @return Response
- */
- public function editProgram()
- {
- $userProgram = Auth::user()['id'];
-
-
-
- $userProgram = DB::select("select program_user.program_id from program_user where user_id = {$userProgram}");
- Log::info($userProgram);
- $title = "Criteria";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->lists('name', 'id');
-
- $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
- $programs = Program::where("id", "=", $userProgram[0]->program_id)->get();
- return View::make('local.managers.pCoords.criteria', compact('title', 'outcomes', 'schools', 'criteria', 'programs', 'objectives'));
- }
-
- public function editSchool()
- {
- $userSchool = Auth::user()['school_id'];
- Log::info($userSchool);
- $title = "Criteria";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->lists('name', 'id');
-
- $schools = School::find($userSchool)->get();
- $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
- $programs = Program::where("school_id", "=", $userSchool)->orderBy('name', 'ASC')->get();
- $listOfId = array();
- foreach ($programs as $program) {
-
- $listOfId[] = $program->id;
- }
-
- //$objectives = DB::table('objectives')->whereIn('program_id', $listOfId)->orderBy('text', 'ASC')->lists('text', 'id');
-
-
-
-
-
- return View::make('local.managers.sCoords.criteria', compact('title', 'outcomes', 'schools', 'criteria', 'programs' /* 'objectives'*/));
- }
-
- public function fetchCriterionWithTemplate()
- {
- $json_to_send = array();
- $json_to_send['criterion'] = DB::table('criteria')->where('id', '=', Input::get('id'))->first();
- $outcomeIDS = DB::table('criterion_objective_outcome')->where('criterion_id', '=', $json_to_send['criterion']->id)->lists('outcome_id');
- Log::info($outcomeIDS);
-
- $json_to_send['scales'] = DB::table('criterion_scale')
- ->join('scales', 'scales.id', '=', 'criterion_scale.scale_id')
- ->where('criterion_id', Input::get('id'))
- ->orderBy('position')
- ->get();
- $json_to_send['outcomes'] = DB::table('outcomes')->whereIn('id', $outcomeIDS)->get();
- $outcomeStr = '';
- if (count($json_to_send['outcomes']) == 1) {
- $outcomeStr .= $json_to_send['outcomes'][0]->name;
- } else {
- foreach ($json_to_send['outcomes'] as $index => $outcome) {
-
- $outcomeStr .= ($index + 1) . '. ' . $outcome->name . '<br>';
- }
- $outcomeStr = rtrim($outcomeStr, ',');
- }
- $json_to_send['outcomes'] = $outcomeStr;
-
- return json_encode($json_to_send);
- }
-
- public function fetchCriterion()
- {
- $json_to_send = array();
-
- $json_to_send['criterion'] = DB::table('criteria')->where('id', '=', Input::get('id'))->first();
-
-
-
- return $json_to_send['criterion'];
- }
- public function fetchAllCriterion()
- {
- $program_id = Input::get('program_fetch');
- $outcome_id = Input::get('outcome_fetch');
- $json = array();
- $json['criterion'] = DB::select("SELECT * FROM `criteria` where id in (select criterion_id from criterion_objective_outcome join program_criterion_objective_outcome on program_criterion_objective_outcome.cri_obj_out_id = criterion_objective_outcome.id where outcome_id ={$outcome_id} and program_id = {$program_id}) ");
-
- return json_encode($json);
- }
- public function fetchObjectivesForSelect()
- {
- $json = array();
- $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;
- case 4:
-
- $program_ids = DB::table('program_user')
- ->where('user_id', Auth::user()->id)
- ->lists('program_id');
-
- break;
- }
- $outcome_id = Input::get('outcomeID');
- Log::info($outcome_id);
-
- $json = DB::table('objectives')
- ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->where('outcome_id', '=', $outcome_id)
- ->where('objectives.id', '<>', 0)
- ->whereIn('program_id', $program_ids)
- ->select('objectives.*', 'objective_outcome.*')
- ->distinct()
- ->get();
-
- foreach ($json as $objective) {
- $objective->program_ids = json_encode(DB::table('objective_program')
- ->where('objective_id', $objective->objective_id)
- ->lists('program_id'), JSON_NUMERIC_CHECK);
- }
-
-
- return json_encode($json);
- }
- public function fetchCriterionWithTrashed()
- {
-
- /* $json = array();
- $json['criteria'] = DB::table('criteria')->where('id', Input::get('id'))->get();
-
-
- $assoc_outcomes = DB::table('criterion_objective_outcome')->where('criterion_id', Input::get('id'))->lists('outcome_id');
- $json['outcomes'] = DB::table('outcomes')->whereIn('id', $assoc_outcomes)->get();
- $criteria_id = Input::get('id');
- foreach ($json['outcomes'] as $outcome) {
- $id = $outcome->id;
- $json['objectives'][$id] = DB::table('objectives')
- ->join('criterion_objective_outcome', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
- ->where('criterion_id', '=', $criteria_id)
- ->where('outcome_id', '=', $id)
- ->get();
- $json['objectives_assoc'][$id] = DB::table('objectives')
- ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
- ->where('outcome_id', $id)
- ->get();
- foreach ($json['objectives_assoc'][$id] as $objective) {
- $objective->program_ids = json_encode(DB::table('objective_program')
- ->where('objective_id', $objective->objective_id)
- ->lists('program_id'));
- }
- }
- $json['program'] = DB::table('program_criterion')->where('criterion_id', $criteria_id)->get();
- $json['activity_criterion'] = DB::table('assessments')
- ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
- ->where('activity_criterion.criterion_id', $criteria_id)
- ->get();
- $json['scales'] = DB::table('criterion_scale')
- ->join('scales', 'criterion_scale.scale_id', '=', 'scales.id')
- ->where('criterion_id', $criteria_id)
- ->orderBy('position')
- ->get();
-
-
- /*
- $json['criteria'] = DB::select(" select * from criteria where id = ?", array(Input::get('id')));
- $json['outcomes'] = DB::select("select DISTINCT outcomes.id, outcomes.name from outcomes , criterion_objective_outcome where criterion_objective_outcome.criterion_id = ? and outcomes.id = criterion_objective_outcome.outcome_id order by outcomes.id", array(Input::get('id')));
- $json['objectives'] = DB::select("SELECT DISTINCT objectives.id, objectives.text FROM objectives, criterion_objective_outcome where criterion_objective_outcome.criterion_id = ? and criterion_objective_outcome.objective_id= objectives.id ", array(Input::get('id')));
- $json['objectives_outcome'] = DB::select("select objectives.id, objectives.text, objective_outcome.outcome_id from objective_outcome, objectives where objective_outcome.outcome_id in(select DISTINCT outcomes.id from outcomes , criterion_objective_outcome where criterion_objective_outcome.criterion_id = ? and outcomes.id = criterion_objective_outcome.outcome_id) and objectives.id = objective_outcome.objective_id ORDER BY outcome_id", array(Input::get('id')));
- $json['program'] = DB::select("select criterion_id, program_id from program_criterion where criterion_id =?", array(Input::get('id')));
- $json['activity_criterion'] = DB::select("select * from assessments where activity_criterion_id in (select id from activity_criterion where criterion_id = ?)", array(Input::get('id')));
-
- foreach ($json['outcomes'] as $id) {
- $outId = $id->id;
- $json['outcomes_assoc'][$outId] = DB::select("select name from outcomes where id = {$outId}");
- $json['objectives_assoc'][$outId] = DB::select("select objectives.id, objectives.text, outcomes.name from objectives, objective_outcome, outcomes where objective_outcome.outcome_id ={$outId} and objective_outcome.objective_id = objectives.id and objectives.active=1 and outcomes.id = objective_outcome.outcome_id");
- }*/
- $userRole = Auth::user()['role'];
- switch ($userRole) {
- 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:
- case 4:
- $program_ids = DB::table('program_user')
- ->where('user_id', Auth::user()->id)
- ->lists('program_id');
- break;
- }
- $criteria_id = Input::get('id');
- $criterion = DB::table('criteria')->where('id', Input::get('id'))->first();
- if (!$criterion) return $criterion;
- $criterion->outcomes = DB::table('criterion_objective_outcome')
- ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
- ->whereIn("program_id", $program_ids)
- ->where('criterion_id', $criterion->id)
- ->select('outcomes.*')
- ->distinct()
- ->get();
-
-
- foreach ($criterion->outcomes as $outcome) {
-
- $outcome->assoc_objectives = DB::table('objective_outcome')
- ->join('objectives', 'objectives.id', '=', 'objective_outcome.objective_id')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->whereIn('program_id', $program_ids)
- ->where('outcome_id', $outcome->id)
- ->select('objectives.*', 'objectives.id as objective_id')
- ->distinct()
- ->get();
- $outcome->objectives_criteria = DB::table('criterion_objective_outcome')
- ->join("program_criterion_objective_outcome as poco", 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
- ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
- ->where('criterion_id', $criterion->id)
- ->whereIn("poco.program_id", $program_ids)
- ->where('outcome_id', $outcome->id)
- ->select('objectives.*', 'objectives.id as objective_id')
- ->distinct()
- ->get();
-
- foreach ($outcome->assoc_objectives as $objective) {
- $objective->program_ids = json_encode(DB::table('objective_program')
- ->where('objective_id', $objective->id)
- ->lists('program_id'), JSON_NUMERIC_CHECK);
- }
- }
- $criterion->scales = DB::table('criterion_scale')
- ->join('scales', 'criterion_scale.scale_id', '=', 'scales.id')
- ->where('criterion_id', $criteria_id)
- ->orderBy('position')
- ->get();
- $criterion->program = DB::table('program_criterion_objective_outcome as poco')
- ->join('criterion_objective_outcome as cobo', 'cobo.id', '=', 'poco.cri_obj_out_id')
- ->where('criterion_id', $criteria_id)
- ->select('poco.program_id')
- ->distinct()->get();
- $criterion->activity_criterion = DB::table('assessments')
- ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
- ->where('activity_criterion.criterion_id', $criteria_id)
- ->get();
- return array($criterion);
- }
-
- public function delete()
-
-
- {
-
- Log::info(Input::all());
- Log::info("LLEGAMOS??");
- $number_of_rows = DB::delete("delete from criteria where id = ?", array(Input::get('criterion_delete')));
-
- if ($number_of_rows <= 0) {
- $message = '<p>Error deleting Criterion:</p><ul>';
-
-
-
- $message .= '</ul>';
-
- /** Send error message and old data */
- Session::flash('status', 'danger');
- Session::flash('message', $message);
- } else {
- $message = '<p>Criterion deleted!</p><ul>';
-
-
-
- $message .= '</ul>';
-
- /** Send error message and old data */
- Session::flash('status', 'success');
- Session::flash('message', $message);
- }
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }
- public function isCriterionUnique($input, $existing_criterion = NULL)
- {
- // dd($input);
- Log::info('isCriterionUnique');
-
- if (Input::get('program_id') != 0)
- $program_id = $input['program_id'];
- else
- $program_id = NULL;
-
- $outcomes = [];
- $objectives = [];
- foreach ($input['objective_id'] as $objective) {
- $parentesis = array('(', ')');
- $outcome_objective = str_replace($parentesis, '', $objective);
- $outcomes[] = $outcome_objective[0];
- $objectives[] = $outcome_objective[1];
- }
- $scales = [];
- foreach ($input['scale_description'] as $scale) {
- $existing_scale = DB::table('scales')->where('description', $scale)
- ->first();
- if (!$existing_scale) return true;
- $scales[] = $existing_scale->id;
- }
-
-
- $saved_criterion = DB::table('criteria')
- ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
- ->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
-
- ->join('criterion_scale', 'criterion_scale.criterion_id', '=', 'criteria.id')
- ->whereIn('program_id', $input['program_id'])
- ->whereIn('objective_id', $objectives)
- ->whereIn('outcome_id', $outcomes)
- ->where('name', '=', $input['name'])
- ->where('subcriteria', '=', $input['subcriteria'])
- ->whereIn('scale_id', $scales)
- ->where('num_scales', $input['number_of_scales'])
- ->where('max_score', $input['maximum_score'])
-
- ->first();
-
-
-
-
-
-
- if ($saved_criterion)
- return false;
- else
- return true;
- }
-
- private function cleanInput()
- {
- $clean_input = array();
-
- $clean_input['name'] = trim(preg_replace('/\t+/', '', Input::get('name')));
-
-
- $trimmed = trim(preg_replace('/\t+/', '', Input::get('subcriteria')));
-
- Log::info('trimmed 1 -->' . $trimmed . '<--');
-
-
- if ($trimmed == '') {
- $trimmed = NULL;
- } else {
- $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
- }
-
- Log::info('trimmed 2 -->' . $trimmed . '<--');
-
-
- $clean_input['subcriteria'] = $trimmed;
- $clean_input['outcome_id'] = Input::get('outcome');
-
-
-
- $clean_input['objective_id'] = Input::get('objective');
-
-
-
-
-
- $clean_input['program_id'] = Input::get('program_id');
-
- $clean_input['copyright'] = trim(preg_replace('/\t+/', '', Input::get('copyright')));
- $clean_input['notes'] = trim(preg_replace('/\t+/', '', Input::get('notes')));
- $clean_input['maximum_score'] = (int) Input::get('maximum_score');
-
- $clean_input['scale_description'] = Input::get('Scales');
-
-
- $clean_input['number_of_scales'] = sizeof($clean_input['scale_description']);
-
-
- return $clean_input;
- }
-
- private function makeValidator($clean_input)
- {
- if (isset($clean_input['scale_description'][0])) {
- $scale = $clean_input['scale_description'][0];
- } else {
- $scale = 0;
- }
- if (isset($clean_input['program_id'][0])) {
- $program_id = $clean_input['program_id'][0];
- } else {
- $program_id = NULL;
- }
-
- if (isset($clean_input['objective_id'][0]) && $clean_input['objective_id'][0] != '0') {
- $objective_id = $clean_input['objective_id'][0];
- Log::info('Estamos');
- } else {
- $objective_id = NULL;
- }
- return Validator::make(
- array(
- 'name' => $clean_input['name'],
- 'subcriteria' => $clean_input['subcriteria'],
- // 'outcome_id' => $clean_input['outcome_id'],
- 'notes' => $clean_input['notes'],
- 'copyright' => $clean_input['copyright'],
- 'maximum_score' => $clean_input['maximum_score'],
- 'scales' => $scale,
- 'objective_id' => $objective_id,
- 'program_id' => $program_id,
- ),
- array(
- 'name' => 'required|string',
- 'subcriteria' => 'string',
- // 'outcome_id' => 'required|array',
- 'scales' => 'required|string',
- 'notes' => 'string',
- 'copyright' => 'string',
- 'maximum_score' => 'required|integer',
- 'objective_id' => 'required|string',
- 'program_id' => 'required|integer'
- )
-
- );
- }
-
- /**
- * Create a new criterion.
- *
- * @return Redirect Redirect back to form page
- */
- public function create()
- {
- $clean_input = $this->cleanInput();
-
- Log::info(json_encode($clean_input));
-
- /** Validation rules */
- $validator = $this->makeValidator($clean_input);
-
- /** If validation fails */
- if ($validator->fails()) {
- /** Prepare error message */
- $message = '<p>Error(s) creating a new Criterion:</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('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- // Log::info(Input::all());
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- } else {
- // Check criterion uniqueness
- if (!$this->isCriterionUnique($clean_input)) {
- /** Send error message and old data*/
- Session::flash('status', 'danger');
- Session::flash('message', 'This criterion is a duplicate of an already saved criterion because its name and associated program are the same.');
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }
-
- /** Instantiate new criterion */
- $criterion = new Criterion;
- $criterion->name = $clean_input['name'];
- $criterion->subcriteria = $clean_input['subcriteria'];
-
-
- //gabriel añadió aqui
-
- $criterion->num_scales = sizeof($clean_input['scale_description']);
- $criterion->max_score = $clean_input['maximum_score'];
-
- if (Input::get('copyright'))
- $criterion->copyright = $clean_input['copyright'];
-
- if (Input::get('notes'))
- $criterion->notes = $clean_input['notes'];
-
-
-
- /** If criterion is saved, send success message */
- Log::info(Input::all());
- if ($criterion->save()) {
-
- $criterionId = $criterion->id;
- $parentesis = array('(', ')');
-
- foreach ($clean_input['objective_id'] as $objective_id) {
-
- $outcome_objective = str_replace($parentesis, '', $objective_id);
-
- $outcome_objective = explode(',', $outcome_objective);
- $cobo_id = DB::table('criterion_objective_outcome')
- ->insertGetId(array(
- "objective_id" => $outcome_objective[1],
- "outcome_id" => $outcome_objective[0],
- "criterion_id" => $criterionId
- ));
-
-
- foreach ($clean_input['program_id'] as $program_id) {
- DB::table('program_criterion_objective_outcome')
- ->insert(array(
- 'program_id' => $program_id,
- 'cri_obj_out_id' => $cobo_id
- ));
- }
- //DB::insert("insert into `criterion_objective_outcome` (`objective_id`, `outcome_id`, `criterion_id`) values ({$outcome_objective[1]},{$outcome_objective[0]}, {$criterionId})");
-
- }
-
-
- for ($i = 0; $i < sizeof($clean_input['scale_description']); $i++) {
-
- $existing_scale = DB::table('scales')->where('description', $clean_input['scale_description'][$i])
- ->first();
- if ($existing_scale) {
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$existing_scale->id},{$i})");
- } else {
- $scale = new Scale;
-
- $position = $i;
- $scale->description = $clean_input['scale_description'][$i];
-
-
- if ($scale->save()) {
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$scale->id}, {$position})");
- } else {
- Session::flash('status', 'danger');
- Session::flash('message', '<p>Error creating the Scales</p>');
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }
- }
- }
-
- /* $role = Auth::user()->role;
- switch ($role) {
- case 1:
- $program_ids = DB::table('criterion_objective_outcome')
- ->join('objective_program', 'criterion_objective_outcome.objective_id', '=', 'objective_program.program_id')
- ->where('criterion_id', $criterionId)
- ->select('program_id')
- ->distinct()
- ->lists('program_id');
- break;
- case 2:
- $program_ids = DB::table('criterion_objective_outcome')
- ->join('objective_program', 'criterion_objective_outcome.objective_id', '=', 'objective_program.program_id')
- ->join('programs', 'programs.id', '=', 'objective_program.program_id')
- ->where('criterion_id', $criterionId)
- ->where('programs.school_id', Auth::user()->school_id)
- ->select('program_id')
- ->distinct()
- ->lists('program_id');
-
- break;
-
- case 3:
-
- $program_ids = DB::table('program_user')
- ->where('user_id', Auth::user()->id)
- ->lists('program_id');
-
- break;
- }*/
-
-
- //foreach ($clean_input['program_id'] as $program_id) {
- // DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
- //}
-
- Session::flash('status', 'success');
- Session::flash('message', 'Criterion created: "' . $criterion->name . '".');
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }
-
- /** If saving fails, send error message and old data */
- else {
- Session::flash('status', 'danger');
- Session::flash('message', '<p>Error creating Criterion. Please try again later.</p>');
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }
- }
- }
-
-
-
- public function edit()
- {
- $title = "Criteria";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->lists('name', 'id');
-
- //$schools = School::orderBy('name', 'ASC')->get();
- // $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
-
-
- // $objectives = DB::table('objectives')->orderBy('text', 'ASC')->lists('text', 'id');
-
- $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;
- }
- //Log::info($userProgram);
- $title = "Criteria";
- $outcomes = Outcome::whereNull("deactivation_date")->orderBy('name', 'ASC')->lists('name', 'id');
-
- //$criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
- $programs = Program::whereIn("id", $program_ids)->get();
- return View::make('local.managers.shared.criteria', compact('title', 'outcomes', 'programs', 'objectives'));
-
-
-
-
-
-
- // return View::make('local.managers.shared.criteria', compact('title', 'outcomes', 'schools', 'criteria', 'programs', 'objectives'));
- }
-
- private function cleanInputEdit()
- {
- $clean_input = array();
-
- $clean_input['name'] = trim(preg_replace('/\t+/', '', Input::get('name')));
-
-
- $trimmed = trim(preg_replace('/\t+/', '', Input::get('subcriteria')));
-
- Log::info('trimmed 1 -->' . $trimmed . '<--');
-
-
- if ($trimmed == '') {
- $trimmed = NULL;
- } else {
- $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
- }
-
- Log::info('trimmed 2 -->' . $trimmed . '<--');
-
-
- $clean_input['subcriteria'] = $trimmed;
- $clean_input['outcome_id'] = Input::get('outcome');
-
-
-
- $clean_input['objective_id'] = Input::get('objective');
-
-
-
-
- $clean_input['program_id'] = Input::get('program_id');
-
- $clean_input['copyright'] = trim(preg_replace('/\t+/', '', Input::get('copyright')));
- $clean_input['notes'] = trim(preg_replace('/\t+/', '', Input::get('notes')));
- $clean_input['maximum_score'] = (int) Input::get('maximum_score');
- //$clean_input['scale_title'] = Input::get('assoc_title');
- $clean_input['scale_description'] = Input::get('Scales');
- $clean_input['number_of_scales'] = sizeof($clean_input['scale_description']);
-
-
- return $clean_input;
- }
-
- public function changeStatus()
- {
- $criterion_id = Input::get('criterion_id');
- $criterion = Criterion::find($criterion_id);
-
- if (!$criterion->deleted_at) {
- $criterion->deleted_at = date('Y-m-d H:i:s');
- if ($criterion->save())
- return "deleted";
- else return 'error';
- } else {
- $criterion->deleted_at = NULL;
- if ($criterion->save())
- return "activated";
- else return 'error';
- }
- }
- public function update()
- {
- $criterion = Criterion::withTrashed()->find(Input::get('id'));
-
- $clean_input = $this->cleanInputEdit();
-
- /** Validation rules */
- $validator = $this->makeValidator($clean_input);
-
- /** If validation fails */
- if ($validator->fails()) {
- /** Prepare error message */
- $message = 'Error(s) updating the Criterion: <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('criteria')->withInput();
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- } else {
-
- // // Check criterion uniqueness
- /*if (!$this->isCriterionUnique($clean_input, $criterion)) {
- /** Send error message and old data */
- /*Session::flash('status', 'danger');
- Session::flash('message', 'This criterion is a duplicate of an already saved criterion because its name, assoaciated school or program, and progress indicators are the same.');
- $role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }
- }*/
-
- /** Set info */
- $criterion->name = $clean_input['name'];
- $criterion->subcriteria = $clean_input['subcriteria'];
-
- $criterion->num_scales = $clean_input['number_of_scales'];
- $criterion->max_score = $clean_input['maximum_score'];
-
-
-
-
-
- // Set program
- /*
- if (Input::get('program_id') != 0)
- $criterion->program_id = Input::get('program_id');
- else
- $criterion->program_id = NULL;*/
-
- // Set status
- if (Input::get('status') == 0)
- $criterion->deleted_at = date('Y-m-d H:i:s');
- else
- $criterion->deleted_at = NULL;
-
- if (Input::get('copyright'))
- $criterion->copyright = $clean_input['copyright'];
- else
- $criterion->copyright = NULL;
-
- if (Input::get('notes'))
- $criterion->notes = $clean_input['notes'];
- else
- $criterion->notes = NULL;
-
- /** If criterion is updated, send success message */
- $parentesis = array('(', ')');
- if ($criterion->save()) {
- $criterionId = $criterion->id;
- DB::table('criterion_objective_outcome as cobo')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
- ->where('cobo.criterion_id', $criterionId)
- ->delete();
- // DB::delete("delete from `criterion_objective_outcome` where `criterion_id` ={$criterionId}");
- DB::delete("delete from `program_criterion` where `criterion_id` ={$criterionId}");
-
- foreach ($clean_input['objective_id'] as $objective_id) {
-
- $outcome_objective = str_replace($parentesis, '', $objective_id);
-
- $outcome_objective = explode(',', $outcome_objective);
- $cobo_id = DB::table('criterion_objective_outcome')
- ->insertGetId(array(
- "objective_id" => $outcome_objective[1],
- "outcome_id" => $outcome_objective[0],
- "criterion_id" => $criterionId
- ));
-
- foreach ($clean_input['program_id'] as $program_id) {
- DB::table('program_criterion_objective_outcome')
- ->insert(array(
- 'program_id' => $program_id,
- 'cri_obj_out_id' => $cobo_id
- ));
- }
- }
-
- /*DB::delete("delete from `scales` where id in (select scale_id id from criterion_scale where criterion_id = {$criterionId})");
- */
- DB::delete("delete from criterion_scale where criterion_id = {$criterionId}");
- for ($i = 0; $i < sizeof($clean_input['scale_description']); $i++) {
-
- $existing_scale = DB::table('scales')->where('description', $clean_input['scale_description'][$i])
- ->first();
- if ($existing_scale) {
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$existing_scale->id},{$i})");
- } else {
- $scale = new Scale;
-
- $position = $i;
- $scale->description = $clean_input['scale_description'][$i];
-
-
- if ($scale->save()) {
- DB::insert("insert into `criterion_scale` (`criterion_id`, `scale_id`, `position`) values({$criterionId},{$scale->id}, {$position})");
- } else {
- Session::flash('status', 'danger');
- Session::flash('message', '<p>Error creating the Scales</p>');
- return Redirect::to('criteria')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }*/
- }
- }
- }/*
- switch ($role) {
- case 1:
- $program_ids = DB::table('criterion_objective_outcome')
- ->join('objective_program', 'criterion_objective_outcome.objective_id', '=', 'objective_program.program_id')
- ->where('criterion_id', $criterionId)
- ->select('program_id')
- ->distinct()
- ->lists('program_id');
- break;
- case 2:
- $program_ids = DB::table('criterion_objective_outcome')
- ->join('objective_program', 'criterion_objective_outcome.objective_id', '=', 'objective_program.program_id')
- ->join('programs', 'programs.id', '=', 'objective_program.program_id')
- ->where('criterion_id', $criterionId)
- ->where('programs.school_id', Auth::user()->school_id)
- ->select('program_id')
- ->distinct()
- ->lists('program_id');
-
- break;
-
- case 3:
-
- $program_ids = DB::table('program_user')
- ->where('user_id', Auth::user()->id)
- ->lists('program_id');
-
- break;
- }*/
- //foreach ($clean_input['program_id'] as $program_id) {
- // DB::insert("insert into `program_criterion` (`criterion_id`, `program_id`) values({$criterionId},{$program_id})");
- //}
-
-
-
- Session::flash('status', 'success');
- Session::flash('message', 'Updated criterion: "' . $criterion->name . '"');
- return Redirect::to('criteria')->withInput();
- /*$role = Auth::user()['role'];
- switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }*/
- }
-
- /** If saving fails, send error message and old data */
- else {
- Session::flash('status', 'danger');
- Session::flash('message', 'Error updating the Criterion. Please try again later.');
- return Redirect::to('criteria')->withInput();
- $role = Auth::user()['role'];
- /*switch ($role) {
- case 1:
- return Redirect::to('criteria')->withInput();
-
- case 2:
- return Redirect::to('school-criteria')->withInput();
-
- case 3:
- return Redirect::to('program-criteria')->withInput();
- }*/
- }
- }
- }
-
- public function index()
- {
- // 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 = "Learning Outcomes and Criteria";
- $outcomes = Outcome::orderBy('name', 'ASC')->get();
- // $outcomes = DB::table('outcomes')
- // ->orderBy('name', 'asc')
- // ->get();
- $schools = School::orderBy('name', 'ASC')->get();
- // $schools = DB::table('schools')
- // ->orderBy('name', 'asc')
- // ->get();
- $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
- // $criteria = DB::table('criteria')
- // ->orderBy('name', 'asc')
- // ->get();
-
- // se annadio la nueva variable
- return View::make('global.view-learning-outcomes-criteria', compact('title', 'outcomes', 'schools', 'criteria', 'semesters'));
- }
-
-
- // copie index() y lo edite
- public function objectivesIndex()
- {
- if (Auth::user()->role == 1) {
- //buscar todos los objetivos
- /*$objectives = DB::table('program_user')
- ->join('objective_program', 'objective_program.program_id', '=', 'program_user.program_id')
- ->join('objectives', 'objectives.id', '=', 'objective_program.objective_id')
- ->join('programs', 'programs.id', '=', 'program_user.program_id')
- ->select('objectives.id', 'objectives.text', 'programs.name')
- ->orderBy('objectives.text', 'asc')
- ->get();*/
-
- $objectives = DB::table('objectives')
- ->where('objectives.active', 1)
- ->orderBy('objectives.text', 'asc')
- ->get();
- } elseif (Auth::user()->role == 2) {
- //buscar los objetivos de la departamento (school)
- /*$objectives = DB::table('program_user')
- ->join('objective_program', 'objective_program.program_id', '=', 'program_user.program_id')
- ->join('objectives', 'objectives.id', '=', 'objective_program.objective_id')
- ->join('programs', 'programs.id', '=', 'program_user.program_id')
- ->where('programs.school_id', Auth::user()->school_id)
- ->select('objectives.id', 'objectives.text', 'programs.name')
- ->orderBy('objectives.text', 'asc')
- ->get();
- */
- $objectives = DB::table('objectives')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->join('programs', 'programs.id', '=', 'objective_program.program_id')
- ->where('programs.school_id', Auth::user()->school_id)
- ->where('objectives.active', 1)
- ->orderBy('objectives.text', 'asc')
- ->select('objectives.id', 'objectives.text')
- ->distinct()
- ->get();
- } elseif ((Auth::user()->role == 3) || (Auth::user()->role == 4)) {
- //buscar los objetivos de los programas cuales el profesor esta
- $objectives = DB::table('program_user')
- ->join('objective_program', 'objective_program.program_id', '=', 'program_user.program_id')
- ->join('objectives', 'objectives.id', '=', 'objective_program.objective_id')
- ->join('programs', 'programs.id', '=', 'program_user.program_id')
- ->where('program_user.user_id', Auth::user()->id)
- ->where('objectives.active', 1)
- ->select('objectives.id', 'objectives.text')
- ->distinct()
-
- ->orderBy('objectives.text', 'asc')
- ->get();
- }
-
- $title = "Learning Objectives and Criteria";
-
- return View::make('global.view-objectives-criteria', compact('title', 'objectives'));
- }
-
- public function destroy()
- {
- $criterion = Criterion::withTrashed()->find(Input::get('id'));
- if (!$criterion->trashed()) {
- try {
- $criterion->delete();
- Session::flash('status', 'success');
- Session::flash('message', 'Deactivated criterion: "' . $criterion->name . '"');
- } catch (Exception $e) {
- Session::flash('status', 'danger');
- Session::flash('message', 'Error deactivating criterion."' . $criterion->name . '"');
- }
- return Redirect::to('criteria')->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 {
- try {
- $criterion->restore();
- Session::flash('status', 'success');
- Session::flash('message', 'Reactivated criterion: "' . $criterion->name . '"');
- } catch (Exception $e) {
- Session::flash('status', 'danger');
- Session::flash('message', 'Error reactivating criterion: "' . $criterion->name . '".');
- }
- return Redirect::to('criteria')->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();
- }*/
- }
- }
-
- public function filterCriteria()
- {
- switch (Input::get('filter')) {
- case 'all':
- return Criteria::all();
- break;
-
- case 'school':
- // If scoord
- if (Auth::user()->role == '2') {
-
- // Fetch all the programs whose school is the user's
- $program_ids = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
-
- // Return all criteria belonging to any of those programs
- return Criterion::whereIn('program_id', $program_ids)
- ->orderBy('name', 'ASC')
- ->get();
- }
-
- // If pcoord
- else {
- // Fetch all the programs from the user's school;
- $program_ids = DB::table('programs')->where('school_id', Auth::user()->programs[0]->school->id)->lists('id');
-
- return Criterion::whereIn('program_id', $program_ids)
- ->orderBy('name', 'ASC')
- ->get();
- }
-
- break;
-
- case 'program':
- return Criterion::whereIn('program_id', Auth::user()->programs->lists('id'))
- ->orderBy('name', 'ASC')
- ->get();
- break;
-
- default:
- return Criteria::all();
- break;
- }
- }
-
- public function fetchFromTemplate()
- {
-
- $role = Auth::user()->role;
-
- $criterion_id = Input::get('criterion_id');
-
- switch ($role) {
- case 1:
- $program_ids = Program::select('programs.*')->lists('id');
- break;
- case 2:
- $program_ids = Program::where("school_id", Auth::user()->school_id)->lists('id');
- break;
-
- case 3:
- case 4:
- $program_ids = Program::whereIn('id', Auth::user()->programs->lists('id'));
- break;
- }
- $outcomes_paired_ids = DB::table('criterion_objective_outcome as cobo')
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
- ->whereIn("program_id", $program_ids)
- ->where('criterion_id', $criterion_id)
- ->select('cobo.outcome_id')
- ->distinct()
- ->lists('cobo.outcome_id');
-
-
- $json = [];
- $json['outcomes'] = $outcomes_paired_ids;
- $json['objectives_available'] = DB::table('objectives')
- ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
- ->join('outcomes', 'outcomes.id', '=', 'outcome_id')
- ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
- ->whereIn("outcome_id", $outcomes_paired_ids)
- ->whereIn("program_id", $program_ids)
- ->where('objectives.id', '<>', 0)
- ->select('objectives.*')
- ->distinct()
-
- ->get();
- $json['objectives_selected'] = DB::table('objectives')
- ->join('criterion_objective_outcome as cobo', 'cobo.objective_id', '=', 'objectives.id')
- ->join('outcomes', 'outcomes.id', '=', 'outcome_id')
-
- ->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
- ->whereIn('outcome_id', $outcomes_paired_ids)
- ->whereIn("program_id", $program_ids)
- ->where('criterion_id', $criterion_id)
- ->where('objective_id', '<>', 0)
- ->select('objectives.*')
- //->groupBy('objectives.id', 'outcome_id')
- ->distinct()
- ->get();
-
-
-
- return $json;
- }
- }
|