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