Нет описания

AnnualPlansController.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. class AnnualPlansController extends \BaseController {
  3. /**
  4. * Checks whether a user has permission to view a page in this controller
  5. *
  6. * @var User $user Authenticated user
  7. */
  8. private function userHasAccess($program_id)
  9. {
  10. $user = Auth::user();
  11. switch ($user->role) {
  12. case '3':
  13. $programs = $user->programs->lists('id');
  14. // If program does not belong to user, show 403
  15. if(!in_array($program_id, $programs))
  16. return false;
  17. break;
  18. case '2':
  19. $programs = Program::where('school_id', $user->school_id)->lists('id');
  20. // If program is not in user's school, show 403
  21. if(!in_array($program_id, $programs))
  22. return false;
  23. break;
  24. case '4':
  25. return false;
  26. }
  27. return true;
  28. }
  29. /**
  30. * Lists annual plans by year and program
  31. * @var string $title Title for page
  32. * @var Program $programs Collection of programs user has access to
  33. * @var User $user Authenticated user
  34. * @var Quinquennium $quinquenniums All current or past quinquenniums
  35. * @var Quinquennium $current_quinquennium Current quinquennium
  36. */
  37. public function index()
  38. {
  39. $title = 'Annual Plans';
  40. $user = Auth::user();
  41. $quinquenniums = Quinquennium::where('start_date','<=', date('Y-m-d'))->get();
  42. $current_quinquennium = Quinquennium::
  43. where('start_date', '<=', date('Y-m-d'))
  44. ->where('end_date', '>=', date('Y-m-d'))
  45. ->first();
  46. switch ($user->role) {
  47. case '1':
  48. $programs = Program::all();
  49. break;
  50. case '2':
  51. $programs = Program::where('school_id', $user->school_id)->get();
  52. break;
  53. case 3:
  54. $programs = $user->programs;
  55. break;
  56. default:
  57. App::abort('404');
  58. break;
  59. }
  60. return View::make('local.managers.shared.index_annual_plans', compact('title', 'quinquenniums', 'programs', 'current_quinquennium'));
  61. }
  62. /**
  63. * Page to create a new plan for the current quinquennium
  64. * @var string $title Title for page
  65. * @var Program $programs Collection of programs user has access to
  66. * @var Outcome $outcomes List of outcomes ordered by name
  67. * @var User $user Currently logged user
  68. * @var Course $courses Courses for a particular program
  69. */
  70. public function create(Program $program)
  71. {
  72. $title = 'New Annual Plan for '.$program->name;
  73. $user = Auth::user();
  74. $outcomes = Outcome::orderBy('name')->get();
  75. $current_quinquennium = Quinquennium::
  76. where('start_date', '<=', date('Y-m-d'))
  77. ->where('end_date', '>=', date('Y-m-d'))
  78. ->first();
  79. $courses = Course::
  80. select('id', 'code', 'number', 'name')
  81. ->where('program_id', $program->id)
  82. ->groupBy('name')
  83. ->orderBy('code','ASC')
  84. ->orderBy('number','ASC')
  85. ->orderBy('name','ASC')
  86. ->get();
  87. // Check if user can create a plan
  88. if(!$this->userHasAccess($program->id))
  89. {
  90. return View::make('global.403');
  91. }
  92. return View::make('local.managers.shared.create_annual_plan', compact('title', 'program', 'current_quinquennium', 'outcomes', 'courses'));
  93. }
  94. }