Passed
Pull Request — master (#260)
by Kai
02:32
created
lib/Controller/PageController.php 2 patches
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 		try {
224 224
 			$poll = $this->eventMapper->findByHash($hash);
225 225
 		} catch (DoesNotExistException $e) {
226
-			return new TemplateResponse('polls', 'no.acc.tmpl', []);
226
+			return new TemplateResponse('polls', 'no.acc.tmpl', [ ]);
227 227
 		}
228 228
 		if ($poll->getType() === 0) {
229 229
 			$dates = $this->dateMapper->findByPoll($poll->getId());
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 			]);
256 256
 		} else {
257 257
 			User::checkLoggedIn();
258
-			return new TemplateResponse('polls', 'no.acc.tmpl', []);
258
+			return new TemplateResponse('polls', 'no.acc.tmpl', [ ]);
259 259
 		}
260 260
 	}
261 261
 
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
 	 */
407 407
 	public function createPoll() {
408 408
 		return new TemplateResponse('polls', 'create.tmpl',
409
-			['userId' => $this->userId, 'userMgr' => $this->userMgr, 'urlGenerator' => $this->urlGenerator]);
409
+			[ 'userId' => $this->userId, 'userMgr' => $this->userMgr, 'urlGenerator' => $this->urlGenerator ]);
410 410
 	}
411 411
 
