whereNull('program_id')->get(); $schools = School::with('programs.templates') ->orderBy('name') ->get(); $templates = Template::orderBy('name')->get(); return View::make('local.managers.admins.rubric_list', compact('title', 'global_templates', 'schools', 'templates')); } public function schoolCoordinatorIndex() { $title = 'Rubric List'; $global_templates = Template::whereNull('school_id')->whereNull('program_id')->get(); $schools = School::with('programs.templates') ->orderBy('name') ->get(); $templates = Template::orderBy('name')->get(); return View::make('local.managers.admins.rubric_list', compact('title', 'global_templates', 'schools', 'templates')); } public function show(Template $template) { $title = $template->name; return View::make('local.managers.admins.view_template', compact('template', 'title')); } public function onLoadFetch() { $json_to_send = []; $template_id = Input::get('id'); $json_to_send["criteria"] = DB::table("criteria")->join('template_criterion', 'template_criterion.criterion_id', '=', 'criteria.id') ->where("template_criterion.template_id", '=', $template_id) ->get(); Log::info($json_to_send["criteria"]); foreach ($json_to_send['criteria'] as $criteria) { $json_to_send['scales'][$criteria->criterion_id] = DB::table("scales")->join('template_criterion_scale', 'template_criterion_scale.scale_id', '=', 'scales.id') ->where("template_criterion_scale.template_criterion_id", '=', $criteria->id)->orderBy('position', 'ASC')->get(); } return json_encode($json_to_send); } /** * Show the form for creating a new rubric * * @return Response */ public function newTemplate() { $title = "Rubric Builder"; $templates = Template::orderBy('name', 'ASC')->get(); $outcomes = Outcome::where("deactivation_date", '=', null)->orderBy('name', 'ASC')->get(); $criteria = Criterion::orderBy('name', 'ASC')->get(); $schools = School::orderBy('name', 'ASC')->get(); $role = Auth::user()->role; $templates = NULL; $programs = NULL; // Returns templates depending on the type of user if ($role == 1) { $templates = Template::orderBy('name', 'ASC')->get(); $programs = Program::orderBy('name', 'ASC')->get(); } elseif ($role == 2) { $templates = Template::where('school_id', '=', Auth::user()->school->id)->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get(); $programs = Auth::user()->school->programs; } elseif ($role == 3) { $templates = Template::where('school_id', '=', Auth::user()->programs[0]->school->id)->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get(); $programs = Auth::user()->programs()->get(); } return View::make('local.managers.shared.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'schools', 'programs')); } /** * Save a new rubric * * @return Response */ public function create() { $template = new Template; $template->name = Input::get('name'); $template->is_visible = Input::get('is_visible'); $template->expected_percentage = Input::get('expected_percentage'); $template->expected_points = Input::get('expected_points'); // If user can set the school (that is, if school_id is not undefined) // set the school id or set to null if (is_numeric(Input::get('school_id'))) { if (Input::get('school_id') != 0) $template->school_id = Input::get('school_id'); elseif (Input::get('school_id') == 0) $template->school_id = NULL; } // If user can set the program (that is, if program_id is not undefined) // set the program id or set to null if (is_numeric(Input::get('program_id'))) { if (Input::get('program_id') != 0) $template->program_id = Input::get('program_id'); elseif (Input::get('program_id') == 0) $template->program_id = NULL; } // If the user is any coordinator, set the school id // If the user is a program coordinator, also set program id switch (Auth::user()->role) { case 2: $template->school_id = Auth::user()->school->id; break; case 3: $template->school_id = Auth::user()->programs[0]->school->id; $template->program_id = Auth::user()->programs[0]->id; break; } $scales = Input::get('scales'); $criteria = Input::get('criteria'); $max_score = Input::get('max_score'); $copyright = Input::get('copyright'); $notes = Input::get('notes'); Log::info($scales); Log::info($criteria); Log::info($copyright); Log::info($notes); $template->num_scales = count($scales[0]); $template->max_score = $max_score; if ($template->save()) { $templateId = $template->id; foreach ($criteria as $index => $criterion_id) { $note = $notes[$index]; $copy = $copyright[$index]; if ($copy == "Empty") $copy = NULL; if ($note == "Empty") $note = NULL; DB::insert("insert into template_criterion (`template_id`,`criterion_id`, `copyright`, `notes`) values ({$templateId},{$criterion_id}, '{$copy}', '{$note}')"); $template_criterion_id = DB::table('template_criterion')->where('template_id', '=', $templateId) ->where('criterion_id', '=', $criterion_id)->first(); for ($i = 0; $i < count($scales[$index]); $i++) { $scale = Scale::where('description', '=', $scales[$index][$i])->first(); Log::info($scale); if ($scale) { DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})"); DB::commit(); } else { $scale = new Scale; $scale->description = $scales[$index][$i]; if ($scale->save()) { DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})"); DB::commit(); } else { Session::flash('status', 'danger'); Session::flash('message', 'Rubric could not be created.'); } } } } Session::flash('status', 'success'); Session::flash('message', 'Rubric created. You can now select it from the list.'); } else { Session::flash('status', 'danger'); Session::flash('message', 'Rubric could not be created.'); } } /** * Return a specific template * * @return Template */ public function fetch() { $template_info = []; $template_info['template'] = Template::find(Input::get('id')); $template_info['criterion'] = DB::table('criteria') ->join('template_criterion', 'template_criterion.criterion_id', '=', 'criteria.id') ->where("template_criterion.template_id", '=', Input::get('id')) ->get(); foreach ($template_info['criterion'] as $temp_crit) { $template_info['scales'][$temp_crit->id] = DB::table('scales') ->join('template_criterion_scale', 'template_criterion_scale.scale_id', '=', 'scales.id') ->where('template_criterion_scale.template_criterion_id', '=', $temp_crit->id) ->orderBy('position', 'ASC') ->get(); $outcomeID = DB::table('criterion_objective_outcome')->where('criterion_id', '=', $temp_crit->criterion_id) ->lists('outcome_id'); $outcomes = DB::table('outcomes')->whereIn('id', $outcomeID)->get(); $outcomeStr = ''; foreach ($outcomes as $key => $outcome) { $outcomeStr .= $outcome->name . ', '; } $outcomeStr = rtrim($outcomeStr, ','); $temp_crit->outcomes = $outcomeStr; } Log::info($template_info); return json_encode($template_info); } /** * Update the specified resource in storage. * * @return Response */ public function update() { $template = Template::find(Input::get('id')); $template->name = Input::get('name'); $template->is_visible = Input::get('is_visible'); $template->expected_percentage = Input::get('expected_percentage'); $template->expected_points = Input::get('expected_points'); // If user can set the school (that is, if school_id is not undefined) // set the school id or set to null if (is_numeric(Input::get('school_id'))) { if (Input::get('school_id') != 0) $template->school_id = Input::get('school_id'); elseif (Input::get('school_id') == 0) $template->school_id = NULL; } // If user can set the program (that is, if program_id is not undefined) // set the program id or set to null if (is_numeric(Input::get('program_id'))) { if (Input::get('program_id') != 0) $template->program_id = Input::get('program_id'); elseif (Input::get('program_id') == 0) $template->program_id = NULL; } switch (Auth::user()->role) { case 2: $template->school_id = Auth::user()->school->id; break; case 3: $template->school_id = Auth::user()->programs[0]->school->id; $template->program_id = Auth::user()->programs[0]->id; break; } $scales = Input::get('scales'); $criteria = Input::get('criteria'); $max_score = Input::get('max_score'); $copyright = Input::get('copyright'); $notes = Input::get('notes'); Log::info($scales); Log::info(Input::all()); $template->num_scales = count($scales[0]); $template->max_score = $max_score; //$division = $max_score / count($scales[0]); if ($template->save()) { $templateId = $template->id; DB::delete("delete from template_criterion where template_id ={$template->id}"); foreach ($criteria as $index => $criterion_id) { $copy = $copyright[$index]; $note = $notes[$index]; if ($copy == 'Empty') $copy = NULL; if ($note == 'Empty') $note = NULL; DB::insert("insert into template_criterion (`template_id`,`criterion_id`, `copyright`, `notes`) values ({$templateId},{$criterion_id}, '{$copy}', '{$note}')"); $template_criterion_id = DB::table('template_criterion')->where('template_id', '=', $templateId) ->where('criterion_id', '=', $criterion_id)->first(); DB::delete("delete from template_criterion_scale where template_criterion_id ={$template_criterion_id->id}"); for ($i = 0; $i < count($scales[$index]); $i++) { $scale = Scale::where('description', '=', $scales[$index][$i]) //->where('max_score', '=', ($division * ($i + 1))) //->where("min_score", '=', (1 + ($division * $i))) ->first(); Log::info($scale); if ($scale) { DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})"); DB::commit(); } else { $scale = new Scale; $scale->description = $scales[$index][$i]; //$scale->min_score = 1 + ($division * $i); //$scale->max_score = ($division * ($i + 1)); if ($scale->save()) { DB::insert("insert into `template_criterion_scale` (`template_criterion_id`, `scale_id`, `position`) values ({$template_criterion_id->id},{$scale->id}, {$i})"); DB::commit(); } else { Session::flash('status', 'danger'); Session::flash('message', 'Rubric could not be created.'); } } } } Session::flash('status', 'success'); Session::flash('message', 'Rubric updated (' . date('m/d/y, h:i:s a') . ').'); } else { Session::flash('status', 'danger'); Session::flash('message', 'Rubric could not be updated (' . date('m/d/y, h:i:s a') . ').'); } } /** * Remove the specified resource from storage. * * @return Response */ public function destroy() { $template = Template::find(Input::get('id')); if ($template->delete()) { Session::flash('status', 'success'); Session::flash('message', 'Rubric deleted.'); } else { Session::flash('status', 'danger'); Session::flash('message', 'Rubric could not be deleted.'); } return; } public function printview($id) { try { $template = Template::find($id); $title = $template->name; if ($template->school_id != NULL) $school = $template->school->name; else $school = 'All Schools'; if ($template->program_id != NULL) $program = $template->program->name; else $program = 'All Programs'; return View::make('local.managers.shared.print_rubric', compact('title', 'template', 'school', 'program')); } catch (Exception $e) { Session::flash('status', 'danger'); Session::flash('message', $e->getMessage()); return Redirect::back(); } } }