1 | <?php |
||
35 | class ViewController extends Controller { |
||
36 | |||
37 | /** |
||
38 | * @var IConfig |
||
39 | */ |
||
40 | private $config; |
||
41 | |||
42 | /** |
||
43 | * @var IURLGenerator |
||
44 | */ |
||
45 | private $urlGenerator; |
||
46 | |||
47 | /** |
||
48 | * @var IUserSession |
||
49 | */ |
||
50 | private $userSession; |
||
51 | |||
52 | /** |
||
53 | * @param string $appName |
||
54 | * @param IRequest $request an instance of the request |
||
55 | * @param IUserSession $userSession |
||
56 | * @param IConfig $config |
||
57 | * @param IURLGenerator $urlGenerator |
||
58 | */ |
||
59 | 24 | public function __construct($appName, IRequest $request, IUserSession $userSession, |
|
60 | IConfig $config, IURLGenerator $urlGenerator) { |
||
61 | 24 | parent::__construct($appName, $request); |
|
62 | 24 | $this->config = $config; |
|
63 | 24 | $this->userSession = $userSession; |
|
64 | 24 | $this->urlGenerator = $urlGenerator; |
|
65 | 24 | } |
|
66 | |||
67 | /** |
||
68 | * @NoAdminRequired |
||
69 | * @NoCSRFRequired |
||
70 | * |
||
71 | * @return TemplateResponse |
||
72 | */ |
||
73 | 8 | public function index() { |
|
74 | 8 | if ($this->needsAssetPipelineWarning()) { |
|
75 | 1 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
|
76 | } |
||
77 | |||
78 | 7 | $templateParameters = $this->getTemplateParams(); |
|
79 | |||
80 | 7 | $user = $this->userSession->getUser(); |
|
81 | 7 | $userId = $user->getUID(); |
|
82 | 7 | $emailAddress = $user->getEMailAddress(); |
|
83 | |||
84 | 7 | $initialView = $this->config->getUserValue($userId, $this->appName, 'currentView', null); |
|
85 | 7 | $skipPopover = $this->config->getUserValue($userId, $this->appName, 'skipPopover', 'no'); |
|
86 | 7 | $weekNumbers = $this->config->getUserValue($userId, $this->appName, 'showWeekNr', 'no'); |
|
87 | 7 | $firstRun = $this->config->getUserValue($userId, $this->appName, 'firstRun', null); |
|
88 | |||
89 | // the default view will be saved as soon as a user |
||
90 | // opens the calendar app, therefore this is a good |
||
91 | // indication if the calendar was used before |
||
92 | 7 | if ($firstRun === null) { |
|
93 | 2 | if ($initialView === null) { |
|
94 | 1 | $firstRun = 'yes'; |
|
95 | 1 | } else { |
|
96 | 1 | $this->config->setUserValue($userId, $this->appName, 'firstRun', 'no'); |
|
97 | 1 | $firstRun = 'no'; |
|
98 | } |
||
99 | 2 | } |
|
100 | |||
101 | 7 | if ($initialView === null) { |
|
102 | 1 | $initialView = 'month'; |
|
103 | 1 | } |
|
104 | |||
105 | 7 | return new TemplateResponse('calendar', 'main', array_merge($templateParameters, [ |
|
106 | 7 | 'initialView' => $initialView, |
|
107 | 7 | 'emailAddress' => $emailAddress, |
|
108 | 7 | 'skipPopover' => $skipPopover, |
|
109 | 7 | 'weekNumbers' => $weekNumbers, |
|
110 | 7 | 'firstRun' => $firstRun, |
|
111 | 7 | 'isPublic' => false, |
|
112 | 7 | 'isEmbedded' => false, |
|
113 | 7 | 'token' => '', |
|
114 | 7 | ])); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * @PublicPage |
||
119 | * @NoCSRFRequired |
||
120 | * |
||
121 | * @param string $token |
||
122 | * |
||
123 | * @return TemplateResponse |
||
124 | */ |
||
125 | 8 | public function publicIndexWithBranding($token) { |
|
126 | 8 | if ($this->needsAssetPipelineWarning()) { |
|
127 | 1 | return new TemplateResponse('calendar', 'main-asset-pipeline-unsupported'); |
|
128 | } |
||
129 | |||
130 | 7 | $templateParameters = $this->getTemplateParams(); |
|
131 | 7 | $publicTemplateParameters = $this->getPublicTemplateParameters($token); |
|
132 | 7 | $params = array_merge($templateParameters, $publicTemplateParameters); |
|
133 | 7 | $params['isEmbedded'] = false; |
|
134 | |||
135 | 7 | return new TemplateResponse('calendar', 'public', $params, 'base'); |
|
136 | } |
||
137 | |||
138 | /** |
||
139 | * @PublicPage |
||
140 | * @NoCSRFRequired |
||
141 | * |
||
142 | * @param string $token |
||
143 | * |
||
144 | * @return TemplateResponse |
||
145 | */ |
||
146 | public function publicIndexWithBrandingAndFancyName($token) { |
||
147 | return $this->publicIndexWithBranding($token); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @PublicPage |
||
152 | * @NoCSRFRequired |
||
153 | * |
||
154 | * @param string $token |
||
155 | * |
||
156 | * @return TemplateResponse |
||
157 | */ |
||
158 | 8 | public function publicIndexForEmbedding($token) { |
|
177 | |||
178 | /** |
||
179 | * @PublicPage |
||
180 | * @NoCSRFRequired |
||
181 | * |
||
182 | * @param string $token |
||
183 | * |
||
184 | * @return TemplateResponse |
||
185 | */ |
||
186 | public function publicIndexForEmbeddingLegacy($token) { |
||
189 | |||
190 | /** |
||
191 | * get common parameters used for all three routes |
||
192 | * @return array |
||
193 | */ |
||
194 | 21 | private function getTemplateParams() { |
|
220 | |||
221 | /** |
||
222 | * get common parameters for public sites |
||
223 | * @param string $token |
||
224 | * @return array |
||
225 | */ |
||
226 | 14 | private function getPublicTemplateParameters($token) { |
|
257 | |||
258 | /** |
||
259 | * check if we need to show the asset pipeline warning |
||
260 | * @return bool |
||
261 | */ |
||
262 | 24 | private function needsAssetPipelineWarning() { |
|
269 | } |
||
270 |