-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCalendarViewController.php
85 lines (73 loc) · 2.35 KB
/
CalendarViewController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
use Illuminate\Database\Eloquent\ModelNotFoundException;
/**
* Class CalendarViewController
* This controller is the main controller of the application. It handles the CRUD of all events.
*/
class CalendarViewController extends \BaseController
{
/**
* Display a calendar view to logged in user
* @return Response
*/
public function index($school_slug)
{
try {
$school = SchoolController::getSchoolBySlug($school_slug);
} catch (ModelNotFoundException $e) {
return Redirect::route('landing')->withErrors("School niet gevonden!");
}
$logged = Sentry::check();
$user = Sentry::getUser();
$uid = 0;
if ($logged) {
$uid == $user->getId();
}
$write = false;
$admin = false;
if ($logged && $user->school_id == $school->id) {
$write = true;
if (Sentry::getUser()->hasAccess('admin')) {
$admin = true;
}
}
$calendars = [];
$orgCalendars = Calendar::where('school_id', $school->id)->get();
// Loop through calendars to get all appointments
foreach ($orgCalendars as $calendar) {
$calendar->load("appointments");
$calendars[$calendar->id] = $calendar;
if (!$calendar->parent_id) {
$root = $calendar;
}
}
$userCalendars = [];
if ($logged) {
foreach ($user->calendars as $calendar) {
$userCalendars[$calendar->id] = $calendar->name;
}
}
return View::make('calendar.index')->with([
"school" => json_encode($school, JSON_NUMERIC_CHECK),
"user" => json_encode([
"id" => $uid,
"logged_in" => $logged,
"permissions" => [
"editor" => $write,
"admin" => $admin,
]
], JSON_NUMERIC_CHECK),
"org" => $school,
"root" => $root,
"calendars" => $calendars,
"editableCalendars" => $userCalendars,
]);
}
public function goToCalendar()
{
if (!Sentry::check()) {
return Redirect::route('landing');
}
return Redirect::route("orgs.index", [Sentry::getUser()->school->slug]);
}
}