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')); } /** * Show the form for creating a new rubric * * @return Response */ public function newTemplate() { $title = "Rubric Builder"; $templates = Template::orderBy('name', 'ASC')->get(); $outcomes = Outcome::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->contents = Input::get('contents'); $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'); Log::info($scales); Log::info($criteria); $template->num_scales = count($scales[0]); $template->max_score = $max_score; $division = $max_score / count($scales[0]); if ($template->save()) { $templateId = $template->id; foreach ($criteria as $index => $criterion_id) { DB::insert("insert into template_criterion (`template_id`,`criterion_id`) values ({$templateId},{$criterion_id})"); $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 = 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})"); } 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('new_criteria') ->join('template_criterion', 'template_criterion.criterion_id', '=', 'new_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(); } 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->contents = Input::get('contents'); $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 ($template->save()) { 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(); } } }