Нет описания

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. class TemplatesController extends \BaseController {
  3. /**
  4. * List all templates, grouped by program
  5. */
  6. public function index()
  7. {
  8. $title = 'Rubric List';
  9. $global_templates = Template::whereNull('school_id')->whereNull('program_id')->get();
  10. $schools = School::with('programs.templates')
  11. ->orderBy('name')
  12. ->get();
  13. $templates = Template::orderBy('name')->get();
  14. return View::make('local.managers.admins.rubric_list', compact('title', 'global_templates','schools', 'templates'));
  15. }
  16. public function schoolCoordinatorIndex()
  17. {
  18. $title = 'Rubric List';
  19. $global_templates = Template::whereNull('school_id')->whereNull('program_id')->get();
  20. $schools = School::with('programs.templates')
  21. ->orderBy('name')
  22. ->get();
  23. $templates = Template::orderBy('name')->get();
  24. return View::make('local.managers.admins.rubric_list', compact('title', 'global_templates','schools', 'templates'));
  25. }
  26. public function show(Template $template)
  27. {
  28. $title = $template->name;
  29. return View::make('local.managers.admins.view_template', compact('template', 'title'));
  30. }
  31. /**
  32. * Show the form for creating a new rubric
  33. *
  34. * @return Response
  35. */
  36. public function newTemplate()
  37. {
  38. $title= "Rubric Builder";
  39. $templates = Template::orderBy('name', 'ASC')->get();
  40. $outcomes = Outcome::orderBy('name', 'ASC')->get();
  41. $criteria = Criterion::orderBy('name', 'ASC')->get();
  42. $schools = School::orderBy('name', 'ASC')->get();
  43. $role = Auth::user()->role;
  44. $templates = NULL;
  45. $programs = NULL;
  46. // Returns templates depending on the type of user
  47. if( $role == 1)
  48. {
  49. $templates = Template::orderBy('name', 'ASC')->get();
  50. $programs = Program::orderBy('name', 'ASC')->get();
  51. } elseif ($role == 2)
  52. {
  53. $templates = Template::where('school_id', '=', Auth::user()->school->id )->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get();
  54. $programs = Auth::user()->school->programs;
  55. }
  56. elseif ($role == 3)
  57. {
  58. $templates = Template::where('school_id', '=', Auth::user()->programs[0]->school->id)->orWhere('school_id', '=', NULL)->orderBy('name', 'ASC')->get();
  59. $programs = Auth::user()->programs()->get();
  60. }
  61. return View::make('local.managers.shared.rubrics', compact('title', 'templates', 'outcomes', 'criteria', 'schools', 'programs'));
  62. }
  63. /**
  64. * Save a new rubric
  65. *
  66. * @return Response
  67. */
  68. public function create()
  69. {
  70. $template = new Template;
  71. $template->name = Input::get('name');
  72. $template->contents = Input::get('contents');
  73. $template->is_visible = Input::get('is_visible');
  74. $template->expected_percentage = Input::get('expected_percentage');
  75. $template->expected_points = Input::get('expected_points');
  76. // If user can set the school (that is, if school_id is not undefined)
  77. // set the school id or set to null
  78. if(is_numeric(Input::get('school_id')))
  79. {
  80. if(Input::get('school_id')!=0)
  81. $template->school_id = Input::get('school_id');
  82. elseif(Input::get('school_id')==0)
  83. $template->school_id = NULL;
  84. }
  85. // If user can set the program (that is, if program_id is not undefined)
  86. // set the program id or set to null
  87. if(is_numeric(Input::get('program_id')))
  88. {
  89. if(Input::get('program_id')!=0)
  90. $template->program_id = Input::get('program_id');
  91. elseif(Input::get('program_id')==0)
  92. $template->program_id = NULL;
  93. }
  94. // If the user is any coordinator, set the school id
  95. // If the user is a program coordinator, also set program id
  96. switch (Auth::user()->role) {
  97. case 2:
  98. $template->school_id = Auth::user()->school->id;
  99. break;
  100. case 3:
  101. $template->school_id = Auth::user()->programs[0]->school->id;
  102. $template->program_id = Auth::user()->programs[0]->id;
  103. break;
  104. }
  105. if($template->save())
  106. {
  107. Session::flash('status', 'success');
  108. Session::flash('message', 'Rubric created. You can now select it from the list.');
  109. }
  110. else
  111. {
  112. Session::flash('status', 'danger');
  113. Session::flash('message', 'Rubric could not be created.');
  114. }
  115. }
  116. /**
  117. * Return a specific template
  118. *
  119. * @return Template
  120. */
  121. public function fetch()
  122. {
  123. return Template::find(Input::get('id'));
  124. }
  125. /**
  126. * Update the specified resource in storage.
  127. *
  128. * @return Response
  129. */
  130. public function update()
  131. {
  132. $template = Template::find(Input::get('id'));
  133. $template->name = Input::get('name');
  134. $template->contents = Input::get('contents');
  135. $template->is_visible = Input::get('is_visible');
  136. $template->expected_percentage = Input::get('expected_percentage');
  137. $template->expected_points = Input::get('expected_points');
  138. // If user can set the school (that is, if school_id is not undefined)
  139. // set the school id or set to null
  140. if(is_numeric(Input::get('school_id')))
  141. {
  142. if(Input::get('school_id')!=0)
  143. $template->school_id = Input::get('school_id');
  144. elseif(Input::get('school_id')==0)
  145. $template->school_id = NULL;
  146. }
  147. // If user can set the program (that is, if program_id is not undefined)
  148. // set the program id or set to null
  149. if(is_numeric(Input::get('program_id')))
  150. {
  151. if(Input::get('program_id')!=0)
  152. $template->program_id = Input::get('program_id');
  153. elseif(Input::get('program_id')==0)
  154. $template->program_id = NULL;
  155. }
  156. if($template->save())
  157. {
  158. Session::flash('status', 'success');
  159. Session::flash('message', 'Rubric updated ('.date('m/d/y, h:i:s a').').');
  160. }
  161. else
  162. {
  163. Session::flash('status', 'danger');
  164. Session::flash('message', 'Rubric could not be updated ('.date('m/d/y, h:i:s a').').');
  165. }
  166. }
  167. /**
  168. * Remove the specified resource from storage.
  169. *
  170. * @return Response
  171. */
  172. public function destroy()
  173. {
  174. $template = Template::find(Input::get('id'));
  175. if($template->delete())
  176. {
  177. Session::flash('status', 'success');
  178. Session::flash('message', 'Rubric deleted.');
  179. }
  180. else
  181. {
  182. Session::flash('status', 'danger');
  183. Session::flash('message', 'Rubric could not be deleted.');
  184. }
  185. return;
  186. }
  187. public function printview($id)
  188. {
  189. try {
  190. $template = Template::find($id);
  191. $title = $template->name;
  192. if($template->school_id!=NULL)
  193. $school= $template->school->name;
  194. else
  195. $school = 'All Schools';
  196. if($template->program_id!=NULL)
  197. $program= $template->program->name;
  198. else
  199. $program = 'All Programs';
  200. return View::make('local.managers.shared.print_rubric', compact('title', 'template', 'school', 'program'));
  201. }
  202. catch (Exception $e) {
  203. Session::flash('status', 'danger');
  204. Session::flash('message', $e->getMessage());
  205. return Redirect::back();
  206. }
  207. }
  208. }