412 412
 	/**
@@ -560,15 +560,15 @@  discard block
 block discarded – undo
560 560
 					$part = new Participation();
561 561
 					$part->setPollId($pollId);
562 562
 					$part->setUserId($userId);
563
-					$part->setDt(date('Y-m-d H:i:s', $dates[$i]));
564
-					$part->setType($types[$i]);
563
+					$part->setDt(date('Y-m-d H:i:s', $dates[ $i ]));
564
+					$part->setType($types[ $i ]);
565 565
 					$this->participationMapper->insert($part);
566 566
 				} else {
567 567
 					$part = new ParticipationText();
568 568
 					$part->setPollId($pollId);
569 569
 					$part->setUserId($userId);
570
-					$part->setText($dates[$i]);
571
-					$part->setType($types[$i]);
570
+					$part->setText($dates[ $i ]);
571
+					$part->setType($types[ $i ]);
572 572
 					$this->participationTextMapper->insert($part);
573 573
 				}
574 574
 
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
 			$this->sendNotifications($pollId, $userId);
577 577
 		}
578 578
 		$hash = $poll->getHash();
579
-		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
579
+		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', [ 'hash' => $hash ]);
580 580
 		return new RedirectResponse($url);
581 581
 	}
582 582
 
@@ -633,15 +633,15 @@  discard block
 block discarded – undo
633 633
 		$gids = array();
634 634
 		$sgids = array();
635 635
 		foreach ($selectedGroups as $sg) {
636
-			$sgids[] = str_replace('group_', '', $sg);
636
+			$sgids[ ] = str_replace('group_', '', $sg);
637 637
 		}
638 638
 		foreach ($groups as $g) {
639
-			$gids[] = $g->getGID();
639
+			$gids[ ] = $g->getGID();
640 640
 		}
641 641
 		$diffGids = array_diff($gids, $sgids);
642 642
 		$gids = array();
643 643
 		foreach ($diffGids as $g) {
644
-			$gids[] = ['gid' => $g, 'isGroup' => true];
644
+			$gids[ ] = [ 'gid' => $g, 'isGroup' => true ];
645 645
 		}
646 646
 		return $gids;
647 647
 	}
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
 		$users = array();
661 661
 		$sUsers = array();
662 662
 		foreach ($selectedUsers as $su) {
663
-			$sUsers[] = str_replace('user_', '', $su);
663
+			$sUsers[ ] = str_replace('user_', '', $su);
664 664
 		}
665 665
 		foreach ($userNames as $u) {
666 666
 			$alreadyAdded = false;
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 				}
673 673
 			}
674 674
 			if (!$alreadyAdded) {
675
-				$users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
675
+				$users[ ] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
676 676
 			} else {
677 677
 				continue;
678 678
 			}
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 		}
701 701
 		// Nextcloud >= 12
702 702
 		$groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
703
-		return array_map(function ($group) {
703
+		return array_map(function($group) {
704 704
 			return $group->getGID();
705 705
 		}, $groups);
706 706
 	}
Please login to merge, or discard this patch.
Indentation   +690 added lines, -690 removed lines patch added patch discarded remove patch
@@ -57,694 +57,694 @@
 block discarded – undo
57 57
 
58 58
 class PageController extends Controller {
59 59
 
60
-	private $userId;
61
-	private $commentMapper;
62
-	private $dateMapper;
63
-	private $eventMapper;
64
-	private $notificationMapper;
65
-	private $participationMapper;
66
-	private $participationTextMapper;
67
-	private $textMapper;
68
-	private $urlGenerator;
69
-	private $userMgr;
70
-	private $avatarManager;
71
-	private $logger;
72
-	private $trans;
73
-	private $groupManager;
74
-
75
-	/**
76
-	 * PageController constructor.
77
-	 * @param string $appName
78
-	 * @param IRequest $request
79
-	 * @param IUserManager $userMgr
80
-	 * @param IGroupManager $groupManager
81
-	 * @param IAvatarManager $avatarManager
82
-	 * @param ILogger $logger
83
-	 * @param IL10N $trans
84
-	 * @param IURLGenerator $urlGenerator
85
-	 * @param string $userId
86
-	 * @param CommentMapper $commentMapper
87
-	 * @param DateMapper $dateMapper
88
-	 * @param EventMapper $eventMapper
89
-	 * @param NotificationMapper $notificationMapper
90
-	 * @param ParticipationMapper $ParticipationMapper
91
-	 * @param ParticipationTextMapper $ParticipationTextMapper
92
-	 * @param TextMapper $textMapper
93
-	 */
94
-	public function __construct(
95
-		$appName,
96
-		IRequest $request,
97
-		IUserManager $userMgr,
98
-		IGroupManager $groupManager,
99
-		IAvatarManager $avatarManager,
100
-		ILogger $logger,
101
-		IL10N $trans,
102
-		IURLGenerator $urlGenerator,
103
-		$userId,
104
-		CommentMapper $commentMapper,
105
-		DateMapper $dateMapper,
106
-		EventMapper $eventMapper,
107
-		NotificationMapper $notificationMapper,
108
-		ParticipationMapper $ParticipationMapper,
109
-		ParticipationTextMapper $ParticipationTextMapper,
110
-		TextMapper $textMapper
111
-	) {
112
-		parent::__construct($appName, $request);
113
-		$this->userMgr = $userMgr;
114
-		$this->groupManager = $groupManager;
115
-		$this->avatarManager = $avatarManager;
116
-		$this->logger = $logger;
117
-		$this->trans = $trans;
118
-		$this->urlGenerator = $urlGenerator;
119
-		$this->userId = $userId;
120
-		$this->commentMapper = $commentMapper;
121
-		$this->dateMapper = $dateMapper;
122
-		$this->eventMapper = $eventMapper;
123
-		$this->notificationMapper = $notificationMapper;
124
-		$this->participationMapper = $ParticipationMapper;
125
-		$this->participationTextMapper = $ParticipationTextMapper;
126
-		$this->textMapper = $textMapper;
127
-	}
128
-
129
-	/**
130
-	 * @NoAdminRequired
131
-	 * @NoCSRFRequired
132
-	 */
133
-	public function index() {
134
-		$polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
135
-		$comments = $this->commentMapper->findDistinctByUser($this->userId);
136
-		$partic = $this->participationMapper->findDistinctByUser($this->userId);
137
-		$particText = $this->participationTextMapper->findDistinctByUser($this->userId);
138
-		$response = new TemplateResponse('polls', 'main.tmpl', [
139
-			'polls' => $polls,
140
-			'comments' => $comments,
141
-			'participations' => $partic,
142
-			'participations_text' => $particText,
143
-			'userId' => $this->userId,
144
-			'userMgr' => $this->userMgr,
145
-			'urlGenerator' => $this->urlGenerator
146
-		]);
147
-		$csp = new ContentSecurityPolicy();
148
-		$response->setContentSecurityPolicy($csp);
149
-		return $response;
150
-	}
151
-
152
-	/**
153
-	 * @param int $pollId
154
-	 * @param string $from
155
-	 */
156
-	private function sendNotifications($pollId, $from) {
157
-		$poll = $this->eventMapper->find($pollId);
158
-		$notifications = $this->notificationMapper->findAllByPoll($pollId);
159
-		foreach ($notifications as $notification) {
160
-			if ($from === $notification->getUserId()) {
161
-				continue;
162
-			}
163
-			$email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
164
-			if ($email === null || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
165
-				continue;
166
-			}
167
-			$url = $this->urlGenerator->getAbsoluteURL(
168
-				$this->urlGenerator->linkToRoute('polls.page.goto_poll',
169
-					array('hash' => $poll->getHash()))
170
-			);
171
-
172
-			$recUser = $this->userMgr->get($notification->getUserId());
173
-			$sendUser = $this->userMgr->get($from);
174
-			$rec = '';
175
-			if ($recUser !== null) {
176
-				$rec = $recUser->getDisplayName();
177
-			}
178
-			$sender = $from;
179
-			if ($sendUser !== null) {
180
-				$sender = $sendUser->getDisplayName();
181
-			}
182
-			$msg = $this->trans->t('Hello %s,<br/><br/><strong>%s</strong> participated in the poll \'%s\'.<br/><br/>To go directly to the poll, you can use this <a href="%s">link</a>',
183
-				array(
184
-					$rec,
185
-					$sender,
186
-					$poll->getTitle(),
187
-					$url
188
-				));
189
-
190
-			$msg .= '<br/><br/>';
191
-
192
-			$toName = $this->userMgr->get($notification->getUserId())->getDisplayName();
193
-			$subject = $this->trans->t('Polls App - New Activity');
194
-			$fromAddress = Util::getDefaultEmailAddress('no-reply');
195
-			$fromName = $this->trans->t('Polls App') . ' (' . $from . ')';
196
-
197
-			try {
198
-				/** @var IMailer $mailer */
199
-				$mailer = \OC::$server->getMailer();
200
-				/** @var \OC\Mail\Message $message */
201
-				$message = $mailer->createMessage();
202
-				$message->setSubject($subject);
203
-				$message->setFrom(array($fromAddress => $fromName));
204
-				$message->setTo(array($email => $toName));
205
-				$message->setHtmlBody($msg);
206
-				$mailer->send($message);
207
-			} catch (\Exception $e) {
208
-				$message = 'Error sending mail to: ' . $toName . ' (' . $email . ')';
209
-				Util::writeLog('polls', $message, Util::ERROR);
210
-			}
211
-		}
212
-	}
213
-
214
-	/**
215
-	 * @NoAdminRequired
216
-	 * @NoCSRFRequired
217
-	 * @PublicPage
218
-	 * @param string $hash
219
-	 * @return TemplateResponse
220
-	 */
221
-	public function gotoPoll($hash) {
222
-		try {
223
-			$poll = $this->eventMapper->findByHash($hash);
224
-		} catch (DoesNotExistException $e) {
225
-			return new TemplateResponse('polls', 'no.acc.tmpl', []);
226
-		}
227
-		if ($poll->getType() === 0) {
228
-			$dates = $this->dateMapper->findByPoll($poll->getId());
229
-			$votes = $this->participationMapper->findByPoll($poll->getId());
230
-			$participants = $this->participationMapper->findParticipantsByPoll($poll->getId());
231
-		} else {
232
-			$dates = $this->textMapper->findByPoll($poll->getId());
233
-			$votes = $this->participationTextMapper->findByPoll($poll->getId());
234
-			$participants = $this->participationTextMapper->findParticipantsByPoll($poll->getId());
235
-		}
236
-		$comments = $this->commentMapper->findByPoll($poll->getId());
237
-		try {
238
-			$notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
239
-		} catch (DoesNotExistException $e) {
240
-			$notification = null;
241
-		}
242
-		if ($this->hasUserAccess($poll)) {
243
-			return new TemplateResponse('polls', 'goto.tmpl', [
244
-				'poll' => $poll,
245
-				'dates' => $dates,
246
-				'comments' => $comments,
247
-				'votes' => $votes,
248
-				'participants' => $participants,
249
-				'notification' => $notification,
250
-				'userId' => $this->userId,
251
-				'userMgr' => $this->userMgr,
252
-				'urlGenerator' => $this->urlGenerator,
253
-				'avatarManager' => $this->avatarManager
254
-			]);
255
-		} else {
256
-			User::checkLoggedIn();
257
-			return new TemplateResponse('polls', 'no.acc.tmpl', []);
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * @NoAdminRequired
263
-	 * @NoCSRFRequired
264
-	 * @param int $pollId
265
-	 * @return TemplateResponse|RedirectResponse
266
-	 */
267
-	public function deletePoll($pollId) {
268
-		$pollToDelete = $this->eventMapper->find($pollId);
269
-		if ($this->userId !== $pollToDelete->getOwner()) {
270
-			return new TemplateResponse('polls', 'no.delete.tmpl');
271
-		}
272
-		$poll = new Event();
273
-		$poll->setId($pollId);
274
-		$this->eventMapper->delete($poll);
275
-		$this->textMapper->deleteByPoll($pollId);
276
-		$this->dateMapper->deleteByPoll($pollId);
277
-		$this->participationMapper->deleteByPoll($pollId);
278
-		$this->participationTextMapper->deleteByPoll($pollId);
279
-		$this->commentMapper->deleteByPoll($pollId);
280
-		$url = $this->urlGenerator->linkToRoute('polls.page.index');
281
-		return new RedirectResponse($url);
282
-	}
283
-
284
-	/**
285
-	 * @NoAdminRequired
286
-	 * @NoCSRFRequired
287
-	 * @param string $hash
288
-	 * @return TemplateResponse
289
-	 */
290
-	public function editPoll($hash) {
291
-		$poll = $this->eventMapper->findByHash($hash);
292
-		if ($this->userId !== $poll->getOwner()) {
293
-			return new TemplateResponse('polls', 'no.create.tmpl');
294
-		}
295
-		if ($poll->getType() === 0) {
296
-			$dates = $this->dateMapper->findByPoll($poll->getId());
297
-		} else {
298
-			$dates = $this->textMapper->findByPoll($poll->getId());
299
-		}
300
-		return new TemplateResponse('polls', 'create.tmpl', [
301
-			'poll' => $poll,
302
-			'dates' => $dates,
303
-			'userId' => $this->userId,
304
-			'userMgr' => $this->userMgr,
305
-			'urlGenerator' => $this->urlGenerator
306
-		]);
307
-	}
308
-
309
-	/**
310
-	 * @NoAdminRequired
311
-	 * @NoCSRFRequired
312
-	 * @param int $pollId
313
-	 * @param string $pollType
314
-	 * @param string $pollTitle
315
-	 * @param string $pollDesc
316
-	 * @param string $userId
317
-	 * @param string $chosenDates
318
-	 * @param int $expireTs
319
-	 * @param string $accessType
320
-	 * @param string $accessValues
321
-	 * @param bool $isAnonymous
322
-	 * @param bool $hideNames
323
-	 * @return RedirectResponse
324
-	 */
325
-	public function updatePoll(
326
-		$pollId,
327
-		$pollType,
328
-		$pollTitle,
329
-		$pollDesc,
330
-		$userId,
331
-		$chosenDates,
332
-		$expireTs,
333
-		$accessType,
334
-		$accessValues,
335
-		$isAnonymous,
336
-		$hideNames
337
-	) {
338
-		$event = $this->eventMapper->find($pollId);
339
-		$event->setTitle(htmlspecialchars(strip_tags($pollTitle)));
340
-		$event->setDescription(htmlspecialchars(strip_tags($pollDesc)));
341
-		$event->setIsAnonymous($isAnonymous ? 1 : 0);
342
-		$event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
343
-
344
-		if ($accessType === 'select') {
345
-			if (isset($accessValues)) {
346
-				$accessValues = json_decode($accessValues);
347
-				if ($accessValues !== null) {
348
-					$groups = array();
349
-					$users = array();
350
-					if ($accessValues->groups !== null) {
351
-						$groups = $accessValues->groups;
352
-					}
353
-					if ($accessValues->users !== null) {
354
-						$users = $accessValues->users;
355
-					}
356
-					$accessType = '';
357
-					foreach ($groups as $gid) {
358
-						$accessType .= $gid . ';';
359
-					}
360
-					foreach ($users as $uid) {
361
-						$accessType .= $uid . ';';
362
-					}
363
-				}
364
-			}
365
-		}
366
-		$event->setAccess($accessType);
367
-		/** @var string[] $chosenDates */
368
-		$chosenDates = json_decode($chosenDates);
369
-
370
-		$expire = null;
371
-		if ($expireTs !== 0 && $expireTs !== '') {
372
-			// Add one day, so it expires at the end of a day
373
-			$expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
374
-		}
375
-		$event->setExpire($expire);
376
-
377
-		$this->dateMapper->deleteByPoll($pollId);
378
-		$this->textMapper->deleteByPoll($pollId);
379
-		if ($pollType === 'event') {
380
-			$event->setType(0);
381
-			$this->eventMapper->update($event);
382
-			sort($chosenDates);
383
-			foreach ($chosenDates as $el) {
384
-				$date = new Date();
385
-				$date->setPollId($pollId);
386
-				$date->setDt(date('Y-m-d H:i:s', $el));
387
-				$this->dateMapper->insert($date);
388
-			}
389
-		} else {
390
-			$event->setType(1);
391
-			$this->eventMapper->update($event);
392
-			foreach ($chosenDates as $el) {
393
-				$text = new Text();
394
-				$text->setPollId($pollId);
395
-				$text->setText($el);
396
-				$this->textMapper->insert($text);
397
-			}
398
-		}
399
-		$url = $this->urlGenerator->linkToRoute('polls.page.index');
400
-		return new RedirectResponse($url);
401
-	}
402
-
403
-	/**
404
-	 * @NoAdminRequired
405
-	 * @NoCSRFRequired
406
-	 */
407
-	public function createPoll() {
408
-		return new TemplateResponse('polls', 'create.tmpl',
409
-			['userId' => $this->userId, 'userMgr' => $this->userMgr, 'urlGenerator' => $this->urlGenerator]);
410
-	}
411
-
412
-	/**
413
-	 * @NoAdminRequired
414
-	 * @NoCSRFRequired
415
-	 * @param string $pollType
416
-	 * @param string $pollTitle
417
-	 * @param string $pollDesc
418
-	 * @param string $userId
419
-	 * @param string $chosenDates
420
-	 * @param int $expireTs
421
-	 * @param string $accessType
422
-	 * @param string $accessValues
423
-	 * @param bool $isAnonymous
424
-	 * @param bool $hideNames
425
-	 * @return RedirectResponse
426
-	 */
427
-	public function insertPoll(
428
-		$pollType,
429
-		$pollTitle,
430
-		$pollDesc,
431
-		$userId,
432
-		$chosenDates,
433
-		$expireTs,
434
-		$accessType,
435
-		$accessValues,
436
-		$isAnonymous,
437
-		$hideNames
438
-	) {
439
-		$event = new Event();
440
-		$event->setTitle(htmlspecialchars(strip_tags($pollTitle)));
441
-		$event->setDescription(htmlspecialchars(strip_tags($pollDesc)));
442
-		$event->setOwner($userId);
443
-		$event->setCreated(date('Y-m-d H:i:s'));
444
-		$event->setHash(\OC::$server->getSecureRandom()->generate(
445
-			16,
446
-			ISecureRandom::CHAR_DIGITS .
447
-			ISecureRandom::CHAR_LOWER .
448
-			ISecureRandom::CHAR_UPPER
449
-		));
450
-		$event->setIsAnonymous($isAnonymous ? 1 : 0);
451
-		$event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
452
-
453
-		if ($accessType === 'select') {
454
-			if (isset($accessValues)) {
455
-				$accessValues = json_decode($accessValues);
456
-				if ($accessValues !== null) {
457
-					$groups = array();
458
-					$users = array();
459
-					if ($accessValues->groups !== null) {
460
-						$groups = $accessValues->groups;
461
-					}
462
-					if ($accessValues->users !== null) {
463
-						$users = $accessValues->users;
464
-					}
465
-					$accessType = '';
466
-					foreach ($groups as $gid) {
467
-						$accessType .= $gid . ';';
468
-					}
469
-					foreach ($users as $uid) {
470
-						$accessType .= $uid . ';';
471
-					}
472
-				}
473
-			}
474
-		}
475
-		$event->setAccess($accessType);
476
-		/** @var string[] $chosenDates */
477
-		$chosenDates = json_decode($chosenDates);
478
-
479
-		$expire = null;
480
-		if ($expireTs !== 0 && $expireTs !== '') {
481
-			// Add one day, so it expires at the end of a day
482
-			$expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
483
-		}
484
-		$event->setExpire($expire);
485
-
486
-		if ($pollType === 'event') {
487
-			$event->setType(0);
488
-			$ins = $this->eventMapper->insert($event);
489
-			$pollId = $ins->getId();
490
-			sort($chosenDates);
491
-			foreach ($chosenDates as $el) {
492
-				$date = new Date();
493
-				$date->setPollId($pollId);
494
-				$date->setDt(date('Y-m-d H:i:s', $el));
495
-				$this->dateMapper->insert($date);
496
-			}
497
-		} else {
498
-			$event->setType(1);
499
-			$ins = $this->eventMapper->insert($event);
500
-			$pollId = $ins->getId();
501
-			$cnt = 1;
502
-			foreach ($chosenDates as $el) {
503
-				$text = new Text();
504
-				$text->setPollId($pollId);
505
-				$text->setText($el . '_' . $cnt);
506
-				$this->textMapper->insert($text);
507
-				$cnt++;
508
-			}
509
-		}
510
-		$url = $this->urlGenerator->linkToRoute('polls.page.index');
511
-		return new RedirectResponse($url);
512
-	}
513
-
514
-	/**
515
-	 * @NoAdminRequired
516
-	 * @NoCSRFRequired
517
-	 * @PublicPage
518
-	 * @param int $pollId
519
-	 * @param string $userId
520
-	 * @param string $types
521
-	 * @param string $dates
522
-	 * @param bool $receiveNotifications
523
-	 * @param bool $changed
524
-	 * @return RedirectResponse
525
-	 */
526
-	public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
527
-		if ($this->userId !== null) {
528
-			if ($receiveNotifications) {
529
-				try {
530
-					//check if user already set notification for this poll
531
-					$this->notificationMapper->findByUserAndPoll($pollId, $userId);
532
-				} catch (DoesNotExistException $e) {
533
-					//insert if not exist
534
-					$not = new Notification();
535
-					$not->setUserId($userId);
536
-					$not->setPollId($pollId);
537
-					$this->notificationMapper->insert($not);
538
-				}
539
-			} else {
540
-				try {
541
-					//delete if entry is in db
542
-					$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
543
-					$this->notificationMapper->delete($not);
544
-				} catch (DoesNotExistException $e) {
545
-					//doesn't exist in db, nothing to do
546
-				}
547
-			}
548
-		}
549
-		$poll = $this->eventMapper->find($pollId);
550
-		if ($changed) {
551
-			$dates = json_decode($dates);
552
-			$types = json_decode($types);
553
-			$count_dates = count($dates);
554
-			if ($poll->getType() === 0) {
555
-				$this->participationMapper->deleteByPollAndUser($pollId, $userId);
556
-			} else {
557
-				$this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
558
-			}
559
-			for ($i = 0; $i < $count_dates; $i++) {
560
-				if ($poll->getType() === 0) {
561
-					$part = new Participation();
562
-					$part->setPollId($pollId);
563
-					$part->setUserId($userId);
564
-					$part->setDt(date('Y-m-d H:i:s', $dates[$i]));
565
-					$part->setType($types[$i]);
566
-					$this->participationMapper->insert($part);
567
-				} else {
568
-					$part = new ParticipationText();
569
-					$part->setPollId($pollId);
570
-					$part->setUserId($userId);
571
-					$part->setText($dates[$i]);
572
-					$part->setType($types[$i]);
573
-					$this->participationTextMapper->insert($part);
574
-				}
575
-
576
-			}
577
-			$this->sendNotifications($pollId, $userId);
578
-		}
579
-		$hash = $poll->getHash();
580
-		$url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
581
-		return new RedirectResponse($url);
582
-	}
583
-
584
-	/**
585
-	 * @NoAdminRequired
586
-	 * @NoCSRFRequired
587
-	 * @PublicPage
588
-	 * @param int $pollId
589
-	 * @param string $userId
590
-	 * @param string $commentBox
591
-	 * @return JSONResponse
592
-	 */
593
-	public function insertComment($pollId, $userId, $commentBox) {
594
-		$comment = new Comment();
595
-		$comment->setPollId($pollId);
596
-		$comment->setUserId($userId);
597
-		$comment->setComment($commentBox);
598
-		$comment->setDt(date('Y-m-d H:i:s'));
599
-		$this->commentMapper->insert($comment);
600
-		$this->sendNotifications($pollId, $userId);
601
-		$newUserId = $userId;
602
-		if ($this->userMgr->get($userId) !== null) {
603
-			$newUserId = $this->userMgr->get($userId)->getDisplayName();
604
-		}
605
-		return new JSONResponse(array(
606
-			'comment' => $commentBox,
607
-			'date' => date('Y-m-d H:i:s'),
608
-			'userName' => $newUserId
609
-		));
610
-	}
611
-
612
-	/**
613
-	 * @NoAdminRequired
614
-	 * @NoCSRFRequired
615
-	 * @param string $searchTerm
616
-	 * @param string $groups
617
-	 * @param string $users
618
-	 * @return array
619
-	 */
620
-	public function search($searchTerm, $groups, $users) {
621
-		return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
622
-	}
623
-
624
-	/**
625
-	 * @NoAdminRequired
626
-	 * @NoCSRFRequired
627
-	 * @param string $searchTerm
628
-	 * @param string $groups
629
-	 * @return array
630
-	 */
631
-	public function searchForGroups($searchTerm, $groups) {
632
-		$selectedGroups = json_decode($groups);
633
-		$groups = $this->groupManager->search($searchTerm);
634
-		$gids = array();
635
-		$sgids = array();
636
-		foreach ($selectedGroups as $sg) {
637
-			$sgids[] = str_replace('group_', '', $sg);
638
-		}
639
-		foreach ($groups as $g) {
640
-			$gids[] = $g->getGID();
641
-		}
642
-		$diffGids = array_diff($gids, $sgids);
643
-		$gids = array();
644
-		foreach ($diffGids as $g) {
645
-			$gids[] = ['gid' => $g, 'isGroup' => true];
646
-		}
647
-		return $gids;
648
-	}
649
-
650
-	/**
651
-	 * @NoAdminRequired
652
-	 * @NoCSRFRequired
653
-	 * @param string $searchTerm
654
-	 * @param string $users
655
-	 * @return array
656
-	 */
657
-	public function searchForUsers($searchTerm, $users) {
658
-		$selectedUsers = json_decode($users);
659
-		Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);
660
-		$userNames = $this->userMgr->searchDisplayName($searchTerm);
661
-		$users = array();
662
-		$sUsers = array();
663
-		foreach ($selectedUsers as $su) {
664
-			$sUsers[] = str_replace('user_', '', $su);
665
-		}
666
-		foreach ($userNames as $u) {
667
-			$alreadyAdded = false;
668
-			foreach ($sUsers as &$su) {
669
-				if ($su === $u->getUID()) {
670
-					unset($su);
671
-					$alreadyAdded = true;
672
-					break;
673
-				}
674
-			}
675
-			if (!$alreadyAdded) {
676
-				$users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
677
-			} else {
678
-				continue;
679
-			}
680
-		}
681
-		return $users;
682
-	}
683
-
684
-	/**
685
-	 * @NoAdminRequired
686
-	 * @NoCSRFRequired
687
-	 * @param string $username
688
-	 * @return string
689
-	 */
690
-	public function getDisplayName($username) {
691
-		return $this->userMgr->get($username)->getDisplayName();
692
-	}
693
-
694
-	/**
695
-	 * @return \OCP\IGroup[]
696
-	 */
697
-	private function getGroups() {
698
-		if (class_exists('\OC_Group')) {
699
-			// Nextcloud <= 11, ownCloud
700
-			return \OC_Group::getUserGroups($this->userId);
701
-		}
702
-		// Nextcloud >= 12
703
-		$groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
704
-		return array_map(function ($group) {
705
-			return $group->getGID();
706
-		}, $groups);
707
-	}
708
-
709
-	/**
710
-	 * @param Event $poll
711
-	 * @return bool
712
-	 */
713
-	private function hasUserAccess($poll) {
714
-		$access = $poll->getAccess();
715
-		$owner = $poll->getOwner();
716
-		if ($access === 'public' || $access === 'hidden') {
717
-			return true;
718
-		}
719
-		if ($this->userId === null) {
720
-			return false;
721
-		}
722
-		if ($access === 'registered') {
723
-			return true;
724
-		}
725
-		if ($owner === $this->userId) {
726
-			return true;
727
-		}
728
-		Util::writeLog('polls', $this->userId, Util::ERROR);
729
-		$userGroups = $this->getGroups();
730
-		$arr = explode(';', $access);
731
-		foreach ($arr as $item) {
732
-			if (strpos($item, 'group_') === 0) {
733
-				$grp = substr($item, 6);
734
-				foreach ($userGroups as $userGroup) {
735
-					if ($userGroup === $grp) {
736
-						return true;
737
-					}
738
-				}
739
-			} else {
740
-				if (strpos($item, 'user_') === 0) {
741
-					$usr = substr($item, 5);
742
-					if ($usr === $this->userId) {
743
-						return true;
744
-					}
745
-				}
746
-			}
747
-		}
748
-		return false;
749
-	}
60
+    private $userId;
61
+    private $commentMapper;
62
+    private $dateMapper;
63
+    private $eventMapper;
64
+    private $notificationMapper;
65
+    private $participationMapper;
66
+    private $participationTextMapper;
67
+    private $textMapper;
68
+    private $urlGenerator;
69
+    private $userMgr;
70
+    private $avatarManager;
71
+    private $logger;
72
+    private $trans;
73
+    private $groupManager;
74
+
75
+    /**
76
+     * PageController constructor.
77
+     * @param string $appName
78
+     * @param IRequest $request
79
+     * @param IUserManager $userMgr
80
+     * @param IGroupManager $groupManager
81
+     * @param IAvatarManager $avatarManager
82
+     * @param ILogger $logger
83
+     * @param IL10N $trans
84
+     * @param IURLGenerator $urlGenerator
85
+     * @param string $userId
86
+     * @param CommentMapper $commentMapper
87
+     * @param DateMapper $dateMapper
88
+     * @param EventMapper $eventMapper
89
+     * @param NotificationMapper $notificationMapper
90
+     * @param ParticipationMapper $ParticipationMapper
91
+     * @param ParticipationTextMapper $ParticipationTextMapper
92
+     * @param TextMapper $textMapper
93
+     */
94
+    public function __construct(
95
+        $appName,
96
+        IRequest $request,
97
+        IUserManager $userMgr,
98
+        IGroupManager $groupManager,
99
+        IAvatarManager $avatarManager,
100
+        ILogger $logger,
101
+        IL10N $trans,
102
+        IURLGenerator $urlGenerator,
103
+        $userId,
104
+        CommentMapper $commentMapper,
105
+        DateMapper $dateMapper,
106
+        EventMapper $eventMapper,
107
+        NotificationMapper $notificationMapper,
108
+        ParticipationMapper $ParticipationMapper,
109
+        ParticipationTextMapper $ParticipationTextMapper,
110
+        TextMapper $textMapper
111
+    ) {
112
+        parent::__construct($appName, $request);
113
+        $this->userMgr = $userMgr;
114
+        $this->groupManager = $groupManager;
115
+        $this->avatarManager = $avatarManager;
116
+        $this->logger = $logger;
117
+        $this->trans = $trans;
118
+        $this->urlGenerator = $urlGenerator;
119
+        $this->userId = $userId;
120
+        $this->commentMapper = $commentMapper;
121
+        $this->dateMapper = $dateMapper;
122
+        $this->eventMapper = $eventMapper;
123
+        $this->notificationMapper = $notificationMapper;
124
+        $this->participationMapper = $ParticipationMapper;
125
+        $this->participationTextMapper = $ParticipationTextMapper;
126
+        $this->textMapper = $textMapper;
127
+    }
128
+
129
+    /**
130
+     * @NoAdminRequired
131
+     * @NoCSRFRequired
132
+     */
133
+    public function index() {
134
+        $polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
135
+        $comments = $this->commentMapper->findDistinctByUser($this->userId);
136
+        $partic = $this->participationMapper->findDistinctByUser($this->userId);
137
+        $particText = $this->participationTextMapper->findDistinctByUser($this->userId);
138
+        $response = new TemplateResponse('polls', 'main.tmpl', [
139
+            'polls' => $polls,
140
+            'comments' => $comments,
141
+            'participations' => $partic,
142
+            'participations_text' => $particText,
143
+            'userId' => $this->userId,
144
+            'userMgr' => $this->userMgr,
145
+            'urlGenerator' => $this->urlGenerator
146
+        ]);
147
+        $csp = new ContentSecurityPolicy();
148
+        $response->setContentSecurityPolicy($csp);
149
+        return $response;
150
+    }
151
+
152
+    /**
153
+     * @param int $pollId
154
+     * @param string $from
155
+     */
156
+    private function sendNotifications($pollId, $from) {
157
+        $poll = $this->eventMapper->find($pollId);
158
+        $notifications = $this->notificationMapper->findAllByPoll($pollId);
159
+        foreach ($notifications as $notification) {
160
+            if ($from === $notification->getUserId()) {
161
+                continue;
162
+            }
163
+            $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
164
+            if ($email === null || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
165
+                continue;
166
+            }
167
+            $url = $this->urlGenerator->getAbsoluteURL(
168
+                $this->urlGenerator->linkToRoute('polls.page.goto_poll',
169
+                    array('hash' => $poll->getHash()))
170
+            );
171
+
172
+            $recUser = $this->userMgr->get($notification->getUserId());
173
+            $sendUser = $this->userMgr->get($from);
174
+            $rec = '';
175
+            if ($recUser !== null) {
176
+                $rec = $recUser->getDisplayName();
177
+            }
178
+            $sender = $from;
179
+            if ($sendUser !== null) {
180
+                $sender = $sendUser->getDisplayName();
181
+            }
182
+            $msg = $this->trans->t('Hello %s,<br/><br/><strong>%s</strong> participated in the poll \'%s\'.<br/><br/>To go directly to the poll, you can use this <a href="%s">link</a>',
183
+                array(
184
+                    $rec,
185
+                    $sender,
186
+                    $poll->getTitle(),
187
+                    $url
188
+                ));
189
+
190
+            $msg .= '<br/><br/>';
191
+
192
+            $toName = $this->userMgr->get($notification->getUserId())->getDisplayName();
193
+            $subject = $this->trans->t('Polls App - New Activity');
194
+            $fromAddress = Util::getDefaultEmailAddress('no-reply');
195
+            $fromName = $this->trans->t('Polls App') . ' (' . $from . ')';
196
+
197
+            try {
198
+                /** @var IMailer $mailer */
199
+                $mailer = \OC::$server->getMailer();
200
+                /** @var \OC\Mail\Message $message */
201
+                $message = $mailer->createMessage();
202
+                $message->setSubject($subject);
203
+                $message->setFrom(array($fromAddress => $fromName));
204
+                $message->setTo(array($email => $toName));
205
+                $message->setHtmlBody($msg);
206
+                $mailer->send($message);
207
+            } catch (\Exception $e) {
208
+                $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')';
209
+                Util::writeLog('polls', $message, Util::ERROR);
210
+            }
211
+        }
212
+    }
213
+
214
+    /**
215
+     * @NoAdminRequired
216
+     * @NoCSRFRequired
217
+     * @PublicPage
218
+     * @param string $hash
219
+     * @return TemplateResponse
220
+     */
221
+    public function gotoPoll($hash) {
222
+        try {
223
+            $poll = $this->eventMapper->findByHash($hash);
224
+        } catch (DoesNotExistException $e) {
225
+            return new TemplateResponse('polls', 'no.acc.tmpl', []);
226
+        }
227
+        if ($poll->getType() === 0) {
228
+            $dates = $this->dateMapper->findByPoll($poll->getId());
229
+            $votes = $this->participationMapper->findByPoll($poll->getId());
230
+            $participants = $this->participationMapper->findParticipantsByPoll($poll->getId());
231
+        } else {
232
+            $dates = $this->textMapper->findByPoll($poll->getId());
233
+            $votes = $this->participationTextMapper->findByPoll($poll->getId());
234
+            $participants = $this->participationTextMapper->findParticipantsByPoll($poll->getId());
235
+        }
236
+        $comments = $this->commentMapper->findByPoll($poll->getId());
237
+        try {
238
+            $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
239
+        } catch (DoesNotExistException $e) {
240
+            $notification = null;
241
+        }
242
+        if ($this->hasUserAccess($poll)) {
243
+            return new TemplateResponse('polls', 'goto.tmpl', [
244
+                'poll' => $poll,
245
+                'dates' => $dates,
246
+                'comments' => $comments,
247
+                'votes' => $votes,
248
+                'participants' => $participants,
249
+                'notification' => $notification,
250
+                'userId' => $this->userId,
251
+                'userMgr' => $this->userMgr,
252
+                'urlGenerator' => $this->urlGenerator,
253
+                'avatarManager' => $this->avatarManager
254
+            ]);
255
+        } else {
256
+            User::checkLoggedIn();
257
+            return new TemplateResponse('polls', 'no.acc.tmpl', []);
258
+        }
259
+    }
260
+
261
+    /**
262
+     * @NoAdminRequired
263
+     * @NoCSRFRequired
264
+     * @param int $pollId
265
+     * @return TemplateResponse|RedirectResponse
266
+     */
267
+    public function deletePoll($pollId) {
268
+        $pollToDelete = $this->eventMapper->find($pollId);
269
+        if ($this->userId !== $pollToDelete->getOwner()) {
270
+            return new TemplateResponse('polls', 'no.delete.tmpl');
271
+        }
272
+        $poll = new Event();
273
+        $poll->setId($pollId);
274
+        $this->eventMapper->delete($poll);
275
+        $this->textMapper->deleteByPoll($pollId);
276
+        $this->dateMapper->deleteByPoll($pollId);
277
+        $this->participationMapper->deleteByPoll($pollId);
278
+        $this->participationTextMapper->deleteByPoll($pollId);
279
+        $this->commentMapper->deleteByPoll($pollId);
280
+        $url = $this->urlGenerator->linkToRoute('polls.page.index');
281
+        return new RedirectResponse($url);
282
+    }
283
+
284
+    /**
285
+     * @NoAdminRequired
286
+     * @NoCSRFRequired
287
+     * @param string $hash
288
+     * @return TemplateResponse
289
+     */
290
+    public function editPoll($hash) {
291
+        $poll = $this->eventMapper->findByHash($hash);
292
+        if ($this->userId !== $poll->getOwner()) {
293
+            return new TemplateResponse('polls', 'no.create.tmpl');
294
+        }
295
+        if ($poll->getType() === 0) {
296
+            $dates = $this->dateMapper->findByPoll($poll->getId());
297
+        } else {
298
+            $dates = $this->textMapper->findByPoll($poll->getId());
299
+        }
300
+        return new TemplateResponse('polls', 'create.tmpl', [
301
+            'poll' => $poll,
302
+            'dates' => $dates,
303
+            'userId' => $this->userId,
304
+            'userMgr' => $this->userMgr,
305
+            'urlGenerator' => $this->urlGenerator
306
+        ]);
307
+    }
308
+
309
+    /**
310
+     * @NoAdminRequired
311
+     * @NoCSRFRequired
312
+     * @param int $pollId
313
+     * @param string $pollType
314
+     * @param string $pollTitle
315
+     * @param string $pollDesc
316
+     * @param string $userId
317
+     * @param string $chosenDates
318
+     * @param int $expireTs
319
+     * @param string $accessType
320
+     * @param string $accessValues
321
+     * @param bool $isAnonymous
322
+     * @param bool $hideNames
323
+     * @return RedirectResponse
324
+     */
325
+    public function updatePoll(
326
+        $pollId,
327
+        $pollType,
328
+        $pollTitle,
329
+        $pollDesc,
330
+        $userId,
331
+        $chosenDates,
332
+        $expireTs,
333
+        $accessType,
334
+        $accessValues,
335
+        $isAnonymous,
336
+        $hideNames
337
+    ) {
338
+        $event = $this->eventMapper->find($pollId);
339
+        $event->setTitle(htmlspecialchars(strip_tags($pollTitle)));
340
+        $event->setDescription(htmlspecialchars(strip_tags($pollDesc)));
341
+        $event->setIsAnonymous($isAnonymous ? 1 : 0);
342
+        $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
343
+
344
+        if ($accessType === 'select') {
345
+            if (isset($accessValues)) {
346
+                $accessValues = json_decode($accessValues);
347
+                if ($accessValues !== null) {
348
+                    $groups = array();
349
+                    $users = array();
350
+                    if ($accessValues->groups !== null) {
351
+                        $groups = $accessValues->groups;
352
+                    }
353
+                    if ($accessValues->users !== null) {
354
+                        $users = $accessValues->users;
355
+                    }
356
+                    $accessType = '';
357
+                    foreach ($groups as $gid) {
358
+                        $accessType .= $gid . ';';
359
+                    }
360
+                    foreach ($users as $uid) {
361
+                        $accessType .= $uid . ';';
362
+                    }
363
+                }
364
+            }
365
+        }
366
+        $event->setAccess($accessType);
367
+        /** @var string[] $chosenDates */
368
+        $chosenDates = json_decode($chosenDates);
369
+
370
+        $expire = null;
371
+        if ($expireTs !== 0 && $expireTs !== '') {
372
+            // Add one day, so it expires at the end of a day
373
+            $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
374
+        }
375
+        $event->setExpire($expire);
376
+
377
+        $this->dateMapper->deleteByPoll($pollId);
378
+        $this->textMapper->deleteByPoll($pollId);
379
+        if ($pollType === 'event') {
380
+            $event->setType(0);
381
+            $this->eventMapper->update($event);
382
+            sort($chosenDates);
383
+            foreach ($chosenDates as $el) {
384
+                $date = new Date();
385
+                $date->setPollId($pollId);
386
+                $date->setDt(date('Y-m-d H:i:s', $el));
387
+                $this->dateMapper->insert($date);
388
+            }
389
+        } else {
390
+            $event->setType(1);
391
+            $this->eventMapper->update($event);
392
+            foreach ($chosenDates as $el) {
393
+                $text = new Text();
394
+                $text->setPollId($pollId);
395
+                $text->setText($el);
396
+                $this->textMapper->insert($text);
397
+            }
398
+        }
399
+        $url = $this->urlGenerator->linkToRoute('polls.page.index');
400
+        return new RedirectResponse($url);
401
+    }
402
+
403
+    /**
404
+     * @NoAdminRequired
405
+     * @NoCSRFRequired
406
+     */
407
+    public function createPoll() {
408
+        return new TemplateResponse('polls', 'create.tmpl',
409
+            ['userId' => $this->userId, 'userMgr' => $this->userMgr, 'urlGenerator' => $this->urlGenerator]);
410
+    }
411
+
412
+    /**
413
+     * @NoAdminRequired
414
+     * @NoCSRFRequired
415
+     * @param string $pollType
416
+     * @param string $pollTitle
417
+     * @param string $pollDesc
418
+     * @param string $userId
419
+     * @param string $chosenDates
420
+     * @param int $expireTs
421
+     * @param string $accessType
422
+     * @param string $accessValues
423
+     * @param bool $isAnonymous
424
+     * @param bool $hideNames
425
+     * @return RedirectResponse
426
+     */
427
+    public function insertPoll(
428
+        $pollType,
429
+        $pollTitle,
430
+        $pollDesc,
431
+        $userId,
432
+        $chosenDates,
433
+        $expireTs,
434
+        $accessType,
435
+        $accessValues,
436
+        $isAnonymous,
437
+        $hideNames
438
+    ) {
439
+        $event = new Event();
440
+        $event->setTitle(htmlspecialchars(strip_tags($pollTitle)));
441
+        $event->setDescription(htmlspecialchars(strip_tags($pollDesc)));
442
+        $event->setOwner($userId);
443
+        $event->setCreated(date('Y-m-d H:i:s'));
444
+        $event->setHash(\OC::$server->getSecureRandom()->generate(
445
+            16,
446
+            ISecureRandom::CHAR_DIGITS .
447
+            ISecureRandom::CHAR_LOWER .
448
+            ISecureRandom::CHAR_UPPER
449
+        ));
450
+        $event->setIsAnonymous($isAnonymous ? 1 : 0);
451
+        $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
452
+
453
+        if ($accessType === 'select') {
454
+            if (isset($accessValues)) {
455
+                $accessValues = json_decode($accessValues);
456
+                if ($accessValues !== null) {
457
+                    $groups = array();
458
+                    $users = array();
459
+                    if ($accessValues->groups !== null) {
460
+                        $groups = $accessValues->groups;
461
+                    }
462
+                    if ($accessValues->users !== null) {
463
+                        $users = $accessValues->users;
464
+                    }
465
+                    $accessType = '';
466
+                    foreach ($groups as $gid) {
467
+                        $accessType .= $gid . ';';
468
+                    }
469
+                    foreach ($users as $uid) {
470
+                        $accessType .= $uid . ';';
471
+                    }
472
+                }
473
+            }
474
+        }
475
+        $event->setAccess($accessType);
476
+        /** @var string[] $chosenDates */
477
+        $chosenDates = json_decode($chosenDates);
478
+
479
+        $expire = null;
480
+        if ($expireTs !== 0 && $expireTs !== '') {
481
+            // Add one day, so it expires at the end of a day
482
+            $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
483
+        }
484
+        $event->setExpire($expire);
485
+
486
+        if ($pollType === 'event') {
487
+            $event->setType(0);
488
+            $ins = $this->eventMapper->insert($event);
489
+            $pollId = $ins->getId();
490
+            sort($chosenDates);
491
+            foreach ($chosenDates as $el) {
492
+                $date = new Date();
493
+                $date->setPollId($pollId);
494
+                $date->setDt(date('Y-m-d H:i:s', $el));
495
+                $this->dateMapper->insert($date);
496
+            }
497
+        } else {
498
+            $event->setType(1);
499
+            $ins = $this->eventMapper->insert($event);
500
+            $pollId = $ins->getId();
501
+            $cnt = 1;
502
+            foreach ($chosenDates as $el) {
503
+                $text = new Text();
504
+                $text->setPollId($pollId);
505
+                $text->setText($el . '_' . $cnt);
506
+                $this->textMapper->insert($text);
507
+                $cnt++;
508
+            }
509
+        }
510
+        $url = $this->urlGenerator->linkToRoute('polls.page.index');
511
+        return new RedirectResponse($url);
512
+    }
513
+
514
+    /**
515
+     * @NoAdminRequired
516
+     * @NoCSRFRequired
517
+     * @PublicPage
518
+     * @param int $pollId
519
+     * @param string $userId
520
+     * @param string $types
521
+     * @param string $dates
522
+     * @param bool $receiveNotifications
523
+     * @param bool $changed
524
+     * @return RedirectResponse
525
+     */
526
+    public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
527
+        if ($this->userId !== null) {
528
+            if ($receiveNotifications) {
529
+                try {
530
+                    //check if user already set notification for this poll
531
+                    $this->notificationMapper->findByUserAndPoll($pollId, $userId);
532
+                } catch (DoesNotExistException $e) {
533
+                    //insert if not exist
534
+                    $not = new Notification();
535
+                    $not->setUserId($userId);
536
+                    $not->setPollId($pollId);
537
+                    $this->notificationMapper->insert($not);
538
+                }
539
+            } else {
540
+                try {
541
+                    //delete if entry is in db
542
+                    $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
543
+                    $this->notificationMapper->delete($not);
544
+                } catch (DoesNotExistException $e) {
545
+                    //doesn't exist in db, nothing to do
546
+                }
547
+            }
548
+        }
549
+        $poll = $this->eventMapper->find($pollId);
550
+        if ($changed) {
551
+            $dates = json_decode($dates);
552
+            $types = json_decode($types);
553
+            $count_dates = count($dates);
554
+            if ($poll->getType() === 0) {
555
+                $this->participationMapper->deleteByPollAndUser($pollId, $userId);
556
+            } else {
557
+                $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
558
+            }
559
+            for ($i = 0; $i < $count_dates; $i++) {
560
+                if ($poll->getType() === 0) {
561
+                    $part = new Participation();
562
+                    $part->setPollId($pollId);
563
+                    $part->setUserId($userId);
564
+                    $part->setDt(date('Y-m-d H:i:s', $dates[$i]));
565
+                    $part->setType($types[$i]);
566
+                    $this->participationMapper->insert($part);
567
+                } else {
568
+                    $part = new ParticipationText();
569
+                    $part->setPollId($pollId);
570
+                    $part->setUserId($userId);
571
+                    $part->setText($dates[$i]);
572
+                    $part->setType($types[$i]);
573
+                    $this->participationTextMapper->insert($part);
574
+                }
575
+
576
+            }
577
+            $this->sendNotifications($pollId, $userId);
578
+        }
579
+        $hash = $poll->getHash();
580
+        $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
581
+        return new RedirectResponse($url);
582
+    }
583
+
584
+    /**
585
+     * @NoAdminRequired
586
+     * @NoCSRFRequired
587
+     * @PublicPage
588
+     * @param int $pollId
589
+     * @param string $userId
590
+     * @param string $commentBox
591
+     * @return JSONResponse
592
+     */
593
+    public function insertComment($pollId, $userId, $commentBox) {
594
+        $comment = new Comment();
595
+        $comment->setPollId($pollId);
596
+        $comment->setUserId($userId);
597
+        $comment->setComment($commentBox);
598
+        $comment->setDt(date('Y-m-d H:i:s'));
599
+        $this->commentMapper->insert($comment);
600
+        $this->sendNotifications($pollId, $userId);
601
+        $newUserId = $userId;
602
+        if ($this->userMgr->get($userId) !== null) {
603
+            $newUserId = $this->userMgr->get($userId)->getDisplayName();
604
+        }
605
+        return new JSONResponse(array(
606
+            'comment' => $commentBox,
607
+            'date' => date('Y-m-d H:i:s'),
608
+            'userName' => $newUserId
609
+        ));
610
+    }
611
+
612
+    /**
613
+     * @NoAdminRequired
614
+     * @NoCSRFRequired
615
+     * @param string $searchTerm
616
+     * @param string $groups
617
+     * @param string $users
618
+     * @return array
619
+     */
620
+    public function search($searchTerm, $groups, $users) {
621
+        return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
622
+    }
623
+
624
+    /**
625
+     * @NoAdminRequired
626
+     * @NoCSRFRequired
627
+     * @param string $searchTerm
628
+     * @param string $groups
629
+     * @return array
630
+     */
631
+    public function searchForGroups($searchTerm, $groups) {
632
+        $selectedGroups = json_decode($groups);
633
+        $groups = $this->groupManager->search($searchTerm);
634
+        $gids = array();
635
+        $sgids = array();
636
+        foreach ($selectedGroups as $sg) {
637
+            $sgids[] = str_replace('group_', '', $sg);
638
+        }
639
+        foreach ($groups as $g) {
640
+            $gids[] = $g->getGID();
641
+        }
642
+        $diffGids = array_diff($gids, $sgids);
643
+        $gids = array();
644
+        foreach ($diffGids as $g) {
645
+            $gids[] = ['gid' => $g, 'isGroup' => true];
646
+        }
647
+        return $gids;
648
+    }
649
+
650
+    /**
651
+     * @NoAdminRequired
652
+     * @NoCSRFRequired
653
+     * @param string $searchTerm
654
+     * @param string $users
655
+     * @return array
656
+     */
657
+    public function searchForUsers($searchTerm, $users) {
658
+        $selectedUsers = json_decode($users);
659
+        Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);
660
+        $userNames = $this->userMgr->searchDisplayName($searchTerm);
661
+        $users = array();
662
+        $sUsers = array();
663
+        foreach ($selectedUsers as $su) {
664
+            $sUsers[] = str_replace('user_', '', $su);
665
+        }
666
+        foreach ($userNames as $u) {
667
+            $alreadyAdded = false;
668
+            foreach ($sUsers as &$su) {
669
+                if ($su === $u->getUID()) {
670
+                    unset($su);
671
+                    $alreadyAdded = true;
672
+                    break;
673
+                }
674
+            }
675
+            if (!$alreadyAdded) {
676
+                $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
677
+            } else {
678
+                continue;
679
+            }
680
+        }
681
+        return $users;
682
+    }
683
+
684
+    /**
685
+     * @NoAdminRequired
686
+     * @NoCSRFRequired
687
+     * @param string $username
688
+     * @return string
689
+     */
690
+    public function getDisplayName($username) {
691
+        return $this->userMgr->get($username)->getDisplayName();
692
+    }
693
+
694
+    /**
695
+     * @return \OCP\IGroup[]
696
+     */
697
+    private function getGroups() {
698
+        if (class_exists('\OC_Group')) {
699
+            // Nextcloud <= 11, ownCloud
700
+            return \OC_Group::getUserGroups($this->userId);
701
+        }
702
+        // Nextcloud >= 12
703
+        $groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
704
+        return array_map(function ($group) {
705
+            return $group->getGID();
706
+        }, $groups);
707
+    }
708
+
709
+    /**
710
+     * @param Event $poll
711
+     * @return bool
712
+     */
713
+    private function hasUserAccess($poll) {
714
+        $access = $poll->getAccess();
715
+        $owner = $poll->getOwner();
716
+        if ($access === 'public' || $access === 'hidden') {
717
+            return true;
718
+        }
719
+        if ($this->userId === null) {
720
+            return false;
721
+        }
722
+        if ($access === 'registered') {
723
+            return true;
724
+        }
725
+        if ($owner === $this->userId) {
726
+            return true;
727
+        }
728
+        Util::writeLog('polls', $this->userId, Util::ERROR);
729
+        $userGroups = $this->getGroups();
730
+        $arr = explode(';', $access);
731
+        foreach ($arr as $item) {
732
+            if (strpos($item, 'group_') === 0) {
733
+                $grp = substr($item, 6);
734
+                foreach ($userGroups as $userGroup) {
735
+                    if ($userGroup === $grp) {
736
+                        return true;
737
+                    }
738
+                }
739
+            } else {
740
+                if (strpos($item, 'user_') === 0) {
741
+                    $usr = substr($item, 5);
742
+                    if ($usr === $this->userId) {
743
+                        return true;
744
+                    }
745
+                }
746
+            }
747
+        }
748
+        return false;
749
+    }
750 750
 }
