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