Please login to merge, or discard this patch.
templates/goto.tmpl.php 3 patches
Indentation   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -1,99 +1,99 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	/**
3
-	 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
-	 *
5
-	 * @author Vinzenz Rosenkranz <[email protected]>
6
-	 *
7
-	 * @license GNU AGPL version 3 or any later version
8
-	 *
9
-	 *  This program is free software: you can redistribute it and/or modify
10
-	 *  it under the terms of the GNU Affero General Public License as
11
-	 *  published by the Free Software Foundation, either version 3 of the
12
-	 *  License, or (at your option) any later version.
13
-	 *
14
-	 *  This program is distributed in the hope that it will be useful,
15
-	 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-	 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
-	 *  GNU Affero General Public License for more details.
18
-	 *
19
-	 *  You should have received a copy of the GNU Affero General Public License
20
-	 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
-	 *
22
-	 */
23
-
24
-	use OCP\User;
25
-
26
-	\OCP\Util::addStyle('polls', 'main');
27
-	\OCP\Util::addStyle('polls', 'vote');
28
-	if (!User::isLoggedIn()) {
29
-		\OCP\Util::addStyle('polls', 'public');
30
-	}
31
-
32
-	\OCP\Util::addScript('polls', 'app');
33
-	\OCP\Util::addScript('polls', 'vote');
34
-
35
-	$userId = $_['userId'];
36
-	/** @var \OCP\IUserManager $userMgr */
37
-	$userMgr = $_['userMgr'];
38
-	/** @var \OCP\IURLGenerator $urlGenerator */
39
-	$urlGenerator = $_['urlGenerator'];
40
-	/** @var \OCP\IAvatarManager $avaMgr */
41
-	$avaMgr = $_['avatarManager'];
42
-	/** @var \OCA\Polls\Db\Event $poll */
43
-	$poll = $_['poll'];
44
-	/** @var OCA\Polls\Db\Date[]|OCA\Polls\Db\Text[] $dates */
45
-	$dates = $_['dates'];
46
-	/** @var OCA\Polls\Db\Participation[]|OCA\Polls\Db\ParticipationText[] $votes */
47
-	$votes = $_['votes'];
48
-	/** @var \OCA\Polls\Db\Comment[] $comments */
49
-	$comments = $_['comments'];
50
-	/** @var \OCA\Polls\Db\Notification $notification */
51
-	$notification = $_['notification'];
52
-
53
-	$isAnonymous = $poll->getIsAnonymous() && $userId !== $poll->getOwner();
54
-	$hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous();
55
-	$access = $poll->getAccess();
56
-	if ($poll->getExpire() === null) {
57
-		$expired = false;
58
-	} else {
59
-		$expired = time() > strtotime($poll->getExpire());
60
-	}
61
-
62
-	if ($expired) {
63
-		$statusClass = 'expired-vote';
64
-	} else {
65
-		$statusClass = 'open-vote';
66
-		if (time() < strtotime($poll->getExpire())) {
67
-			$statusClass .= ' endless';
68
-		}
69
-	}
70
-
71
- 	if ($poll->getType() === 0) {
72
-		$pollType = 'date-poll';
73
-		$pollTypeClass = 'date-poll';
74
-	} else if ($poll->getType() === 1) {
75
-		$pollType = 'option-poll';
76
-		$pollTypeClass = 'option-poll';
77
-	}
78
-
79
-
80
-	if (
81
-		$poll->getDescription() !== null &&
82
-		$poll->getDescription() !== ''
83
-	) {
84
-		$description = $poll->getDescription();
85
-	} else {
86
-		$description = $l->t('No description provided.');
87
-	}
88
-
89
-	// init array for counting 'yes'-votes for each date
90
-	$total = array();
91
-	for ($i = 0; $i < count($dates); $i++) {
92
-		$total['yes'][$i] = 0;
93
-		$total['no'][$i] = 0;
94
-	}
95
-	$userVoted = array();
96
-	$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]);
2
+    /**
3
+     * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
+     *
5
+     * @author Vinzenz Rosenkranz <[email protected]>
6
+     *
7
+     * @license GNU AGPL version 3 or any later version
8
+     *
9
+     *  This program is free software: you can redistribute it and/or modify
10
+     *  it under the terms of the GNU Affero General Public License as
11
+     *  published by the Free Software Foundation, either version 3 of the
12
+     *  License, or (at your option) any later version.
13
+     *
14
+     *  This program is distributed in the hope that it will be useful,
15
+     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+     *  GNU Affero General Public License for more details.
18
+     *
19
+     *  You should have received a copy of the GNU Affero General Public License
20
+     *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+     *
22
+     */
23
+
24
+    use OCP\User;
25
+
26
+    \OCP\Util::addStyle('polls', 'main');
27
+    \OCP\Util::addStyle('polls', 'vote');
28
+    if (!User::isLoggedIn()) {
29
+        \OCP\Util::addStyle('polls', 'public');
30
+    }
31
+
32
+    \OCP\Util::addScript('polls', 'app');
33
+    \OCP\Util::addScript('polls', 'vote');
34
+
35
+    $userId = $_['userId'];
36
+    /** @var \OCP\IUserManager $userMgr */
37
+    $userMgr = $_['userMgr'];
38
+    /** @var \OCP\IURLGenerator $urlGenerator */
39
+    $urlGenerator = $_['urlGenerator'];
40
+    /** @var \OCP\IAvatarManager $avaMgr */
41
+    $avaMgr = $_['avatarManager'];
42
+    /** @var \OCA\Polls\Db\Event $poll */
43
+    $poll = $_['poll'];
44
+    /** @var OCA\Polls\Db\Date[]|OCA\Polls\Db\Text[] $dates */
45
+    $dates = $_['dates'];
46
+    /** @var OCA\Polls\Db\Participation[]|OCA\Polls\Db\ParticipationText[] $votes */
47
+    $votes = $_['votes'];
48
+    /** @var \OCA\Polls\Db\Comment[] $comments */
49
+    $comments = $_['comments'];
50
+    /** @var \OCA\Polls\Db\Notification $notification */
51
+    $notification = $_['notification'];
52
+
53
+    $isAnonymous = $poll->getIsAnonymous() && $userId !== $poll->getOwner();
54
+    $hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous();
55
+    $access = $poll->getAccess();
56
+    if ($poll->getExpire() === null) {
57
+        $expired = false;
58
+    } else {
59
+        $expired = time() > strtotime($poll->getExpire());
60
+    }
61
+
62
+    if ($expired) {
63
+        $statusClass = 'expired-vote';
64
+    } else {
65
+        $statusClass = 'open-vote';
66
+        if (time() < strtotime($poll->getExpire())) {
67
+            $statusClass .= ' endless';
68
+        }
69
+    }
70
+
71
+        if ($poll->getType() === 0) {
72
+        $pollType = 'date-poll';
73
+        $pollTypeClass = 'date-poll';
74
+    } else if ($poll->getType() === 1) {
75
+        $pollType = 'option-poll';
76
+        $pollTypeClass = 'option-poll';
77
+    }
78
+
79
+
80
+    if (
81
+        $poll->getDescription() !== null &&
82
+        $poll->getDescription() !== ''
83
+    ) {
84
+        $description = $poll->getDescription();
85
+    } else {
86
+        $description = $l->t('No description provided.');
87
+    }
88
+
89
+    // init array for counting 'yes'-votes for each date
90
+    $total = array();
91
+    for ($i = 0; $i < count($dates); $i++) {
92
+        $total['yes'][$i] = 0;
93
+        $total['no'][$i] = 0;
94
+    }
95
+    $userVoted = array();
96
+    $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]);
97 97
 ?>
98 98
 
99 99
 <div id="app">
@@ -127,84 +127,84 @@  discard block
 block discarded – undo
127 127
 		<div id="votings" class="main-container">
128 128
 			<div class="wordwrap description"><span><?php p($description); ?></span>
129 129
 			<?php
130
-				if ($expired) {
131
-					print_unescaped('<span class="' . $statusClass . '">' . $l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire())))) . '</span>');
132
-				}?>
130
+                if ($expired) {
131
+                    print_unescaped('<span class="' . $statusClass . '">' . $l->t('The poll expired on %s. Voting is disabled, but you can still comment.', array(date('d.m.Y H:i', strtotime($poll->getExpire())))) . '</span>');
132
+                }?>
133 133
 			</div>
134 134
 			<div class="table">
135 135
 					<ul class="table-row header" >
136 136
 						<?php
137
-						foreach ($dates as $dateElement) {
138
-							if ($poll->getType() === 0) {
139
-								$timestamp = strtotime($dateElement->getDt());
140
-								print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . $dateElement->getDt() . ' ' . date_default_timezone_get() . '" class="column vote time has-tooltip" data-timestamp="' . $timestamp . '"data-value-utc="' . $dateElement->getDt() . '">');
141
-
142
-								print_unescaped('	<div class="date-box column">');
143
-								print_unescaped('		<div class="month">' . $l->t(date('M', $timestamp))  . '</div>');
144
-								print_unescaped('		<div class="day">'   .       date('j', $timestamp)   . '</div>');
145
-								print_unescaped('		<div class="dayow">' . $l->t(date('D', $timestamp))  . '</div>');
146
-								print_unescaped('		<div class="time">'  .       date('G:i', $timestamp) . ' UTC</div>');
147
-								print_unescaped('	</div>');
148
-							} else {
149
-								print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . preg_replace('/_\d+$/', '', $dateElement->getText()) . '" class="column vote option">');
150
-								print_unescaped('	<div class="date-box column">' . preg_replace('/_\d+$/', '', $dateElement->getText()).'</div>');
151
-							}
152
-							print_unescaped('<div class="counter table-row">');
153
-							print_unescaped('	<div class="yes table-row">');
154
-							print_unescaped('		<div class="svg"></div>');
155
-							print_unescaped('		<div id="counter_yes_voteid_' . $dateElement->getId() . '" class ="result-cell yes" data-voteId="' . $dateElement->getId() . '">0</div>');
156
-							print_unescaped('	</div>');
157
-							print_unescaped('	<div class="no table-row">');
158
-							print_unescaped('		<div class="svg"></div>');
159
-							print_unescaped('		<div id="counter_no_voteid_' . $dateElement->getId() . '" class ="result-cell no" data-voteId="' . $dateElement->getId() . '">0</div>');
160
-							print_unescaped('	</div>');
161
-							print_unescaped('</div>');
162
-						}
163
-						?>
137
+                        foreach ($dates as $dateElement) {
138
+                            if ($poll->getType() === 0) {
139
+                                $timestamp = strtotime($dateElement->getDt());
140
+                                print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . $dateElement->getDt() . ' ' . date_default_timezone_get() . '" class="column vote time has-tooltip" data-timestamp="' . $timestamp . '"data-value-utc="' . $dateElement->getDt() . '">');
141
+
142
+                                print_unescaped('	<div class="date-box column">');
143
+                                print_unescaped('		<div class="month">' . $l->t(date('M', $timestamp))  . '</div>');
144
+                                print_unescaped('		<div class="day">'   .       date('j', $timestamp)   . '</div>');
145
+                                print_unescaped('		<div class="dayow">' . $l->t(date('D', $timestamp))  . '</div>');
146
+                                print_unescaped('		<div class="time">'  .       date('G:i', $timestamp) . ' UTC</div>');
147
+                                print_unescaped('	</div>');
148
+                            } else {
149
+                                print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . preg_replace('/_\d+$/', '', $dateElement->getText()) . '" class="column vote option">');
150
+                                print_unescaped('	<div class="date-box column">' . preg_replace('/_\d+$/', '', $dateElement->getText()).'</div>');
151
+                            }
152
+                            print_unescaped('<div class="counter table-row">');
153
+                            print_unescaped('	<div class="yes table-row">');
154
+                            print_unescaped('		<div class="svg"></div>');
155
+                            print_unescaped('		<div id="counter_yes_voteid_' . $dateElement->getId() . '" class ="result-cell yes" data-voteId="' . $dateElement->getId() . '">0</div>');
156
+                            print_unescaped('	</div>');
157
+                            print_unescaped('	<div class="no table-row">');
158
+                            print_unescaped('		<div class="svg"></div>');
159
+                            print_unescaped('		<div id="counter_no_voteid_' . $dateElement->getId() . '" class ="result-cell no" data-voteId="' . $dateElement->getId() . '">0</div>');
160
+                            print_unescaped('	</div>');
161
+                            print_unescaped('</div>');
162
+                        }
163
+                        ?>
164 164
 						</li>
165 165
 					</ul>
166 166
 				<ul class="column table-body">
167 167
 					<?php
168
-					if ($votes !== null) {
169
-						//group by user
170
-						$others = array();
171
-						$displayName = '';
172
-						$avatarName = '';
173
-						$activeClass = '';
174
-						foreach ($votes as $vote) {
175
-							if (!isset($others[$vote->getUserId()])) {
176
-								$others[$vote->getUserId()] = array();
177
-							}
178
-							$others[$vote->getUserId()][]= $vote;
179
-						}
180
-						$userCnt = 0;
181
-						foreach (array_keys($others) as $usr) {
182
-							$userCnt++;
183
-							if ($usr === $userId) {
184
-								// if poll expired, just put current user among the others;
185
-								// otherwise skip here to add current user as last table-row (to vote)
186
-								if (!$expired) {
187
-									$userVoted = $others[$usr];
188
-									continue;
189
-								}
190
-							}
191
-							if (
192
-								$userMgr->get($usr) !== null &&
193
-								!$isAnonymous &&
194
-								!$hideNames
195
-							) {
196
-								$displayName = $userMgr->get($usr)->getDisplayName();
197
-								$avatarName = $usr;
198
-							} else {
199
-								if ($isAnonymous || $hideNames) {
200
-									$displayName = 'Anonymous';
201
-									$avatarName = $userCnt;
202
-								} else {
203
-									$displayName = $usr;
204
-									$avatarName = $usr;
205
-								}
206
-							}
207
-							?>
168
+                    if ($votes !== null) {
169
+                        //group by user
170
+                        $others = array();
171
+                        $displayName = '';
172
+                        $avatarName = '';
173
+                        $activeClass = '';
174
+                        foreach ($votes as $vote) {
175
+                            if (!isset($others[$vote->getUserId()])) {
176
+                                $others[$vote->getUserId()] = array();
177
+                            }
178
+                            $others[$vote->getUserId()][]= $vote;
179
+                        }
180
+                        $userCnt = 0;
181
+                        foreach (array_keys($others) as $usr) {
182
+                            $userCnt++;
183
+                            if ($usr === $userId) {
184
+                                // if poll expired, just put current user among the others;
185
+                                // otherwise skip here to add current user as last table-row (to vote)
186
+                                if (!$expired) {
187
+                                    $userVoted = $others[$usr];
188
+                                    continue;
189
+                                }
190
+                            }
191
+                            if (
192
+                                $userMgr->get($usr) !== null &&
193
+                                !$isAnonymous &&
194
+                                !$hideNames
195
+                            ) {
196
+                                $displayName = $userMgr->get($usr)->getDisplayName();
197
+                                $avatarName = $usr;
198
+                            } else {
199
+                                if ($isAnonymous || $hideNames) {
200
+                                    $displayName = 'Anonymous';
201
+                                    $avatarName = $userCnt;
202
+                                } else {
203
+                                    $displayName = $usr;
204
+                                    $avatarName = $usr;
205
+                                }
206
+                            }
207
+                            ?>
208 208
 							<li class="table-row user">
209 209
 								<div class="first">
210 210
 									<div class="user-cell table-row">
@@ -214,109 +214,109 @@  discard block
 block discarded – undo
214 214
 									</div>
215 215
 									<ul class="table-row">
216 216
 							<?php
217
-							// loop over dts
218
-							$i_tot = 0;
219
-
220
-							foreach ($dates as $dateElement) {
221
-								if ($poll->getType() === 0) {
222
-									$dateId = strtotime($dateElement->getDt());
223
-									$pollId = 'voteid_' . $dateElement->getId();
224
-								} else {
225
-									$dateId = $dateElement->getText();
226
-									$pollId = 'voteid_' . $dateElement->getId();
227
-								}
228
-								// look what user voted for this dts
229
-								$class = 'column poll-cell no';
230
-								foreach ($others[$usr] as $vote) {
231
-									$voteVal = null;
232
-									if ($poll->getType() === 0) {
233
-										$voteVal = strtotime($vote->getDt());
234
-									} else {
235
-										$voteVal = $vote->getText();
236
-									}
237
-									if ($dateId === $voteVal) {
238
-										if ($vote->getType() === 1) {
239
-											$class = 'column poll-cell yes';
240
-											$total['yes'][$i_tot]++;
241
-										} else if ($vote->getType() === 0) {
242
-											$class = 'column poll-cell no';
243
-											$total['no'][$i_tot]++;
244
-										} else if ($vote->getType() === 2) {
245
-											$class = 'column poll-cell maybe';
246
-										}
247
-										break;
248
-									}
249
-								}
250
-								print_unescaped('<li id="'. $pollId . '" class="' . $class . '"></li>');
251
-								$i_tot++;
252
-							}
253
-
254
-							print_unescaped('</ul>');
255
-							print_unescaped('</li>');
256
-						}
257
-					}
258
-					$totalYesOthers = array_merge(array(), $total['yes']);
259
-					$totalNoOthers = array_merge(array(), $total['no']);
260
-					$toggleTooltip = $l->t('Switch all options at once');
261
-					if (!$expired) {
262
-						print_unescaped('<li class="table-row user current-user">');
263
-						print_unescaped('	<div class="table-row first">');
264
-						print_unescaped('		<div class="user-cell table-row">');
265
-						if (User::isLoggedIn()) {
266
-							print_unescaped('		<div class="avatar has-tooltip" title="'.($userId).'"></div>');
267
-							print_unescaped('		<div class="name">');
268
-							p($userMgr->get($userId)->getDisplayName());
269
-						} else {
270
-							print_unescaped('		<div class="avatar has-tooltip" title="?"></div>');
271
-							print_unescaped('		<div id="id_ac_detected" class="name external current-user"><input type="text" name="user_name" id="user_name" placeholder="' . $l->t('Your name here') . '" />');
272
-						}
273
-						print_unescaped('		</div>');
274
-						print_unescaped('	</div>');
275
-						print_unescaped('	<div id="toggle-cell" class="toggle-cell has-tooltip maybe" title="'. $toggleTooltip .'">');
276
-						print_unescaped('		<div class="toggle"></div>');
277
-						print_unescaped('	</div>');
278
-						print_unescaped('</div>');
279
-						print_unescaped('<ul class="table-row">');
280
-
281
-						$i_tot = 0;
282
-						foreach ($dates as $dateElement) {
283
-							if ($poll->getType() === 0) {
284
-								$dateId = strtotime($dateElement->getDt());
285
-								$pollId = 'voteid_' . $dateElement->getId();
286
-							} else {
287
-								$dateId = $dateElement->getText();
288
-								$pollId = 'voteid_' . $dateElement->getId();
289
-							}
290
-							// see if user already has data for this event
291
-							$class = 'no';
292
-							$activeClass = 'column active poll-cell';
293
-							if (isset($userVoted)) {
294
-								foreach ($userVoted as $obj) {
295
-									$voteVal = null;
296
-									if($poll->getType() === 0) {
297
-										$voteVal = strtotime($obj->getDt());
298
-									} else {
299
-										$voteVal = $obj->getText();
300
-									}
301
-									if ($voteVal === $dateId) {
302
-										if ($obj->getType() === 1) {
303
-											$class = 'yes';
304
-											$total['yes'][$i_tot]++;
305
-										} else if($obj->getType() === 2) {
306
-											$class = 'maybe';
307
-										}
308
-										break;
309
-									}
310
-								}
311
-							}
312
-							print_unescaped('<li id="' . $pollId . '" class="' . $activeClass . ' ' . $class . '" data-value="' . $dateId . '"></li>');
313
-
314
-							$i_tot++;
315
-						}
316
-						print_unescaped('</ul>');
317
-						print_unescaped('</li>');
318
-					}
319
-					?>
217
+                            // loop over dts
218
+                            $i_tot = 0;
219
+
220
+                            foreach ($dates as $dateElement) {
221
+                                if ($poll->getType() === 0) {
222
+                                    $dateId = strtotime($dateElement->getDt());
223
+                                    $pollId = 'voteid_' . $dateElement->getId();
224
+                                } else {
225
+                                    $dateId = $dateElement->getText();
226
+                                    $pollId = 'voteid_' . $dateElement->getId();
227
+                                }
228
+                                // look what user voted for this dts
229
+                                $class = 'column poll-cell no';
230
+                                foreach ($others[$usr] as $vote) {
231
+                                    $voteVal = null;
232
+                                    if ($poll->getType() === 0) {
233
+                                        $voteVal = strtotime($vote->getDt());
234
+                                    } else {
235
+                                        $voteVal = $vote->getText();
236
+                                    }
237
+                                    if ($dateId === $voteVal) {
238
+                                        if ($vote->getType() === 1) {
239
+                                            $class = 'column poll-cell yes';
240
+                                            $total['yes'][$i_tot]++;
241
+                                        } else if ($vote->getType() === 0) {
242
+                                            $class = 'column poll-cell no';
243
+                                            $total['no'][$i_tot]++;
244
+                                        } else if ($vote->getType() === 2) {
245
+                                            $class = 'column poll-cell maybe';
246
+                                        }
247
+                                        break;
248
+                                    }
249
+                                }
250
+                                print_unescaped('<li id="'. $pollId . '" class="' . $class . '"></li>');
251
+                                $i_tot++;
252
+                            }
253
+
254
+                            print_unescaped('</ul>');
255
+                            print_unescaped('</li>');
256
+                        }
257
+                    }
258
+                    $totalYesOthers = array_merge(array(), $total['yes']);
259
+                    $totalNoOthers = array_merge(array(), $total['no']);
260
+                    $toggleTooltip = $l->t('Switch all options at once');
261
+                    if (!$expired) {
262
+                        print_unescaped('<li class="table-row user current-user">');
263
+                        print_unescaped('	<div class="table-row first">');
264
+                        print_unescaped('		<div class="user-cell table-row">');
265
+                        if (User::isLoggedIn()) {
266
+                            print_unescaped('		<div class="avatar has-tooltip" title="'.($userId).'"></div>');
267
+                            print_unescaped('		<div class="name">');
268
+                            p($userMgr->get($userId)->getDisplayName());
269
+                        } else {
270
+                            print_unescaped('		<div class="avatar has-tooltip" title="?"></div>');
271
+                            print_unescaped('		<div id="id_ac_detected" class="name external current-user"><input type="text" name="user_name" id="user_name" placeholder="' . $l->t('Your name here') . '" />');
272
+                        }
273
+                        print_unescaped('		</div>');
274
+                        print_unescaped('	</div>');
275
+                        print_unescaped('	<div id="toggle-cell" class="toggle-cell has-tooltip maybe" title="'. $toggleTooltip .'">');
276
+                        print_unescaped('		<div class="toggle"></div>');
277
+                        print_unescaped('	</div>');
278
+                        print_unescaped('</div>');
279
+                        print_unescaped('<ul class="table-row">');
280
+
281
+                        $i_tot = 0;
282
+                        foreach ($dates as $dateElement) {
283
+                            if ($poll->getType() === 0) {
284
+                                $dateId = strtotime($dateElement->getDt());
285
+                                $pollId = 'voteid_' . $dateElement->getId();
286
+                            } else {
287
+                                $dateId = $dateElement->getText();
288
+                                $pollId = 'voteid_' . $dateElement->getId();
289
+                            }
290
+                            // see if user already has data for this event
291
+                            $class = 'no';
292
+                            $activeClass = 'column active poll-cell';
293
+                            if (isset($userVoted)) {
294
+                                foreach ($userVoted as $obj) {
295
+                                    $voteVal = null;
296
+                                    if($poll->getType() === 0) {
297
+                                        $voteVal = strtotime($obj->getDt());
298
+                                    } else {
299
+                                        $voteVal = $obj->getText();
300
+                                    }
301
+                                    if ($voteVal === $dateId) {
302
+                                        if ($obj->getType() === 1) {
303
+                                            $class = 'yes';
304
+                                            $total['yes'][$i_tot]++;
305
+                                        } else if($obj->getType() === 2) {
306
+                                            $class = 'maybe';
307
+                                        }
308
+                                        break;
309
+                                    }
310
+                                }
311
+                            }
312
+                            print_unescaped('<li id="' . $pollId . '" class="' . $activeClass . ' ' . $class . '" data-value="' . $dateId . '"></li>');
313
+
314
+                            $i_tot++;
315
+                        }
316
+                        print_unescaped('</ul>');
317
+                        print_unescaped('</li>');
318
+                    }
319
+                    ?>
320 320
 				</ul>
321 321
 			</div>
322 322
 			<div class="submitPoll table-row">
@@ -355,30 +355,30 @@  discard block
 block discarded – undo
355 355
 
356 356
 					<div class="cloud">
357 357
 						<?php
358
-						if ($expired) {
359
-							print_unescaped('<span class="expired">' . $l->t('Expired'). '</span>');
360
-						} else {
361
-							if ($poll->getExpire() !== null){
362
-								print_unescaped('<span class="open">' . $l->t('Expires on %s', array(date('d.m.Y', strtotime($poll->getExpire())))) . '</span>');
363
-							} else {
364
-								print_unescaped('<span class="open">' . $l->t('Expires never') . '</span>');
365
-							}
366
-						}
367
-
368
-						if ($access === 'public' || $access === 'hidden' || $access === 'registered') {
369
-							print_unescaped('<span class="information">' . $access . '</span>');
370
-						} else {
371
-							print_unescaped('<span class="information">' . $l->t('Invitation access') . '</span>');
372
-						}
373
-						if ($isAnonymous) {
374
-							print_unescaped('<span class="information">' . $l->t('Anononymous poll') . '</span>');
375
-							if ($hideNames) {
376
-								print_unescaped('<span class="information">' . $l->t('Usernames hidden to Owner') . '</span>');
377
-							} else {
378
-								print_unescaped('<span class="information">' . $l->t('Usernames visible to Owner') . '</span>');
379
-							}
380
-						}
381
-						?>
358
+                        if ($expired) {
359
+                            print_unescaped('<span class="expired">' . $l->t('Expired'). '</span>');
360
+                        } else {
361
+                            if ($poll->getExpire() !== null){
362
+                                print_unescaped('<span class="open">' . $l->t('Expires on %s', array(date('d.m.Y', strtotime($poll->getExpire())))) . '</span>');
363
+                            } else {
364
+                                print_unescaped('<span class="open">' . $l->t('Expires never') . '</span>');
365
+                            }
366
+                        }
367
+
368
+                        if ($access === 'public' || $access === 'hidden' || $access === 'registered') {
369
+                            print_unescaped('<span class="information">' . $access . '</span>');
370
+                        } else {
371
+                            print_unescaped('<span class="information">' . $l->t('Invitation access') . '</span>');
372
+                        }
373
+                        if ($isAnonymous) {
374
+                            print_unescaped('<span class="information">' . $l->t('Anononymous poll') . '</span>');
375
+                            if ($hideNames) {
376
+                                print_unescaped('<span class="information">' . $l->t('Usernames hidden to Owner') . '</span>');
377
+                            } else {
378
+                                print_unescaped('<span class="information">' . $l->t('Usernames visible to Owner') . '</span>');
379
+                            }
380
+                        }
381
+                        ?>
382 382
 					</div>
383 383
 
384 384
 				</div>
@@ -462,31 +462,31 @@  discard block
 block discarded – undo
462 462
 					<?php foreach ($comments as $comment) : ?>
463 463
 
464 464
 						<?php
465
-							if ( $comment->getUserId() === $userId ) {
466
-								// Comment is from current user
467
-								// -> display user
468
-								$avatarName = $userId;
469
-								$displayName = $userMgr->get($userId)->getDisplayName();
470
-
471
-							} else if ( !$isAnonymous && !$hideNames ) {
472
-								// comment is from another user,
473
-								// poll is not anoymous (for current user)
474
-								// users are not hidden
475
-								// -> display user
476
-								$avatarName = $comment->getUserId();
477
-								$displayName = $avatarName;
478
-								if ($userMgr->get($comment->getUserId()) !== null) {
479
-									$displayName = $userMgr->get($avatarName)->getDisplayName();
480
-								}
481
-							} else {
482
-								// in all other cases
483
-								// -> make user anonymous
484
-								// poll is anonymous and current user is not owner
485
-								// or names are hidden
486
-								$displayName = 'Anonymous';
487
-								$avatarName = $displayName;
488
-							}
489
-						?>
465
+                            if ( $comment->getUserId() === $userId ) {
466
+                                // Comment is from current user
467
+                                // -> display user
468
+                                $avatarName = $userId;
469
+                                $displayName = $userMgr->get($userId)->getDisplayName();
470
+
471
+                            } else if ( !$isAnonymous && !$hideNames ) {
472
+                                // comment is from another user,
473
+                                // poll is not anoymous (for current user)
474
+                                // users are not hidden
475
+                                // -> display user
476
+                                $avatarName = $comment->getUserId();
477
+                                $displayName = $avatarName;
478
+                                if ($userMgr->get($comment->getUserId()) !== null) {
479
+                                    $displayName = $userMgr->get($avatarName)->getDisplayName();
480
+                                }
481
+                            } else {
482
+                                // in all other cases
483
+                                // -> make user anonymous
484
+                                // poll is anonymous and current user is not owner
485
+                                // or names are hidden
486
+                                $displayName = 'Anonymous';
487
+                                $avatarName = $displayName;
488
+                            }
489
+                        ?>
490 490
 
491 491
 						<li id="comment_<?php p($comment->getId()); ?>" class="comment column">
492 492
 							<div class="authorRow user-cell table-row">
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -32,23 +32,23 @@  discard block
 block discarded – undo
32 32
 	\OCP\Util::addScript('polls', 'app');
33 33
 	\OCP\Util::addScript('polls', 'vote');
34 34
 
35
-	$userId = $_['userId'];
35
+	$userId = $_[ 'userId' ];
36 36
 	/** @var \OCP\IUserManager $userMgr */
37
-	$userMgr = $_['userMgr'];
37
+	$userMgr = $_[ 'userMgr' ];
38 38
 	/** @var \OCP\IURLGenerator $urlGenerator */
39
-	$urlGenerator = $_['urlGenerator'];
39
+	$urlGenerator = $_[ 'urlGenerator' ];
40 40
 	/** @var \OCP\IAvatarManager $avaMgr */
41
-	$avaMgr = $_['avatarManager'];
41
+	$avaMgr = $_[ 'avatarManager' ];
42 42
 	/** @var \OCA\Polls\Db\Event $poll */
43
-	$poll = $_['poll'];
43
+	$poll = $_[ 'poll' ];
44 44
 	/** @var OCA\Polls\Db\Date[]|OCA\Polls\Db\Text[] $dates */
45
-	$dates = $_['dates'];
45
+	$dates = $_[ 'dates' ];
46 46
 	/** @var OCA\Polls\Db\Participation[]|OCA\Polls\Db\ParticipationText[] $votes */
47
-	$votes = $_['votes'];
47
+	$votes = $_[ 'votes' ];
48 48
 	/** @var \OCA\Polls\Db\Comment[] $comments */
49
-	$comments = $_['comments'];
49
+	$comments = $_[ 'comments' ];
50 50
 	/** @var \OCA\Polls\Db\Notification $notification */
51
-	$notification = $_['notification'];
51
+	$notification = $_[ 'notification' ];
52 52
 
53 53
 	$isAnonymous = $poll->getIsAnonymous() && $userId !== $poll->getOwner();
54 54
 	$hideNames = $poll->getIsAnonymous() && $poll->getFullAnonymous();
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
 	// init array for counting 'yes'-votes for each date
90 90
 	$total = array();
91 91
 	for ($i = 0; $i < count($dates); $i++) {
92
-		$total['yes'][$i] = 0;
93
-		$total['no'][$i] = 0;
92
+		$total[ 'yes' ][ $i ] = 0;
93
+		$total[ 'no' ][ $i ] = 0;
94 94
 	}
95 95
 	$userVoted = array();
96
-	$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', ['hash' => $poll->getHash()]);
96
+	$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', [ 'hash' => $poll->getHash() ]);
97 97
 ?>
98 98
 
99 99
 <div id="app">
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
 								print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . $dateElement->getDt() . ' ' . date_default_timezone_get() . '" class="column vote time has-tooltip" data-timestamp="' . $timestamp . '"data-value-utc="' . $dateElement->getDt() . '">');
141 141
 
142 142
 								print_unescaped('	<div class="date-box column">');
143
-								print_unescaped('		<div class="month">' . $l->t(date('M', $timestamp))  . '</div>');
144
-								print_unescaped('		<div class="day">'   .       date('j', $timestamp)   . '</div>');
145
-								print_unescaped('		<div class="dayow">' . $l->t(date('D', $timestamp))  . '</div>');
146
-								print_unescaped('		<div class="time">'  .       date('G:i', $timestamp) . ' UTC</div>');
143
+								print_unescaped('		<div class="month">' . $l->t(date('M', $timestamp)) . '</div>');
144
+								print_unescaped('		<div class="day">' . date('j', $timestamp) . '</div>');
145
+								print_unescaped('		<div class="dayow">' . $l->t(date('D', $timestamp)) . '</div>');
146
+								print_unescaped('		<div class="time">' . date('G:i', $timestamp) . ' UTC</div>');
147 147
 								print_unescaped('	</div>');
148 148
 							} else {
149 149
 								print_unescaped('<li id="slot_' . $dateElement->getId() . '" title="' . preg_replace('/_\d+$/', '', $dateElement->getText()) . '" class="column vote option">');
150
-								print_unescaped('	<div class="date-box column">' . preg_replace('/_\d+$/', '', $dateElement->getText()).'</div>');
150
+								print_unescaped('	<div class="date-box column">' . preg_replace('/_\d+$/', '', $dateElement->getText()) . '</div>');
151 151
 							}
152 152
 							print_unescaped('<div class="counter table-row">');
153 153
 							print_unescaped('	<div class="yes table-row">');
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
 						$avatarName = '';
173 173
 						$activeClass = '';
174 174
 						foreach ($votes as $vote) {
175
-							if (!isset($others[$vote->getUserId()])) {
176
-								$others[$vote->getUserId()] = array();
175
+							if (!isset($others[ $vote->getUserId() ])) {
176
+								$others[ $vote->getUserId() ] = array();
177 177
 							}
178
-							$others[$vote->getUserId()][]= $vote;
178
+							$others[ $vote->getUserId() ][ ] = $vote;
179 179
 						}
180 180
 						$userCnt = 0;
181 181
 						foreach (array_keys($others) as $usr) {
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 								// if poll expired, just put current user among the others;
185 185
 								// otherwise skip here to add current user as last table-row (to vote)
186 186
 								if (!$expired) {
187
-									$userVoted = $others[$usr];
187
+									$userVoted = $others[ $usr ];
188 188
 									continue;
189 189
 								}
190 190
 							}
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 								}
228 228
 								// look what user voted for this dts
229 229
 								$class = 'column poll-cell no';
230
-								foreach ($others[$usr] as $vote) {
230
+								foreach ($others[ $usr ] as $vote) {
231 231
 									$voteVal = null;
232 232
 									if ($poll->getType() === 0) {
233 233
 										$voteVal = strtotime($vote->getDt());
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
 									if ($dateId === $voteVal) {
238 238
 										if ($vote->getType() === 1) {
239 239
 											$class = 'column poll-cell yes';
240
-											$total['yes'][$i_tot]++;
240
+											$total[ 'yes' ][ $i_tot ]++;
241 241
 										} else if ($vote->getType() === 0) {
242 242
 											$class = 'column poll-cell no';
243
-											$total['no'][$i_tot]++;
243
+											$total[ 'no' ][ $i_tot ]++;
244 244
 										} else if ($vote->getType() === 2) {
245 245
 											$class = 'column poll-cell maybe';
246 246
 										}
247 247
 										break;
248 248
 									}
249 249
 								}
250
-								print_unescaped('<li id="'. $pollId . '" class="' . $class . '"></li>');
250
+								print_unescaped('<li id="' . $pollId . '" class="' . $class . '"></li>');
251 251
 								$i_tot++;
252 252
 							}
253 253
 
@@ -255,15 +255,15 @@  discard block
 block discarded – undo
255 255
 							print_unescaped('</li>');
256 256
 						}
257 257
 					}
258
-					$totalYesOthers = array_merge(array(), $total['yes']);
259
-					$totalNoOthers = array_merge(array(), $total['no']);
258
+					$totalYesOthers = array_merge(array(), $total[ 'yes' ]);
259
+					$totalNoOthers = array_merge(array(), $total[ 'no' ]);
260 260
 					$toggleTooltip = $l->t('Switch all options at once');
261 261
 					if (!$expired) {
262 262
 						print_unescaped('<li class="table-row user current-user">');
263 263
 						print_unescaped('	<div class="table-row first">');
264 264
 						print_unescaped('		<div class="user-cell table-row">');
265 265
 						if (User::isLoggedIn()) {
266
-							print_unescaped('		<div class="avatar has-tooltip" title="'.($userId).'"></div>');
266
+							print_unescaped('		<div class="avatar has-tooltip" title="' . ($userId) . '"></div>');
267 267
 							print_unescaped('		<div class="name">');
268 268
 							p($userMgr->get($userId)->getDisplayName());
269 269
 						} else {
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 						}
273 273
 						print_unescaped('		</div>');
274 274
 						print_unescaped('	</div>');
275
-						print_unescaped('	<div id="toggle-cell" class="toggle-cell has-tooltip maybe" title="'. $toggleTooltip .'">');
275
+						print_unescaped('	<div id="toggle-cell" class="toggle-cell has-tooltip maybe" title="' . $toggleTooltip . '">');
276 276
 						print_unescaped('		<div class="toggle"></div>');
277 277
 						print_unescaped('	</div>');
278 278
 						print_unescaped('</div>');
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 							if (isset($userVoted)) {
294 294
 								foreach ($userVoted as $obj) {
295 295
 									$voteVal = null;
296
-									if($poll->getType() === 0) {
296
+									if ($poll->getType() === 0) {
297 297
 										$voteVal = strtotime($obj->getDt());
298 298
 									} else {
299 299
 										$voteVal = $obj->getText();
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 									if ($voteVal === $dateId) {
302 302
 										if ($obj->getType() === 1) {
303 303
 											$class = 'yes';
304
-											$total['yes'][$i_tot]++;
305
-										} else if($obj->getType() === 2) {
304
+											$total[ 'yes' ][ $i_tot ]++;
305
+										} else if ($obj->getType() === 2) {
306 306
 											$class = 'maybe';
307 307
 										}
308 308
 										break;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 
343 343
 		<div id="app-sidebar" class="detailsView scroll-container disappear">
344 344
 			<div class="close table-row">
345
-				<a id="closeDetails" class="close icon-close" href="#" alt="<?php $l->t('Close');?>"></a>
345
+				<a id="closeDetails" class="close icon-close" href="#" alt="<?php $l->t('Close'); ?>"></a>
346 346
 			</div>
347 347
 
348 348
 			<div class="header table-row">
@@ -356,9 +356,9 @@  discard block
 block discarded – undo
356 356
 					<div class="cloud">
357 357
 						<?php
358 358
 						if ($expired) {
359
-							print_unescaped('<span class="expired">' . $l->t('Expired'). '</span>');
359
+							print_unescaped('<span class="expired">' . $l->t('Expired') . '</span>');
360 360
 						} else {
361
-							if ($poll->getExpire() !== null){
361
+							if ($poll->getExpire() !== null) {
362 362
 								print_unescaped('<span class="open">' . $l->t('Expires on %s', array(date('d.m.Y', strtotime($poll->getExpire())))) . '</span>');
363 363
 							} else {
364 364
 								print_unescaped('<span class="open">' . $l->t('Expires never') . '</span>');
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 							</a>
398 398
 						</li>
399 399
 						<li>
400
-							<a id="id_edit_<?php p($poll->getId()); ?>" class="icon-rename svg" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>">
400
+							<a id="id_edit_<?php p($poll->getId()); ?>" class="icon-rename svg" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', [ 'hash' => $poll->getHash() ])); ?>">
401 401
 								<?php p($l->t('Edit Poll')); ?>
402 402
 							</a>
403 403
 						</li>
@@ -462,13 +462,13 @@  discard block
 block discarded – undo
462 462
 					<?php foreach ($comments as $comment) : ?>
463 463
 
464 464
 						<?php
465
-							if ( $comment->getUserId() === $userId ) {
465
+							if ($comment->getUserId() === $userId) {
466 466
 								// Comment is from current user
467 467
 								// -> display user
468 468
 								$avatarName = $userId;
469 469
 								$displayName = $userMgr->get($userId)->getDisplayName();
470 470
 
471
-							} else if ( !$isAnonymous && !$hideNames ) {
471
+							} else if (!$isAnonymous && !$hideNames) {
472 472
 								// comment is from another user,
473 473
 								// poll is not anoymous (for current user)
474 474
 								// users are not hidden
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 							<div class="authorRow user-cell table-row">
493 493
 								<div class="avatar has-tooltip" title="<?php p($avatarName)?>"></div>
494 494
 								<div class="author"><?php p($displayName) ?></div>
495
-								<div class="date has-tooltip live-relative-timestamp datespan" data-timestamp="<?php p(strtotime($comment->getDt())*1000); ?>" title="<?php p($comment->getDt()) ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($comment->getDt()))) ?></div>
495
+								<div class="date has-tooltip live-relative-timestamp datespan" data-timestamp="<?php p(strtotime($comment->getDt()) * 1000); ?>" title="<?php p($comment->getDt()) ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($comment->getDt()))) ?></div>
496 496
 							</div>
497 497
 							<div class="message wordwrap comment-content"><?php p($comment->getComment()); ?></div>
498 498
 						</li>
Please login to merge, or discard this patch.
Braces   +19 added lines, -7 removed lines patch added patch discarded remove patch
@@ -118,9 +118,12 @@  discard block
 block discarded – undo
118 118
 				<span class="symbol icon-settings"></span>
119 119
 				<?php if (count($comments)) : ?>
120 120
 					<div id="comment-counter" class="badge"><?php p(count($comments)) ?></div>
121
-				<?php else: ?>
121
+				<?php else {
122
+    : ?>
122 123
 					<div id="comment-counter" class="badge no-comments"><?php p(count($comments)) ?></div>
123
-				<?php endif; ?>
124
+				<?php endif;
125
+}
126
+?>
124 127
 			</a>
125 128
 		</div>
126 129
 
@@ -333,7 +336,10 @@  discard block
 block discarded – undo
333 336
 				</div>
334 337
 			<?php if (User::isLoggedIn()) : ?>
335 338
 				<div class="notification">
336
-					<input type="checkbox" id="check_notif" class="checkbox" <?php if ($notification !== null) print_unescaped(' checked'); ?> />
339
+					<input type="checkbox" id="check_notif" class="checkbox" <?php if ($notification !== null) {
340
+    print_unescaped(' checked');
341
+}
342
+?> />
337 343
 					<label for="check_notif"><?php p($l->t('Receive notification email on activity')); ?></label>
338 344
 				</div>
339 345
 			<?php endif; ?>
@@ -429,8 +435,11 @@  discard block
 block discarded – undo
429 435
 							<div class="author"><?php p($userMgr->get($userId)->getDisplayName()) ?></div>
430 436
 						</div>
431 437
 
432
-					<?php else: ?>
433
-						<a href="<?php p($urlGenerator->linkToRouteAbsolute('core.login.showLoginForm')); ?>"><?php p($l->t('Login or ...')); ?></a>
438
+					<?php else {
439
+    : ?>
440
+						<a href="<?php p($urlGenerator->linkToRouteAbsolute('core.login.showLoginForm'));
441
+}
442
+?>"><?php p($l->t('Login or ...')); ?></a>
434 443
 						<div class="authorRow user-cell table-row">
435 444
 							<div class="avatar has-tooltip" title="?"></div>
436 445
 							<div id="id_ac_detected" class="author  column external">
@@ -451,9 +460,12 @@  discard block
 block discarded – undo
451 460
 
452 461
 					<?php if ($comments == null) : ?>
453 462
 						<li id="no-comments" class="emptycontent">
454
-					<?php else : ?>
463
+					<?php else {
464
+    : ?>
455 465
 						<li id="no-comments" class="emptycontent hidden">
456
-					<?php endif; ?>
466
+					<?php endif;
467
+}
468
+?>
457 469
 
458 470
 							<div class="icon-comment"></div>
459 471
 							<p><?php p($l->t('No comments yet. Be the first.')); ?></p>
Please login to merge, or discard this patch.
templates/main.tmpl.php 3 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -1,40 +1,40 @@  discard block
 block discarded – undo
1 1
 <?php
2
-	/**
3
-	 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
-	 *
5
-	 * @author Vinzenz Rosenkranz <[email protected]>
6
-	 *
7
-	 * @license GNU AGPL version 3 or any later version
8
-	 *
9
-	 *  This program is free software: you can redistribute it and/or modify
10
-	 *  it under the terms of the GNU Affero General Public License as
11
-	 *  published by the Free Software Foundation, either version 3 of the
12
-	 *  License, or (at your option) any later version.
13
-	 *
14
-	 *  This program is distributed in the hope that it will be useful,
15
-	 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-	 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
-	 *  GNU Affero General Public License for more details.
18
-	 *
19
-	 *  You should have received a copy of the GNU Affero General Public License
20
-	 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
-	 *
22
-	 */
2
+    /**
3
+     * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
+     *
5
+     * @author Vinzenz Rosenkranz <[email protected]>
6
+     *
7
+     * @license GNU AGPL version 3 or any later version
8
+     *
9
+     *  This program is free software: you can redistribute it and/or modify
10
+     *  it under the terms of the GNU Affero General Public License as
11
+     *  published by the Free Software Foundation, either version 3 of the
12
+     *  License, or (at your option) any later version.
13
+     *
14
+     *  This program is distributed in the hope that it will be useful,
15
+     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+     *  GNU Affero General Public License for more details.
18
+     *
19
+     *  You should have received a copy of the GNU Affero General Public License
20
+     *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+     *
22
+     */
23 23
 
24
-	use OCP\User;
24
+    use OCP\User;
25 25
 
26
-	\OCP\Util::addStyle('polls', 'main');
27
-	\OCP\Util::addStyle('polls', 'list');
28
-	\OCP\Util::addScript('polls', 'app');
29
-	\OCP\Util::addScript('polls', 'start');
26
+    \OCP\Util::addStyle('polls', 'main');
27
+    \OCP\Util::addStyle('polls', 'list');
28
+    \OCP\Util::addScript('polls', 'app');
29
+    \OCP\Util::addScript('polls', 'start');
30 30
 
31
-	$userId = $_['userId'];
32
-	/** @var \OCP\IUserManager $userMgr */
33
-	$userMgr = $_['userMgr'];
34
-	/** @var \OCP\IURLGenerator $urlGenerator */
35
-	$urlGenerator = $_['urlGenerator'];
36
-	/** @var \OCA\Polls\Db\Event[] $polls */
37
-	$polls = $_['polls'];
31
+    $userId = $_['userId'];
32
+    /** @var \OCP\IUserManager $userMgr */
33
+    $userMgr = $_['userMgr'];
34
+    /** @var \OCP\IURLGenerator $urlGenerator */
35
+    $urlGenerator = $_['urlGenerator'];
36
+    /** @var \OCA\Polls\Db\Event[] $polls */
37
+    $polls = $_['polls'];
38 38
 ?>
39 39
 
40 40
 <div id="app">
@@ -90,64 +90,64 @@  discard block
 block discarded – undo
90 90
 
91 91
 				<?php foreach ($polls as $poll) : ?>
92 92
 					<?php
93
-						if (!userHasAccess($poll, $userId)) {
94
-							continue;
95
-						}
96
-						// direct url to poll
97
-						$pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash()));
98
-						$owner = $poll->getOwner();
93
+                        if (!userHasAccess($poll, $userId)) {
94
+                            continue;
95
+                        }
96
+                        // direct url to poll
97
+                        $pollUrl = $urlGenerator->linkToRouteAbsolute('polls.page.goto_poll', array('hash' => $poll->getHash()));
98
+                        $owner = $poll->getOwner();
99 99
 
100
-						$expiry_style = '';
101
-						if ($poll->getType() === 0) {
102
-							$participated = $_['participations'];
103
-						} else {
104
-							$participated = $_['participations_text'];
105
-						}
106
-						$participated_class = 'partic_no';
107
-						$participated_title = 'You did not vote';
108
-						$participated_count = count($participated);
100
+                        $expiry_style = '';
101
+                        if ($poll->getType() === 0) {
102
+                            $participated = $_['participations'];
103
+                        } else {
104
+                            $participated = $_['participations_text'];
105
+                        }
106
+                        $participated_class = 'partic_no';
107
+                        $participated_title = 'You did not vote';
108
+                        $participated_count = count($participated);
109 109
 
110
-						$comments = $_['comments'];
111
-						$commented_class = 'commented_no';
112
-						$commented_title = 'You did not comment';
113
-						$commented_count = count($comments);
110
+                        $comments = $_['comments'];
111
+                        $commented_class = 'commented_no';
112
+                        $commented_title = 'You did not comment';
113
+                        $commented_count = count($comments);
114 114
 
115
-						if ($owner === $userId) {
116
-							$owner = $l->t('Yourself');
117
-						}
115
+                        if ($owner === $userId) {
116
+                            $owner = $l->t('Yourself');
117
+                        }
118 118
 
119
-						$timestamp_style = '';
120
-						$expiry_style = ' endless';
121
-						$expiry_date = $l->t('Never');
119
+                        $timestamp_style = '';
120
+                        $expiry_style = ' endless';
121
+                        $expiry_date = $l->t('Never');
122 122
 
123
-						if ($poll->getExpire() !== null) {
124
-							$expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs
125
-							$expiry_style = ' progress';
126
-							$timestamp_style = ' live-relative-timestamp';
127
-							if (date('U') > strtotime($poll->getExpire())) {
128
-								$expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire()));
129
-								$expiry_style = ' expired';
130
-							}
131
-						}
123
+                        if ($poll->getExpire() !== null) {
124
+                            $expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire())); // does not work, because relative_modified_date seems not to recognise future time diffs
125
+                            $expiry_style = ' progress';
126
+                            $timestamp_style = ' live-relative-timestamp';
127
+                            if (date('U') > strtotime($poll->getExpire())) {
128
+                                $expiry_date = \OCP\Template::relative_modified_date(strtotime($poll->getExpire()));
129
+                                $expiry_style = ' expired';
130
+                            }
131
+                        }
132 132
 
133
-						for ($i = 0; $i < count($participated); $i++) {
134
-							if ($poll->getId() === $participated[$i]->getPollId()) {
135
-								$participated_class = 'partic_yes';
136
-								$participated_title = 'You voted';
137
-								array_splice($participated, $i, 1);
138
-								break;
139
-							}
140
-						}
133
+                        for ($i = 0; $i < count($participated); $i++) {
134
+                            if ($poll->getId() === $participated[$i]->getPollId()) {
135
+                                $participated_class = 'partic_yes';
136
+                                $participated_title = 'You voted';
137
+                                array_splice($participated, $i, 1);
138
+                                break;
139
+                            }
140
+                        }
141 141
 
142
-						for ($i = 0; $i < count($comments); $i++) {
143
-							if ($poll->getId() === $comments[$i]->getPollId()) {
144
-								$commented_class = 'commented_yes';
145
-								$commented_title = 'You commented';
146
-								array_splice($comments, $i, 1);
147
-								break;
148
-							}
149
-						}
150
-					?>
142
+                        for ($i = 0; $i < count($comments); $i++) {
143
+                            if ($poll->getId() === $comments[$i]->getPollId()) {
144
+                                $commented_class = 'commented_yes';
145
+                                $commented_title = 'You commented';
146
+                                array_splice($comments, $i, 1);
147
+                                break;
148
+                            }
149
+                        }
150
+                    ?>
151 151
 
152 152
 					<div class="table-row table-body">
153 153
 						<div class="wrapper group-master">
@@ -223,15 +223,15 @@  discard block
 block discarded – undo
223 223
  * @return \OCP\IGroup[]
224 224
  */
225 225
 function getGroups($userId) {
226
-	if (class_exists('\OC_Group')) {
227
-		// Nextcloud <= 11, ownCloud
228
-		return \OC_Group::getUserGroups($userId);
229
-	}
230
-	// Nextcloud >= 12
231
-	$groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
232
-	return array_map(function ($group) {
233
-		return $group->getGID();
234
-	}, $groups);
226
+    if (class_exists('\OC_Group')) {
227
+        // Nextcloud <= 11, ownCloud
228
+        return \OC_Group::getUserGroups($userId);
229
+    }
230
+    // Nextcloud >= 12
231
+    $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
232
+    return array_map(function ($group) {
233
+        return $group->getGID();
234
+    }, $groups);
235 235
 }
236 236
 
237 237
 /**
@@ -240,40 +240,40 @@  discard block
 block discarded – undo
240 240
  * @return boolean
241 241
  */
242 242
 function userHasAccess(OCA\Polls\Db\Event $poll, $userId) {
243
-	if ($poll === null) {
244
-		return false;
245
-	}
246
-	$access = $poll->getAccess();
247
-	$owner = $poll->getOwner();
248
-	if (!User::isLoggedIn()) {
249
-		return false;
250
-	}
251
-	if ($access === 'public' || $access === 'hidden' || $access === 'registered') {
252
-		return true;
253
-	}
254
-	if ($owner === $userId) {
255
-		return true;
256
-	}
243
+    if ($poll === null) {
244
+        return false;
245
+    }
246
+    $access = $poll->getAccess();
247
+    $owner = $poll->getOwner();
248
+    if (!User::isLoggedIn()) {
249
+        return false;
250
+    }
251
+    if ($access === 'public' || $access === 'hidden' || $access === 'registered') {
252
+        return true;
253
+    }
254
+    if ($owner === $userId) {
255
+        return true;
256
+    }
257 257
 
258
-	$user_groups = getGroups($userId);
259
-	$arr = explode(';', $access);
258
+    $user_groups = getGroups($userId);
259
+    $arr = explode(';', $access);
260 260
 
261
-	foreach ($arr as $item) {
262
-		if (strpos($item, 'group_') === 0) {
263
-			$grp = substr($item, 6);
264
-			foreach ($user_groups as $user_group) {
265
-				if ($user_group === $grp) {
266
-					return true;
267
-				}
268
-			}
269
-		}
270
-		else if (strpos($item, 'user_') === 0) {
271
-			$usr = substr($item, 5);
272
-			if ($usr === $userId) {
273
-				return true;
274
-			}
275
-		}
276
-	}
277
-	return false;
261
+    foreach ($arr as $item) {
262
+        if (strpos($item, 'group_') === 0) {
263
+            $grp = substr($item, 6);
264
+            foreach ($user_groups as $user_group) {
265
+                if ($user_group === $grp) {
266
+                    return true;
267
+                }
268
+            }
269
+        }
270
+        else if (strpos($item, 'user_') === 0) {
271
+            $usr = substr($item, 5);
272
+            if ($usr === $userId) {
273
+                return true;
274
+            }
275
+        }
276
+    }
277
+    return false;
278 278
 }
279 279
 ?>
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 	\OCP\Util::addScript('polls', 'app');
29 29
 	\OCP\Util::addScript('polls', 'start');
30 30
 
31
-	$userId = $_['userId'];
31
+	$userId = $_[ 'userId' ];
32 32
 	/** @var \OCP\IUserManager $userMgr */
33
-	$userMgr = $_['userMgr'];
33
+	$userMgr = $_[ 'userMgr' ];
34 34
 	/** @var \OCP\IURLGenerator $urlGenerator */
35
-	$urlGenerator = $_['urlGenerator'];
35
+	$urlGenerator = $_[ 'urlGenerator' ];
36 36
 	/** @var \OCA\Polls\Db\Event[] $polls */
37
-	$polls = $_['polls'];
37
+	$polls = $_[ 'polls' ];
38 38
 ?>
39 39
 
40 40
 <div id="app">
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 						<input class="stop icon-close" style="display:none" value="" type="button">
56 56
 					</div>
57 57
 				</div>
58
-	<?php if (count($_['polls']) === 0) : ?>
58
+	<?php if (count($_[ 'polls' ]) === 0) : ?>
59 59
 		<div id="emptycontent" class="">
60 60
 			<div class="icon-polls"></div>
61 61
 			<h2><?php p($l->t('No existing polls.')); ?></h2>
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 
100 100
 						$expiry_style = '';
101 101
 						if ($poll->getType() === 0) {
102
-							$participated = $_['participations'];
102
+							$participated = $_[ 'participations' ];
103 103
 						} else {
104
-							$participated = $_['participations_text'];
104
+							$participated = $_[ 'participations_text' ];
105 105
 						}
106 106
 						$participated_class = 'partic_no';
107 107
 						$participated_title = 'You did not vote';
108 108
 						$participated_count = count($participated);
109 109
 
110
-						$comments = $_['comments'];
110
+						$comments = $_[ 'comments' ];
111 111
 						$commented_class = 'commented_no';
112 112
 						$commented_title = 'You did not comment';
113 113
 						$commented_count = count($comments);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 						}
132 132
 
133 133
 						for ($i = 0; $i < count($participated); $i++) {
134
-							if ($poll->getId() === $participated[$i]->getPollId()) {
134
+							if ($poll->getId() === $participated[ $i ]->getPollId()) {
135 135
 								$participated_class = 'partic_yes';
136 136
 								$participated_title = 'You voted';
137 137
 								array_splice($participated, $i, 1);
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 						}
141 141
 
142 142
 						for ($i = 0; $i < count($comments); $i++) {
143
-							if ($poll->getId() === $comments[$i]->getPollId()) {
143
+							if ($poll->getId() === $comments[ $i ]->getPollId()) {
144 144
 								$commented_class = 'commented_yes';
145 145
 								$commented_title = 'You commented';
146 146
 								array_splice($comments, $i, 1);
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 					<div class="table-row table-body">
153 153
 						<div class="wrapper group-master">
154 154
 							<div class="wrapper group-1">
155
-								<div class="thumbnail <?php p($expiry_style . ' ' . $commented_class. ' ' . $participated_class); ?>"></div><!-- Image to display the status or type of poll -->
155
+								<div class="thumbnail <?php p($expiry_style . ' ' . $commented_class . ' ' . $participated_class); ?>"></div><!-- Image to display the status or type of poll -->
156 156
 								<a href="<?php p($pollUrl); ?>" class="wrapper group-1-1">
157 157
 									<div class="column name">						  <?php p($poll->getTitle()); ?></div>
158 158
 									<div class="column description">				   <?php p($poll->getDescription()); ?></div>
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 												</a>
176 176
 											</li>
177 177
 											<li>
178
-												<a id="id_edit_<?php p($poll->getId()); ?>" class="menuitem action permanent" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', ['hash' => $poll->getHash()])); ?>">
178
+												<a id="id_edit_<?php p($poll->getId()); ?>" class="menuitem action permanent" href="<?php p($urlGenerator->linkToRoute('polls.page.edit_poll', [ 'hash' => $poll->getHash() ])); ?>">
179 179
 													<span class="icon-rename"></span>
180 180
 													<span>Edit Poll</span>
181 181
 												</a>
@@ -194,10 +194,10 @@  discard block
 block discarded – undo
194 194
 								</div>
195 195
 								<div class="wrapper group-2-1">
196 196
 									<div class="column access"><?php p($l->t($poll->getAccess())); ?></div>
197
-									<div class="column created has-tooltip live-relative-timestamp" data-timestamp="<?php p(strtotime($poll->getCreated())*1000); ?>" data-value="<?php p($poll->getCreated()); ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($poll->getCreated()))); ?></div>
197
+									<div class="column created has-tooltip live-relative-timestamp" data-timestamp="<?php p(strtotime($poll->getCreated()) * 1000); ?>" data-value="<?php p($poll->getCreated()); ?>"><?php p(\OCP\Template::relative_modified_date(strtotime($poll->getCreated()))); ?></div>
198 198
 								</div>
199 199
 								<div class="wrapper group-2-2">
200
-									<div class="column has-tooltip expiry<?php p($expiry_style . $timestamp_style); ?>" data-timestamp="<?php p(strtotime($poll->getExpire())*1000); ?>" data-value="<?php p($poll->getExpire()); ?>"> <?php p($expiry_date); ?></div>
200
+									<div class="column has-tooltip expiry<?php p($expiry_style . $timestamp_style); ?>" data-timestamp="<?php p(strtotime($poll->getExpire()) * 1000); ?>" data-value="<?php p($poll->getExpire()); ?>"> <?php p($expiry_date); ?></div>
201 201
 									<div class="column participants">
202 202
 										<div class="symbol alt-tooltip partic_voted icon-<?php p($participated_class); ?>" title="<?php p($participated_title); ?>"></div>
203 203
 										<div class="symbol alt-tooltip partic_commented icon-<?php p($commented_class); ?>" title="<?php p($commented_title); ?>"></div>
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	}
230 230
 	// Nextcloud >= 12
231 231
 	$groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
232
-	return array_map(function ($group) {
232
+	return array_map(function($group) {
233 233
 		return $group->getGID();
234 234
 	}, $groups);
235 235
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,14 +60,17 @@  discard block
 block discarded – undo
60 60
 			<div class="icon-polls"></div>
61 61
 			<h2><?php p($l->t('No existing polls.')); ?></h2>
62 62
 		</div>
63
-	<?php else : ?>
63
+	<?php else {
64
+    : ?>
64 65
 			<div class="table main-container has-controls">
65 66
 				<div class ="table-row table-header">
66 67
 
67 68
 					<div class="wrapper group-master">
68 69
 						<div class="wrapper group-1">
69 70
 							<div class="wrapper group-1-1">
70
-								<div class="column name">		<?php p($l->t('Title')); ?></div>
71
+								<div class="column name">		<?php p($l->t('Title'));
72
+}
73
+?></div>
71 74
 								<div class="column description"></div>
72 75
 							</div>
73 76
 							<div class="wrapper group-1-2">
@@ -266,8 +269,7 @@  discard block
 block discarded – undo
266 269
 					return true;
267 270
 				}
268 271
 			}
269
-		}
270
-		else if (strpos($item, 'user_') === 0) {
272
+		} else if (strpos($item, 'user_') === 0) {
271 273
 			$usr = substr($item, 5);
272 274
 			if ($usr === $userId) {
273 275
 				return true;
Please login to merge, or discard this patch.
tests/Unit/Factories/EventFactory.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,20 +27,20 @@
 block discarded – undo
27 27
  * General factory for the event model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Event')->setDefinitions([
30
-	'type' => 0,
31
-	'title' => Faker::sentence(10),
32
-	'description' => Faker::text(256),
33
-	'owner' => Faker::firstNameMale(),
34
-	'created' => function () {
35
-		$date = new DateTime('today');
36
-		return $date->format('Y-m-d H:i:s');
37
-	},
38
-	'access' => 'registered',
39
-	'expire' => function () {
40
-		$date = new DateTime('tomorrow');
41
-		return $date->format('Y-m-d H:i:s');
42
-	},
43
-	'hash' => Faker::regexify('[A-Za-z0-9]{16}'),
44
-	'isAnonymous' => 0,
45
-	'fullAnonymous' => 0
30
+    'type' => 0,
31
+    'title' => Faker::sentence(10),
32
+    'description' => Faker::text(256),
33
+    'owner' => Faker::firstNameMale(),
34
+    'created' => function () {
35
+        $date = new DateTime('today');
36
+        return $date->format('Y-m-d H:i:s');
37
+    },
38
+    'access' => 'registered',
39
+    'expire' => function () {
40
+        $date = new DateTime('tomorrow');
41
+        return $date->format('Y-m-d H:i:s');
42
+    },
43
+    'hash' => Faker::regexify('[A-Za-z0-9]{16}'),
44
+    'isAnonymous' => 0,
45
+    'fullAnonymous' => 0
46 46
 ]);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,12 +31,12 @@
 block discarded – undo
31 31
 	'title' => Faker::sentence(10),
32 32
 	'description' => Faker::text(256),
33 33
 	'owner' => Faker::firstNameMale(),
34
-	'created' => function () {
34
+	'created' => function() {
35 35
 		$date = new DateTime('today');
36 36
 		return $date->format('Y-m-d H:i:s');
37 37
 	},
38 38
 	'access' => 'registered',
39
-	'expire' => function () {
39
+	'expire' => function() {
40 40
 		$date = new DateTime('tomorrow');
41 41
 		return $date->format('Y-m-d H:i:s');
42 42
 	},
Please login to merge, or discard this patch.
tests/Unit/Factories/TextFactory.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,5 +27,5 @@
 block discarded – undo
27 27
  * General factory for the text model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\Text')->setDefinitions([
30
-	'text' => Faker::text(256)
30
+    'text' => Faker::text(256)
31 31
 ]);
Please login to merge, or discard this patch.
tests/Unit/Factories/ParticipationTextFactory.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
  * General factory for the participation text model.
28 28
  */
29 29
 $fm->define('OCA\Polls\Db\ParticipationText')->setDefinitions([
30
-	'text' => Faker::text(256),
31
-	'userId' => Faker::firstNameMale(),
32
-	'type' => 0
30
+    'text' => Faker::text(256),
31
+    'userId' => Faker::firstNameMale(),
32
+    'type' => 0
33 33
 ]);
Please login to merge, or discard this patch.
lib/AppInfo/Application.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -36,118 +36,118 @@
 block discarded – undo
36 36
 
37 37
 class Application extends App {
38 38
 
39
-	/**
40
-	 * Application constructor.
41
-	 * @param array $urlParams
42
-	 */
43
-	public function __construct(array $urlParams = array()) {
44
-		parent::__construct('polls', $urlParams);
45
-
46
-		$container = $this->getContainer();
47
-		$server = $container->getServer();
48
-
49
-		/**
50
-		 * Controllers
51
-		 */
52
-		$container->registerService('PageController', function (IContainer $c) {
53
-			return new PageController(
54
-				$c->query('AppName'),
55
-				$c->query('Request'),
56
-				$c->query('UserManager'),
57
-				$c->query('GroupManager'),
58
-				$c->query('AvatarManager'),
59
-				$c->query('Logger'),
60
-				$c->query('L10N'),
61
-				$c->query('ServerContainer')->getURLGenerator(),
62
-				$c->query('UserId'),
63
-				$c->query('CommentMapper'),
64
-				$c->query('DateMapper'),
65
-				$c->query('EventMapper'),
66
-				$c->query('NotificationMapper'),
67
-				$c->query('ParticipationMapper'),
68
-				$c->query('ParticipationTextMapper'),
69
-				$c->query('TextMapper')
70
-			);
71
-		});
72
-
73
-		$container->registerService('UserManager', function (IContainer $c) {
74
-			return $c->query('ServerContainer')->getUserManager();
75
-		});
76
-
77
-		$container->registerService('GroupManager', function (IContainer $c) {
78
-			return $c->query('ServerContainer')->getGroupManager();
79
-		});
80
-
81
-		$container->registerService('AvatarManager', function (IContainer $c) {
82
-			return $c->query('ServerContainer')->getAvatarManager();
83
-		});
84
-
85
-		$container->registerService('Logger', function (IContainer $c) {
86
-			return $c->query('ServerContainer')->getLogger();
87
-		});
88
-
89
-		$container->registerService('L10N', function (IContainer $c) {
90
-			return $c->query('ServerContainer')->getL10N($c->query('AppName'));
91
-		});
92
-
93
-		$container->registerService('CommentMapper', function (IContainer $c) use ($server) {
94
-			return new CommentMapper(
95
-				$server->getDatabaseConnection()
96
-			);
97
-		});
98
-
99
-		$container->registerService('DateMapper', function (IContainer $c) use ($server) {
100
-			return new DateMapper(
101
-				$server->getDatabaseConnection()
102
-			);
103
-		});
104
-
105
-		$container->registerService('EventMapper', function (IContainer $c) use ($server) {
106
-			return new EventMapper(
107
-				$server->getDatabaseConnection()
108
-			);
109
-		});
110
-
111
-		$container->registerService('NotificationMapper', function (IContainer $c) use ($server) {
112
-			return new NotificationMapper(
113
-				$server->getDatabaseConnection()
114
-			);
115
-		});
116
-
117
-		$container->registerService('ParticipationMapper', function (IContainer $c) use ($server) {
118
-			return new ParticipationMapper(
119
-				$server->getDatabaseConnection()
120
-			);
121
-		});
122
-
123
-		$container->registerService('ParticipationTextMapper', function (IContainer $c) use ($server) {
124
-			return new ParticipationTextMapper(
125
-				$server->getDatabaseConnection()
126
-			);
127
-		});
128
-
129
-		$container->registerService('TextMapper', function (IContainer $c) use ($server) {
130
-			return new TextMapper(
131
-				$server->getDatabaseConnection()
132
-			);
133
-		});
134
-	}
135
-
136
-	/**
137
-	 * Register navigation entry for main navigation.
138
-	 */
139
-	public function registerNavigationEntry() {
140
-		$container = $this->getContainer();
141
-		$container->query('OCP\INavigationManager')->add(function () use ($container) {
142
-			$urlGenerator = $container->query('OCP\IURLGenerator');
143
-			$l10n = $container->query('OCP\IL10N');
144
-			return [
145
-				'id' => 'polls',
146
-				'order' => 77,
147
-				'href' => $urlGenerator->linkToRoute('polls.page.index'),
148
-				'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
149
-				'name' => $l10n->t('Polls')
150
-			];
151
-		});
152
-	}
39
+    /**
40
+     * Application constructor.
41
+     * @param array $urlParams
42
+     */
43
+    public function __construct(array $urlParams = array()) {
44
+        parent::__construct('polls', $urlParams);
45
+
46
+        $container = $this->getContainer();
47
+        $server = $container->getServer();
48
+
49
+        /**
50
+         * Controllers
51
+         */
52
+        $container->registerService('PageController', function (IContainer $c) {
53
+            return new PageController(
54
+                $c->query('AppName'),
55
+                $c->query('Request'),
56
+                $c->query('UserManager'),
57
+                $c->query('GroupManager'),
58
+                $c->query('AvatarManager'),
59
+                $c->query('Logger'),
60
+                $c->query('L10N'),
61
+                $c->query('ServerContainer')->getURLGenerator(),
62
+                $c->query('UserId'),
63
+                $c->query('CommentMapper'),
64
+                $c->query('DateMapper'),
65
+                $c->query('EventMapper'),
66
+                $c->query('NotificationMapper'),
67
+                $c->query('ParticipationMapper'),
68
+                $c->query('ParticipationTextMapper'),
69
+                $c->query('TextMapper')
70
+            );
71
+        });
72
+
73
+        $container->registerService('UserManager', function (IContainer $c) {
74
+            return $c->query('ServerContainer')->getUserManager();
75
+        });
76
+
77
+        $container->registerService('GroupManager', function (IContainer $c) {
78
+            return $c->query('ServerContainer')->getGroupManager();
79
+        });
80
+
81
+        $container->registerService('AvatarManager', function (IContainer $c) {
82
+            return $c->query('ServerContainer')->getAvatarManager();
83
+        });
84
+
85
+        $container->registerService('Logger', function (IContainer $c) {
86
+            return $c->query('ServerContainer')->getLogger();
87
+        });
88
+
89
+        $container->registerService('L10N', function (IContainer $c) {
90
+            return $c->query('ServerContainer')->getL10N($c->query('AppName'));
91
+        });
92
+
93
+        $container->registerService('CommentMapper', function (IContainer $c) use ($server) {
94
+            return new CommentMapper(
95
+                $server->getDatabaseConnection()
96
+            );
97
+        });
98
+
99
+        $container->registerService('DateMapper', function (IContainer $c) use ($server) {
100
+            return new DateMapper(
101
+                $server->getDatabaseConnection()
102
+            );
103
+        });
104
+
105
+        $container->registerService('EventMapper', function (IContainer $c) use ($server) {
106
+            return new EventMapper(
107
+                $server->getDatabaseConnection()
108
+            );
109
+        });
110
+
111
+        $container->registerService('NotificationMapper', function (IContainer $c) use ($server) {
112
+            return new NotificationMapper(
113
+                $server->getDatabaseConnection()
114
+            );
115
+        });
116
+
117
+        $container->registerService('ParticipationMapper', function (IContainer $c) use ($server) {
118
+            return new ParticipationMapper(
119
+                $server->getDatabaseConnection()
120
+            );
121
+        });
122
+
123
+        $container->registerService('ParticipationTextMapper', function (IContainer $c) use ($server) {
124
+            return new ParticipationTextMapper(
125
+                $server->getDatabaseConnection()
126
+            );
127
+        });
128
+
129
+        $container->registerService('TextMapper', function (IContainer $c) use ($server) {
130
+            return new TextMapper(
131
+                $server->getDatabaseConnection()
132
+            );
133
+        });
134
+    }
135
+
136
+    /**
137
+     * Register navigation entry for main navigation.
138
+     */
139
+    public function registerNavigationEntry() {
140
+        $container = $this->getContainer();
141
+        $container->query('OCP\INavigationManager')->add(function () use ($container) {
142
+            $urlGenerator = $container->query('OCP\IURLGenerator');
143
+            $l10n = $container->query('OCP\IL10N');
144
+            return [
145
+                'id' => 'polls',
146
+                'order' => 77,
147
+                'href' => $urlGenerator->linkToRoute('polls.page.index'),
148
+                'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
149
+                'name' => $l10n->t('Polls')
150
+            ];
151
+        });
152
+    }
153 153
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		/**
50 50
 		 * Controllers
51 51
 		 */
52
-		$container->registerService('PageController', function (IContainer $c) {
52
+		$container->registerService('PageController', function(IContainer $c) {
53 53
 			return new PageController(
54 54
 				$c->query('AppName'),
55 55
 				$c->query('Request'),
@@ -70,63 +70,63 @@  discard block
 block discarded – undo
70 70
 			);
71 71
 		});
72 72
 
73
-		$container->registerService('UserManager', function (IContainer $c) {
73
+		$container->registerService('UserManager', function(IContainer $c) {
74 74
 			return $c->query('ServerContainer')->getUserManager();
75 75
 		});
76 76
 
77
-		$container->registerService('GroupManager', function (IContainer $c) {
77
+		$container->registerService('GroupManager', function(IContainer $c) {
78 78
 			return $c->query('ServerContainer')->getGroupManager();
79 79
 		});
80 80
 
81
-		$container->registerService('AvatarManager', function (IContainer $c) {
81
+		$container->registerService('AvatarManager', function(IContainer $c) {
82 82
 			return $c->query('ServerContainer')->getAvatarManager();
83 83
 		});
84 84
 
85
-		$container->registerService('Logger', function (IContainer $c) {
85
+		$container->registerService('Logger', function(IContainer $c) {
86 86
 			return $c->query('ServerContainer')->getLogger();
87 87
 		});
88 88
 
89
-		$container->registerService('L10N', function (IContainer $c) {
89
+		$container->registerService('L10N', function(IContainer $c) {
90 90
 			return $c->query('ServerContainer')->getL10N($c->query('AppName'));
91 91
 		});
92 92
 
93
-		$container->registerService('CommentMapper', function (IContainer $c) use ($server) {
93
+		$container->registerService('CommentMapper', function(IContainer $c) use ($server) {
94 94
 			return new CommentMapper(
95 95
 				$server->getDatabaseConnection()
96 96
 			);
97 97
 		});
98 98
 
99
-		$container->registerService('DateMapper', function (IContainer $c) use ($server) {
99
+		$container->registerService('DateMapper', function(IContainer $c) use ($server) {
100 100
 			return new DateMapper(
101 101
 				$server->getDatabaseConnection()
102 102
 			);
103 103
 		});
104 104
 
105
-		$container->registerService('EventMapper', function (IContainer $c) use ($server) {
105
+		$container->registerService('EventMapper', function(IContainer $c) use ($server) {
106 106
 			return new EventMapper(
107 107
 				$server->getDatabaseConnection()
108 108
 			);
109 109
 		});
110 110
 
111
-		$container->registerService('NotificationMapper', function (IContainer $c) use ($server) {
111
+		$container->registerService('NotificationMapper', function(IContainer $c) use ($server) {
112 112
 			return new NotificationMapper(
113 113
 				$server->getDatabaseConnection()
114 114
 			);
115 115
 		});
116 116
 
117
-		$container->registerService('ParticipationMapper', function (IContainer $c) use ($server) {
117
+		$container->registerService('ParticipationMapper', function(IContainer $c) use ($server) {
118 118
 			return new ParticipationMapper(
119 119
 				$server->getDatabaseConnection()
120 120
 			);
121 121
 		});
122 122
 
123
-		$container->registerService('ParticipationTextMapper', function (IContainer $c) use ($server) {
123
+		$container->registerService('ParticipationTextMapper', function(IContainer $c) use ($server) {
124 124
 			return new ParticipationTextMapper(
125 125
 				$server->getDatabaseConnection()
126 126
 			);
127 127
 		});
128 128
 
129
-		$container->registerService('TextMapper', function (IContainer $c) use ($server) {
129
+		$container->registerService('TextMapper', function(IContainer $c) use ($server) {
130 130
 			return new TextMapper(
131 131
 				$server->getDatabaseConnection()
132 132
 			);
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function registerNavigationEntry() {
140 140
 		$container = $this->getContainer();
141
-		$container->query('OCP\INavigationManager')->add(function () use ($container) {
141
+		$container->query('OCP\INavigationManager')->add(function() use ($container) {
142 142
 			$urlGenerator = $container->query('OCP\IURLGenerator');
143 143
 			$l10n = $container->query('OCP\IL10N');
144 144
 			return [
Please login to merge, or discard this patch.