Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2017-10-21 15:41:34 +0300
committerGitHub <noreply@github.com>2017-10-21 15:41:34 +0300
commit540e09bcade129f22e2682041dcf4e704385ee79 (patch)
tree0dc96520deae6a36083dc33f4cceaec40d61a7dc /lib
parent4788739b6470cebd2ca32b6f74600952738dcfca (diff)
Code cleaning (#185)
* Update no.acc.tmpl.php * update for scutinizer * Update PageController.php * Update PageController.php * coding style * dito * more fixes * update * Added scrutinizer config * Coding style Adopting style guide from docs.nextcloud.com * More changes * disabled external code coverage * changes * Changes * changes * changes * More changes * Update to version 2.5.11 * Update .scrutinizer.yml * Update .scrutinizer.yml * created vendor [ci skip] * config [skip scrutinizer] [skip ci] * fix [skip ci] * Minor * continuing [skip ci] * just a test * removed unused function declarations Commenting out some functions, which seem not to be used. * css tests? * again * formatting * removed comment and converted spaces in tabs
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php253
-rw-r--r--lib/Controller/PageController.php1394
-rw-r--r--lib/Db/Comment.php8
-rw-r--r--lib/Db/CommentMapper.php68
-rw-r--r--lib/Db/Date.php4
-rw-r--r--lib/Db/DateMapper.php48
-rw-r--r--lib/Db/Event.php20
-rw-r--r--lib/Db/EventMapper.php142
-rw-r--r--lib/Db/Notification.php4
-rw-r--r--lib/Db/NotificationMapper.php106
-rw-r--r--lib/Db/Participation.php8
-rw-r--r--lib/Db/ParticipationMapper.php84
-rw-r--r--lib/Db/ParticipationText.php8
-rw-r--r--lib/Db/ParticipationTextMapper.php64
-rw-r--r--lib/Db/Text.php4
-rw-r--r--lib/Db/TextMapper.php48
16 files changed, 1132 insertions, 1131 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 1a561183..810362d7 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -23,6 +23,7 @@
namespace OCA\Polls\AppInfo;
+
use OC\AppFramework\Utility\SimpleContainer;
use OCP\AppFramework\App;
use OCA\Polls\Db\CommentMapper;
@@ -36,130 +37,130 @@ use OCA\Polls\Controller\PageController;
class Application extends App {
- /**
- * Application constructor.
- * @param array $urlParams
- */
- public function __construct(array $urlParams = array()) {
- parent::__construct('polls', $urlParams);
-
- $container = $this->getContainer();
- $server = $container->getServer();
-
- /**
- * Controllers
- */
- $container->registerService('PageController', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new PageController(
- $c->query('AppName'),
- $c->query('Request'),
- $c->query('UserManager'),
- $c->query('GroupManager'),
- $c->query('AvatarManager'),
- $c->query('Logger'),
- $c->query('L10N'),
- $c->query('ServerContainer')->getURLGenerator(),
- $c->query('UserId'),
- $c->query('CommentMapper'),
- $c->query('DateMapper'),
- $c->query('EventMapper'),
- $c->query('NotificationMapper'),
- $c->query('ParticipationMapper'),
- $c->query('ParticipationTextMapper'),
- $c->query('TextMapper')
- );
- });
-
- $container->registerService('UserManager', function ($c) {
- /** @var SimpleContainer $c */
- return $c->query('ServerContainer')->getUserManager();
- });
-
- $container->registerService('GroupManager', function ($c) {
- /** @var SimpleContainer $c */
- return $c->query('ServerContainer')->getGroupManager();
- });
-
- $container->registerService('AvatarManager', function ($c) {
- /** @var SimpleContainer $c */
- return $c->query('ServerContainer')->getAvatarManager();
- });
-
- $container->registerService('Logger', function ($c) {
- /** @var SimpleContainer $c */
- return $c->query('ServerContainer')->getLogger();
- });
-
- $container->registerService('L10N', function ($c) {
- return $c->query('ServerContainer')->getL10N($c->query('AppName'));
- });
-
- $container->registerService('CommentMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new CommentMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('DateMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new DateMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('EventMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new EventMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('NotificationMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new NotificationMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('ParticipationMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new ParticipationMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('ParticipationTextMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new ParticipationTextMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $container->registerService('TextMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new TextMapper(
- $server->getDatabaseConnection()
- );
- });
- }
-
- /**
- * Register navigation entry for main navigation.
- */
- public function registerNavigationEntry() {
- $container = $this->getContainer();
- $container->query('OCP\INavigationManager')->add(function () use ($container) {
- $urlGenerator = $container->query('OCP\IURLGenerator');
- $l10n = $container->query('OCP\IL10N');
- return [
- 'id' => 'polls',
- 'order' => 77,
- 'href' => $urlGenerator->linkToRoute('polls.page.index'),
- 'icon' => $urlGenerator->imagePath('polls', 'app-logo-polls.svg'),
- 'name' => $l10n->t('Polls')
- ];
- });
- }
+ /**
+ * Application constructor.
+ * @param array $urlParams
+ */
+ public function __construct(array $urlParams = array()) {
+ parent::__construct('polls', $urlParams);
+
+ $container = $this->getContainer();
+ $server = $container->getServer();
+
+ /**
+ * Controllers
+ */
+ $container->registerService('PageController', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new PageController(
+ $c->query('AppName'),
+ $c->query('Request'),
+ $c->query('UserManager'),
+ $c->query('GroupManager'),
+ $c->query('AvatarManager'),
+ $c->query('Logger'),
+ $c->query('L10N'),
+ $c->query('ServerContainer')->getURLGenerator(),
+ $c->query('UserId'),
+ $c->query('CommentMapper'),
+ $c->query('DateMapper'),
+ $c->query('EventMapper'),
+ $c->query('NotificationMapper'),
+ $c->query('ParticipationMapper'),
+ $c->query('ParticipationTextMapper'),
+ $c->query('TextMapper')
+ );
+ });
+
+ $container->registerService('UserManager', function ($c) {
+ /** @var SimpleContainer $c */
+ return $c->query('ServerContainer')->getUserManager();
+ });
+
+ $container->registerService('GroupManager', function ($c) {
+ /** @var SimpleContainer $c */
+ return $c->query('ServerContainer')->getGroupManager();
+ });
+
+ $container->registerService('AvatarManager', function ($c) {
+ /** @var SimpleContainer $c */
+ return $c->query('ServerContainer')->getAvatarManager();
+ });
+
+ $container->registerService('Logger', function ($c) {
+ /** @var SimpleContainer $c */
+ return $c->query('ServerContainer')->getLogger();
+ });
+
+ $container->registerService('L10N', function ($c) {
+ return $c->query('ServerContainer')->getL10N($c->query('AppName'));
+ });
+
+ $container->registerService('CommentMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new CommentMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('DateMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new DateMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('EventMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new EventMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('NotificationMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new NotificationMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('ParticipationMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new ParticipationMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('ParticipationTextMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new ParticipationTextMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $container->registerService('TextMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new TextMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+ }
+
+ /**
+ * Register navigation entry for main navigation.
+ */
+ public function registerNavigationEntry() {
+ $container = $this->getContainer();
+ $container->query('OCP\INavigationManager')->add(function () use ($container) {
+ $urlGenerator = $container->query('OCP\IURLGenerator');
+ $l10n = $container->query('OCP\IL10N');
+ return [
+ 'id' => 'polls',
+ 'order' => 77,
+ 'href' => $urlGenerator->linkToRoute('polls.page.index'),
+ 'icon' => $urlGenerator->imagePath('polls', 'app-logo-polls.svg'),
+ 'name' => $l10n->t('Polls')
+ ];
+ });
+ }
}
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 9e3febbb..cecc30be 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -55,703 +55,703 @@ use OCP\Util;
class PageController extends Controller {
- private $userId;
- private $commentMapper;
- private $dateMapper;
- private $eventMapper;
- private $notificationMapper;
- private $participationMapper;
- private $participationTextMapper;
- private $textMapper;
- private $urlGenerator;
- private $manager;
- private $avatarManager;
- private $logger;
- private $trans;
- private $userMgr;
- private $groupManager;
-
- /**
- * PageController constructor.
- * @param $appName
- * @param IRequest $request
- * @param IUserManager $manager
- * @param IGroupManager $groupManager
- * @param IAvatarManager $avatarManager
- * @param ILogger $logger
- * @param IL10N $trans
- * @param IURLGenerator $urlGenerator
- * @param $userId
- * @param CommentMapper $commentMapper
- * @param DateMapper $dateMapper
- * @param EventMapper $eventMapper
- * @param NotificationMapper $notificationMapper
- * @param ParticipationMapper $ParticipationMapper
- * @param ParticipationTextMapper $ParticipationTextMapper
- * @param TextMapper $textMapper
- */
- public function __construct(
- $appName,
- IRequest $request,
- IUserManager $manager,
- IGroupManager $groupManager,
- IAvatarManager $avatarManager,
- ILogger $logger,
- IL10N $trans,
- IURLGenerator $urlGenerator,
- $userId,
- CommentMapper $commentMapper,
- DateMapper $dateMapper,
- EventMapper $eventMapper,
- NotificationMapper $notificationMapper,
- ParticipationMapper $ParticipationMapper,
- ParticipationTextMapper $ParticipationTextMapper,
- TextMapper $textMapper
- ) {
- parent::__construct($appName, $request);
- $this->manager = $manager;
- $this->groupManager = $groupManager;
- $this->avatarManager = $avatarManager;
- $this->logger = $logger;
- $this->trans = $trans;
- $this->urlGenerator = $urlGenerator;
- $this->userId = $userId;
- $this->commentMapper = $commentMapper;
- $this->dateMapper = $dateMapper;
- $this->eventMapper = $eventMapper;
- $this->notificationMapper = $notificationMapper;
- $this->participationMapper = $ParticipationMapper;
- $this->participationTextMapper = $ParticipationTextMapper;
- $this->textMapper = $textMapper;
- $this->userMgr = \OC::$server->getUserManager();
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- */
- public function index() {
- $polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
- $comments = $this->commentMapper->findDistinctByUser($this->userId);
- $partic = $this->participationMapper->findDistinctByUser($this->userId);
+ private $userId;
+ private $commentMapper;
+ private $dateMapper;
+ private $eventMapper;
+ private $notificationMapper;
+ private $participationMapper;
+ private $participationTextMapper;
+ private $textMapper;
+ private $urlGenerator;
+ private $manager;
+ private $avatarManager;
+ private $logger;
+ private $trans;
+ private $userMgr;
+ private $groupManager;
+
+ /**
+ * PageController constructor.
+ * @param $appName
+ * @param IRequest $request
+ * @param IUserManager $manager
+ * @param IGroupManager $groupManager
+ * @param IAvatarManager $avatarManager
+ * @param ILogger $logger
+ * @param IL10N $trans
+ * @param IURLGenerator $urlGenerator
+ * @param $userId
+ * @param CommentMapper $commentMapper
+ * @param DateMapper $dateMapper
+ * @param EventMapper $eventMapper
+ * @param NotificationMapper $notificationMapper
+ * @param ParticipationMapper $ParticipationMapper
+ * @param ParticipationTextMapper $ParticipationTextMapper
+ * @param TextMapper $textMapper
+ */
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IUserManager $manager,
+ IGroupManager $groupManager,
+ IAvatarManager $avatarManager,
+ ILogger $logger,
+ IL10N $trans,
+ IURLGenerator $urlGenerator,
+ $userId,
+ CommentMapper $commentMapper,
+ DateMapper $dateMapper,
+ EventMapper $eventMapper,
+ NotificationMapper $notificationMapper,
+ ParticipationMapper $ParticipationMapper,
+ ParticipationTextMapper $ParticipationTextMapper,
+ TextMapper $textMapper
+ ) {
+ parent::__construct($appName, $request);
+ $this->manager = $manager;
+ $this->groupManager = $groupManager;
+ $this->avatarManager = $avatarManager;
+ $this->logger = $logger;
+ $this->trans = $trans;
+ $this->urlGenerator = $urlGenerator;
+ $this->userId = $userId;
+ $this->commentMapper = $commentMapper;
+ $this->dateMapper = $dateMapper;
+ $this->eventMapper = $eventMapper;
+ $this->notificationMapper = $notificationMapper;
+ $this->participationMapper = $ParticipationMapper;
+ $this->participationTextMapper = $ParticipationTextMapper;
+ $this->textMapper = $textMapper;
+ $this->userMgr = \OC::$server->getUserManager();
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function index() {
+ $polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
+ $comments = $this->commentMapper->findDistinctByUser($this->userId);
+ $partic = $this->participationMapper->findDistinctByUser($this->userId);
$particText = $this->participationTextMapper->findDistinctByUser($this->userId);
- $response = new TemplateResponse('polls', 'main.tmpl', [
- 'polls' => $polls,
- 'comments' => $comments,
- 'participations' => $partic,
+ $response = new TemplateResponse('polls', 'main.tmpl', [
+ 'polls' => $polls,
+ 'comments' => $comments,
+ 'participations' => $partic,
'participations_text' => $particText,
- 'userId' => $this->userId,
- 'userMgr' => $this->manager,
- 'urlGenerator' => $this->urlGenerator
- ]);
- if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
- $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
- $response->setContentSecurityPolicy($csp);
- }
- return $response;
- }
-
- /**
- * @param string $pollId
- * @param string $from
- */
- private function sendNotifications($pollId, $from) {
- $poll = $this->eventMapper->find($pollId);
- $notifications = $this->notificationMapper->findAllByPoll($pollId);
- foreach ($notifications as $notification) {
- if ($from === $notification->getUserId()) {
- continue;
- }
- $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
- if (strlen($email) === 0 || !isset($email)) {
- continue;
- }
- $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll',
- array('hash' => $poll->getHash())));
-
- $recUser = $this->userMgr->get($notification->getUserId());
- $sendUser = $this->userMgr->get($from);
- $rec = "";
- if ($recUser !== null) {
- $rec = $recUser->getDisplayName();
- }
- if ($sendUser !== null) {
- $sender = $sendUser->getDisplayName();
- } else {
- $sender = $from;
- }
- $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>',
- array(
- $rec,
- $sender,
- $poll->getTitle(),
- $url
- ));
-
- $msg .= "<br/><br/>";
-
- $toName = $this->userMgr->get($notification->getUserId())->getDisplayName();
- $subject = $this->trans->t('Polls App - New Comment');
- $fromAddress = Util::getDefaultEmailAddress('no-reply');
- $fromName = $this->trans->t("Polls App") . ' (' . $from . ')';
-
- try {
- $mailer = \OC::$server->getMailer();
- $message = $mailer->createMessage();
- $message->setSubject($subject);
- $message->setFrom(array($fromAddress => $fromName));
- $message->setTo(array($email => $toName));
- $message->setHtmlBody($msg);
- $mailer->send($message);
- } catch (\Exception $e) {
- $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')';
- Util::writeLog("polls", $message, Util::ERROR);
- }
- }
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @PublicPage
- * @param string $hash
- * @return TemplateResponse
- */
- public function gotoPoll($hash) {
- $poll = $this->eventMapper->findByHash($hash);
- if ($poll->getType() == '0') {
- $dates = $this->dateMapper->findByPoll($poll->getId());
- $votes = $this->participationMapper->findByPoll($poll->getId());
- } else {
- $dates = $this->textMapper->findByPoll($poll->getId());
- $votes = $this->participationTextMapper->findByPoll($poll->getId());
- }
- $comments = $this->commentMapper->findByPoll($poll->getId());
- try {
- $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
- } catch (DoesNotExistException $e) {
- $notification = null;
- }
- if ($this->hasUserAccess($poll)) {
- return new TemplateResponse('polls', 'goto.tmpl', [
- 'poll' => $poll,
- 'dates' => $dates,
- 'comments' => $comments,
- 'votes' => $votes,
- 'notification' => $notification,
- 'userId' => $this->userId,
- 'userMgr' => $this->manager,
- 'urlGenerator' => $this->urlGenerator,
- 'avatarManager' => $this->avatarManager
- ]);
- } else {
- User::checkLoggedIn();
- return new TemplateResponse('polls', 'no.acc.tmpl', []);
- }
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param string $pollId
- * @return RedirectResponse
- */
- public function deletePoll($pollId) {
- $poll = new Event();
- $poll->setId($pollId);
- $this->eventMapper->delete($poll);
- $this->textMapper->deleteByPoll($pollId);
- $this->dateMapper->deleteByPoll($pollId);
- $this->participationMapper->deleteByPoll($pollId);
- $this->participationTextMapper->deleteByPoll($pollId);
- $this->commentMapper->deleteByPoll($pollId);
- $url = $this->urlGenerator->linkToRoute('polls.page.index');
- return new RedirectResponse($url);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param string $hash
- * @return TemplateResponse
- */
- public function editPoll($hash) {
- $poll = $this->eventMapper->findByHash($hash);
- if ($this->userId !== $poll->getOwner()) {
- return new TemplateResponse('polls', 'no.create.tmpl');
- }
- if ($poll->getType() == '0') {
- $dates = $this->dateMapper->findByPoll($poll->getId());
- } else {
- $dates = $this->textMapper->findByPoll($poll->getId());
- }
- return new TemplateResponse('polls', 'create.tmpl', [
- 'poll' => $poll,
- 'dates' => $dates,
- 'userId' => $this->userId,
- 'userMgr' => $this->manager,
- 'urlGenerator' => $this->urlGenerator
- ]);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $pollId
- * @param $pollType
- * @param $pollTitle
- * @param $pollDesc
- * @param $userId
- * @param $chosenDates
- * @param $expireTs
- * @param $accessType
- * @param $accessValues
- * @param $isAnonymous
- * @param $hideNames
- * @return RedirectResponse
- */
- public function updatePoll(
- $pollId,
- $pollType,
- $pollTitle,
- $pollDesc,
- $userId,
- $chosenDates,
- $expireTs,
- $accessType,
- $accessValues,
- $isAnonymous,
- $hideNames
- ) {
- $event = $this->eventMapper->find($pollId);
- $event->setTitle(htmlspecialchars($pollTitle));
- $event->setDescription(htmlspecialchars($pollDesc));
- $event->setIsAnonymous($isAnonymous ? '1' : '0');
- $event->setFullAnonymous($isAnonymous && $hideNames ? '1' : '0');
-
- if ($accessType === 'select') {
- if (isset($accessValues)) {
- $accessValues = json_decode($accessValues);
- if ($accessValues !== null) {
- $groups = array();
- $users = array();
- if ($accessValues->groups !== null) {
- $groups = $accessValues->groups;
- }
- if ($accessValues->users !== null) {
- $users = $accessValues->users;
- }
- $accessType = '';
- foreach ($groups as $gid) {
- $accessType .= $gid . ';';
- }
- foreach ($users as $uid) {
- $accessType .= $uid . ';';
- }
- }
- }
- }
- $event->setAccess($accessType);
-
- $chosenDates = json_decode($chosenDates);
-
- $expire = null;
- if ($expireTs !== null && $expireTs !== '') {
- $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
- }
- $event->setExpire($expire);
-
- $this->dateMapper->deleteByPoll($pollId);
- $this->textMapper->deleteByPoll($pollId);
- if ($pollType === 'event') {
- $event->setType(0);
- $this->eventMapper->update($event);
- sort($chosenDates);
- foreach ($chosenDates as $el) {
- $date = new Date();
- $date->setPollId($pollId);
- $date->setDt(date('Y-m-d H:i:s', $el));
- $this->dateMapper->insert($date);
- }
- } else {
- $event->setType(1);
- $this->eventMapper->update($event);
- foreach ($chosenDates as $el) {
- $text = new Text();
- $text->setText($el);
- $text->setPollId($pollId);
- $this->textMapper->insert($text);
- }
- }
- $url = $this->urlGenerator->linkToRoute('polls.page.index');
- return new RedirectResponse($url);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- */
- public function createPoll() {
- return new TemplateResponse('polls', 'create.tmpl',
- ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $pollType
- * @param $pollTitle
- * @param $pollDesc
- * @param $userId
- * @param $chosenDates
- * @param $expireTs
- * @param $accessType
- * @param $accessValues
- * @param $isAnonymous
- * @param $hideNames
- * @return RedirectResponse
- */
- public function insertPoll(
- $pollType,
- $pollTitle,
- $pollDesc,
- $userId,
- $chosenDates,
- $expireTs,
- $accessType,
- $accessValues,
- $isAnonymous,
- $hideNames
- ) {
- $event = new Event();
- $event->setTitle(htmlspecialchars($pollTitle));
- $event->setDescription(htmlspecialchars($pollDesc));
- $event->setOwner($userId);
- $event->setCreated(date('Y-m-d H:i:s'));
- $event->setHash(\OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(16,
- ISecureRandom::CHAR_DIGITS .
- ISecureRandom::CHAR_LOWER .
- ISecureRandom::CHAR_UPPER));
- $event->setIsAnonymous($isAnonymous ? '1' : '0');
- $event->setFullAnonymous($isAnonymous && $hideNames ? '1' : '0');
-
- if ($accessType === 'select') {
- if (isset($accessValues)) {
- $accessValues = json_decode($accessValues);
- if ($accessValues !== null) {
- $groups = array();
- $users = array();
- if ($accessValues->groups !== null) {
- $groups = $accessValues->groups;
- }
- if ($accessValues->users !== null) {
- $users = $accessValues->users;
- }
- $accessType = '';
- foreach ($groups as $gid) {
- $accessType .= $gid . ';';
- }
- foreach ($users as $uid) {
- $accessType .= $uid . ';';
- }
- }
- }
- }
- $event->setAccess($accessType);
-
- $chosenDates = json_decode($chosenDates);
-
- $expire = null;
- if ($expireTs !== null && $expireTs !== '') {
- $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
- }
- $event->setExpire($expire);
-
- if ($pollType === 'event') {
- $event->setType(0);
- $ins = $this->eventMapper->insert($event);
- $poll_id = $ins->getId();
- sort($chosenDates);
- foreach ($chosenDates as $el) {
- $date = new Date();
- $date->setPollId($poll_id);
- $date->setDt(date('Y-m-d H:i:s', $el));
- $this->dateMapper->insert($date);
- }
- } else {
- $event->setType(1);
- $ins = $this->eventMapper->insert($event);
- $poll_id = $ins->getId();
- $cnt = 1;
- foreach ($chosenDates as $el) {
- $text = new Text();
- $text->setText($el . '_' . $cnt);
- $text->setPollId($poll_id);
- $this->textMapper->insert($text);
- $cnt++;
- }
- }
- $url = $this->urlGenerator->linkToRoute('polls.page.index');
- return new RedirectResponse($url);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @PublicPage
- * @param $pollId
- * @param $userId
- * @param $types
- * @param $dates
- * @param $receiveNotifications
- * @param $changed
- * @return RedirectResponse
- */
- public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
- if ($this->userId !== null) {
- if ($receiveNotifications === 'true') {
- try {
- //check if user already set notification for this poll
- $this->notificationMapper->findByUserAndPoll($pollId, $userId);
- } catch (DoesNotExistException $e) {
- //insert if not exist
- $not = new Notification();
- $not->setUserId($userId);
- $not->setPollId($pollId);
- $this->notificationMapper->insert($not);
- }
- } else {
- try {
- //delete if entry is in db
- $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
- $this->notificationMapper->delete($not);
- } catch (DoesNotExistException $e) {
- //doesn't exist in db, nothing to do
- }
- }
- }
- $poll = $this->eventMapper->find($pollId);
- if ($changed === 'true') {
- $dates = json_decode($dates);
- $types = json_decode($types);
- if ($poll->getType() == '0') {
- $this->participationMapper->deleteByPollAndUser($pollId, $userId);
- } else {
- $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
- }
- for ($i = 0; $i < count($dates); $i++) {
- if ($poll->getType() == '0') {
- $part = new Participation();
- $part->setPollId($pollId);
- $part->setUserId($userId);
- $part->setDt(date('Y-m-d H:i:s', $dates[$i]));
- $part->setType($types[$i]);
- $this->participationMapper->insert($part);
- } else {
- $part = new ParticipationText();
- $part->setPollId($pollId);
- $part->setUserId($userId);
- $part->setText($dates[$i]);
- $part->setType($types[$i]);
- $this->participationTextMapper->insert($part);
- }
-
- }
- $this->sendNotifications($pollId, $userId);
- }
- $hash = $poll->getHash();
- $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
- return new RedirectResponse($url);
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @PublicPage
- * @param $pollId
- * @param $userId
- * @param $commentBox
- * @return JSONResponse
- */
- public function insertComment($pollId, $userId, $commentBox) {
- $comment = new Comment();
- $comment->setPollId($pollId);
- $comment->setUserId($userId);
- $comment->setComment($commentBox);
- $comment->setDt(date('Y-m-d H:i:s'));
- $this->commentMapper->insert($comment);
- $this->sendNotifications($pollId, $userId);
- if ($this->manager->get($userId) !== null) {
- $newUserId = $this->manager->get($userId)->getDisplayName();
- } else {
- $newUserId = $userId;
- }
- return new JSONResponse(array(
- 'comment' => $commentBox,
- 'date' => date('Y-m-d H:i:s'),
- 'userName' => $newUserId
- ));
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $searchTerm
- * @param $groups
- * @param $users
- * @return array
- */
- public function search($searchTerm, $groups, $users) {
- return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $searchTerm
- * @param $groups
- * @return array
- */
- public function searchForGroups($searchTerm, $groups) {
- $selectedGroups = json_decode($groups);
- $groups = $this->groupManager->search($searchTerm);
- $gids = array();
- $sgids = array();
- foreach ($selectedGroups as $sg) {
- $sgids[] = str_replace('group_', '', $sg);
- }
- foreach ($groups as $g) {
- $gids[] = $g->getGID();
- }
- $diffGids = array_diff($gids, $sgids);
- $gids = array();
- foreach ($diffGids as $g) {
- $gids[] = ['gid' => $g, 'isGroup' => true];
- }
- return $gids;
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $searchTerm
- * @param $users
- * @return array
- */
- public function searchForUsers($searchTerm, $users) {
- $selectedUsers = json_decode($users);
- Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
- $userNames = $this->userMgr->searchDisplayName($searchTerm);
- $users = array();
- $sUsers = array();
- foreach ($selectedUsers as $su) {
- $sUsers[] = str_replace('user_', '', $su);
- }
- foreach ($userNames as $u) {
- $alreadyAdded = false;
- foreach ($sUsers as &$su) {
- if ($su === $u->getUID()) {
- unset($su);
- $alreadyAdded = true;
- break;
- }
- }
- if (!$alreadyAdded) {
- $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
- } else {
- continue;
- }
- }
- return $users;
- }
-
- /**
- * @NoAdminRequired
- * @NoCSRFRequired
- * @param $username
- * @return string
- */
- public function getDisplayName($username) {
- return $this->manager->get($username)->getDisplayName();
- }
-
- /**
- * @return Event[]
- */
- public function getPollsForUser() {
- return $this->eventMapper->findAllForUser($this->userId);
- }
-
- /**
- * @param null $user
- * @return Event[]
- */
- public function getPollsForUserWithInfo($user = null) {
- if ($user === null) {
- return $this->eventMapper->findAllForUserWithInfo($this->userId);
- } else {
- return $this->eventMapper->findAllForUserWithInfo($user);
- }
- }
-
- /**
- * @return array
- */
- public function getGroups() {
- // $this->requireLogin();
- if (class_exists('\OC_Group', true)) {
- // Nextcloud <= 11, ownCloud
- return \OC_Group::getUserGroups($this->userId);
- }
- // Nextcloud >= 12
- $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
- return array_map(function ($group) {
- return $group->getGID();
- }, $groups);
- }
-
- /**
- * @param $poll
- * @return bool
- */
- private function hasUserAccess($poll) {
- $access = $poll->getAccess();
- $owner = $poll->getOwner();
- if ($access === 'public') {
- return true;
- }
- if ($access === 'hidden') {
- return true;
- }
- if ($this->userId === null) {
- return false;
- }
- if ($access === 'registered') {
- return true;
- }
- if ($owner === $this->userId) {
- return true;
- }
- Util::writeLog("polls", $this->userId, Util::ERROR);
- $user_groups = $this->getGroups();
- $arr = explode(';', $access);
- foreach ($arr as $item) {
- if (strpos($item, 'group_') === 0) {
- $grp = substr($item, 6);
- foreach ($user_groups as $user_group) {
- if ($user_group === $grp) {
- return true;
- }
- }
- } else {
- if (strpos($item, 'user_') === 0) {
- $usr = substr($item, 5);
- if ($usr === User::getUser()) {
- return true;
- }
- }
- }
- }
- return false;
- }
+ 'userId' => $this->userId,
+ 'userMgr' => $this->manager,
+ 'urlGenerator' => $this->urlGenerator
+ ]);
+ if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
+ $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
+ $response->setContentSecurityPolicy($csp);
+ }
+ return $response;
+ }
+
+ /**
+ * @param string $pollId
+ * @param string $from
+ */
+ private function sendNotifications($pollId, $from) {
+ $poll = $this->eventMapper->find($pollId);
+ $notifications = $this->notificationMapper->findAllByPoll($pollId);
+ foreach ($notifications as $notification) {
+ if ($from === $notification->getUserId()) {
+ continue;
+ }
+ $email = \OC::$server->getConfig()->getUserValue($notification->getUserId(), 'settings', 'email');
+ if (strlen($email) === 0 || !isset($email)) {
+ continue;
+ }
+ $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll',
+ array('hash' => $poll->getHash())));
+
+ $recUser = $this->userMgr->get($notification->getUserId());
+ $sendUser = $this->userMgr->get($from);
+ $rec = "";
+ if ($recUser !== null) {
+ $rec = $recUser->getDisplayName();
+ }
+ if ($sendUser !== null) {
+ $sender = $sendUser->getDisplayName();
+ } else {
+ $sender = $from;
+ }
+ $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>',
+ array(
+ $rec,
+ $sender,
+ $poll->getTitle(),
+ $url
+ ));
+
+ $msg .= "<br/><br/>";
+
+ $toName = $this->userMgr->get($notification->getUserId())->getDisplayName();
+ $subject = $this->trans->t('Polls App - New Comment');
+ $fromAddress = Util::getDefaultEmailAddress('no-reply');
+ $fromName = $this->trans->t("Polls App") . ' (' . $from . ')';
+
+ try {
+ $mailer = \OC::$server->getMailer();
+ $message = $mailer->createMessage();
+ $message->setSubject($subject);
+ $message->setFrom(array($fromAddress => $fromName));
+ $message->setTo(array($email => $toName));
+ $message->setHtmlBody($msg);
+ $mailer->send($message);
+ } catch (\Exception $e) {
+ $message = 'Error sending mail to: ' . $toName . ' (' . $email . ')';
+ Util::writeLog("polls", $message, Util::ERROR);
+ }
+ }
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @PublicPage
+ * @param string $hash
+ * @return TemplateResponse
+ */
+ public function gotoPoll($hash) {
+ $poll = $this->eventMapper->findByHash($hash);
+ if ($poll->getType() == '0') {
+ $dates = $this->dateMapper->findByPoll($poll->getId());
+ $votes = $this->participationMapper->findByPoll($poll->getId());
+ } else {
+ $dates = $this->textMapper->findByPoll($poll->getId());
+ $votes = $this->participationTextMapper->findByPoll($poll->getId());
+ }
+ $comments = $this->commentMapper->findByPoll($poll->getId());
+ try {
+ $notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
+ } catch (DoesNotExistException $e) {
+ $notification = null;
+ }
+ if ($this->hasUserAccess($poll)) {
+ return new TemplateResponse('polls', 'goto.tmpl', [
+ 'poll' => $poll,
+ 'dates' => $dates,
+ 'comments' => $comments,
+ 'votes' => $votes,
+ 'notification' => $notification,
+ 'userId' => $this->userId,
+ 'userMgr' => $this->manager,
+ 'urlGenerator' => $this->urlGenerator,
+ 'avatarManager' => $this->avatarManager
+ ]);
+ } else {
+ User::checkLoggedIn();
+ return new TemplateResponse('polls', 'no.acc.tmpl', []);
+ }
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param string $pollId
+ * @return RedirectResponse
+ */
+ public function deletePoll($pollId) {
+ $poll = new Event();
+ $poll->setId($pollId);
+ $this->eventMapper->delete($poll);
+ $this->textMapper->deleteByPoll($pollId);
+ $this->dateMapper->deleteByPoll($pollId);
+ $this->participationMapper->deleteByPoll($pollId);
+ $this->participationTextMapper->deleteByPoll($pollId);
+ $this->commentMapper->deleteByPoll($pollId);
+ $url = $this->urlGenerator->linkToRoute('polls.page.index');
+ return new RedirectResponse($url);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param string $hash
+ * @return TemplateResponse
+ */
+ public function editPoll($hash) {
+ $poll = $this->eventMapper->findByHash($hash);
+ if ($this->userId !== $poll->getOwner()) {
+ return new TemplateResponse('polls', 'no.create.tmpl');
+ }
+ if ($poll->getType() == '0') {
+ $dates = $this->dateMapper->findByPoll($poll->getId());
+ } else {
+ $dates = $this->textMapper->findByPoll($poll->getId());
+ }
+ return new TemplateResponse('polls', 'create.tmpl', [
+ 'poll' => $poll,
+ 'dates' => $dates,
+ 'userId' => $this->userId,
+ 'userMgr' => $this->manager,
+ 'urlGenerator' => $this->urlGenerator
+ ]);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $pollId
+ * @param $pollType
+ * @param $pollTitle
+ * @param $pollDesc
+ * @param $userId
+ * @param $chosenDates
+ * @param $expireTs
+ * @param $accessType
+ * @param $accessValues
+ * @param $isAnonymous
+ * @param $hideNames
+ * @return RedirectResponse
+ */
+ public function updatePoll(
+ $pollId,
+ $pollType,
+ $pollTitle,
+ $pollDesc,
+ $userId,
+ $chosenDates,
+ $expireTs,
+ $accessType,
+ $accessValues,
+ $isAnonymous,
+ $hideNames
+ ) {
+ $event = $this->eventMapper->find($pollId);
+ $event->setTitle(htmlspecialchars($pollTitle));
+ $event->setDescription(htmlspecialchars($pollDesc));
+ $event->setIsAnonymous($isAnonymous ? 1 : 0);
+ $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
+
+ if ($accessType === 'select') {
+ if (isset($accessValues)) {
+ $accessValues = json_decode($accessValues);
+ if ($accessValues !== null) {
+ $groups = array();
+ $users = array();
+ if ($accessValues->groups !== null) {
+ $groups = $accessValues->groups;
+ }
+ if ($accessValues->users !== null) {
+ $users = $accessValues->users;
+ }
+ $accessType = '';
+ foreach ($groups as $gid) {
+ $accessType .= $gid . ';';
+ }
+ foreach ($users as $uid) {
+ $accessType .= $uid . ';';
+ }
+ }
+ }
+ }
+ $event->setAccess($accessType);
+
+ $chosenDates = json_decode($chosenDates);
+
+ $expire = null;
+ if ($expireTs !== null && $expireTs !== '') {
+ $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
+ }
+ $event->setExpire($expire);
+
+ $this->dateMapper->deleteByPoll($pollId);
+ $this->textMapper->deleteByPoll($pollId);
+ if ($pollType === 'event') {
+ $event->setType(0);
+ $this->eventMapper->update($event);
+ sort($chosenDates);
+ foreach ($chosenDates as $el) {
+ $date = new Date();
+ $date->setPollId($pollId);
+ $date->setDt(date('Y-m-d H:i:s', $el));
+ $this->dateMapper->insert($date);
+ }
+ } else {
+ $event->setType(1);
+ $this->eventMapper->update($event);
+ foreach ($chosenDates as $el) {
+ $text = new Text();
+ $text->setText($el);
+ $text->setPollId($pollId);
+ $this->textMapper->insert($text);
+ }
+ }
+ $url = $this->urlGenerator->linkToRoute('polls.page.index');
+ return new RedirectResponse($url);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function createPoll() {
+ return new TemplateResponse('polls', 'create.tmpl',
+ ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $pollType
+ * @param $pollTitle
+ * @param $pollDesc
+ * @param $userId
+ * @param $chosenDates
+ * @param $expireTs
+ * @param $accessType
+ * @param $accessValues
+ * @param $isAnonymous
+ * @param $hideNames
+ * @return RedirectResponse
+ */
+ public function insertPoll(
+ $pollType,
+ $pollTitle,
+ $pollDesc,
+ $userId,
+ $chosenDates,
+ $expireTs,
+ $accessType,
+ $accessValues,
+ $isAnonymous,
+ $hideNames
+ ) {
+ $event = new Event();
+ $event->setTitle(htmlspecialchars($pollTitle));
+ $event->setDescription(htmlspecialchars($pollDesc));
+ $event->setOwner($userId);
+ $event->setCreated(date('Y-m-d H:i:s'));
+ $event->setHash(\OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(16,
+ ISecureRandom::CHAR_DIGITS .
+ ISecureRandom::CHAR_LOWER .
+ ISecureRandom::CHAR_UPPER));
+ $event->setIsAnonymous($isAnonymous ? 1 : 0);
+ $event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
+
+ if ($accessType === 'select') {
+ if (isset($accessValues)) {
+ $accessValues = json_decode($accessValues);
+ if ($accessValues !== null) {
+ $groups = array();
+ $users = array();
+ if ($accessValues->groups !== null) {
+ $groups = $accessValues->groups;
+ }
+ if ($accessValues->users !== null) {
+ $users = $accessValues->users;
+ }
+ $accessType = '';
+ foreach ($groups as $gid) {
+ $accessType .= $gid . ';';
+ }
+ foreach ($users as $uid) {
+ $accessType .= $uid . ';';
+ }
+ }
+ }
+ }
+ $event->setAccess($accessType);
+
+ $chosenDates = json_decode($chosenDates);
+
+ $expire = null;
+ if ($expireTs !== null && $expireTs !== '') {
+ $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24); //add one day, so it expires at the end of a day
+ }
+ $event->setExpire($expire);
+
+ if ($pollType === 'event') {
+ $event->setType(0);
+ $ins = $this->eventMapper->insert($event);
+ $poll_id = $ins->getId();
+ sort($chosenDates);
+ foreach ($chosenDates as $el) {
+ $date = new Date();
+ $date->setPollId($poll_id);
+ $date->setDt(date('Y-m-d H:i:s', $el));
+ $this->dateMapper->insert($date);
+ }
+ } else {
+ $event->setType(1);
+ $ins = $this->eventMapper->insert($event);
+ $poll_id = $ins->getId();
+ $cnt = 1;
+ foreach ($chosenDates as $el) {
+ $text = new Text();
+ $text->setText($el . '_' . $cnt);
+ $text->setPollId($poll_id);
+ $this->textMapper->insert($text);
+ $cnt++;
+ }
+ }
+ $url = $this->urlGenerator->linkToRoute('polls.page.index');
+ return new RedirectResponse($url);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @PublicPage
+ * @param $pollId
+ * @param $userId
+ * @param $types
+ * @param $dates
+ * @param $receiveNotifications
+ * @param $changed
+ * @return RedirectResponse
+ */
+ public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
+ if ($this->userId !== null) {
+ if ($receiveNotifications === 'true') {
+ try {
+ //check if user already set notification for this poll
+ $this->notificationMapper->findByUserAndPoll($pollId, $userId);
+ } catch (DoesNotExistException $e) {
+ //insert if not exist
+ $not = new Notification();
+ $not->setUserId($userId);
+ $not->setPollId($pollId);
+ $this->notificationMapper->insert($not);
+ }
+ } else {
+ try {
+ //delete if entry is in db
+ $not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
+ $this->notificationMapper->delete($not);
+ } catch (DoesNotExistException $e) {
+ //doesn't exist in db, nothing to do
+ }
+ }
+ }
+ $poll = $this->eventMapper->find($pollId);
+ if ($changed === 'true') {
+ $dates = json_decode($dates);
+ $types = json_decode($types);
+ $count_dates = count($dates);
+ if ($poll->getType() == '0') {
+ $this->participationMapper->deleteByPollAndUser($pollId, $userId);
+ } else {
+ $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
+ }
+ for ($i = 0; $i < $count_dates; $i++) {
+ if ($poll->getType() == '0') {
+ $part = new Participation();
+ $part->setPollId($pollId);
+ $part->setUserId($userId);
+ $part->setDt(date('Y-m-d H:i:s', $dates[$i]));
+ $part->setType($types[$i]);
+ $this->participationMapper->insert($part);
+ } else {
+ $part = new ParticipationText();
+ $part->setPollId($pollId);
+ $part->setUserId($userId);
+ $part->setText($dates[$i]);
+ $part->setType($types[$i]);
+ $this->participationTextMapper->insert($part);
+ }
+
+ }
+ $this->sendNotifications($pollId, $userId);
+ }
+ $hash = $poll->getHash();
+ $url = $this->urlGenerator->linkToRoute('polls.page.goto_poll', ['hash' => $hash]);
+ return new RedirectResponse($url);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @PublicPage
+ * @param $pollId
+ * @param $userId
+ * @param $commentBox
+ * @return JSONResponse
+ */
+ public function insertComment($pollId, $userId, $commentBox) {
+ $comment = new Comment();
+ $comment->setPollId($pollId);
+ $comment->setUserId($userId);
+ $comment->setComment($commentBox);
+ $comment->setDt(date('Y-m-d H:i:s'));
+ $this->commentMapper->insert($comment);
+ $this->sendNotifications($pollId, $userId);
+ if ($this->manager->get($userId) !== null) {
+ $newUserId = $this->manager->get($userId)->getDisplayName();
+ } else {
+ $newUserId = $userId;
+ }
+ return new JSONResponse(array(
+ 'comment' => $commentBox,
+ 'date' => date('Y-m-d H:i:s'),
+ 'userName' => $newUserId
+ ));
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $searchTerm
+ * @param $groups
+ * @param $users
+ * @return array
+ */
+ public function search($searchTerm, $groups, $users) {
+ return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $searchTerm
+ * @param $groups
+ * @return array
+ */
+ public function searchForGroups($searchTerm, $groups) {
+ $selectedGroups = json_decode($groups);
+ $groups = $this->groupManager->search($searchTerm);
+ $gids = array();
+ $sgids = array();
+ foreach ($selectedGroups as $sg) {
+ $sgids[] = str_replace('group_', '', $sg);
+ }
+ foreach ($groups as $g) {
+ $gids[] = $g->getGID();
+ }
+ $diffGids = array_diff($gids, $sgids);
+ $gids = array();
+ foreach ($diffGids as $g) {
+ $gids[] = ['gid' => $g, 'isGroup' => true];
+ }
+ return $gids;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $searchTerm
+ * @param $users
+ * @return array
+ */
+ public function searchForUsers($searchTerm, $users) {
+ $selectedUsers = json_decode($users);
+ Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
+ $userNames = $this->userMgr->searchDisplayName($searchTerm);
+ $users = array();
+ $sUsers = array();
+ foreach ($selectedUsers as $su) {
+ $sUsers[] = str_replace('user_', '', $su);
+ }
+ foreach ($userNames as $u) {
+ $alreadyAdded = false;
+ foreach ($sUsers as &$su) {
+ if ($su === $u->getUID()) {
+ unset($su);
+ $alreadyAdded = true;
+ break;
+ }
+ }
+ if (!$alreadyAdded) {
+ $users[] = array('uid' => $u->getUID(), 'displayName' => $u->getDisplayName(), 'isGroup' => false);
+ } else {
+ continue;
+ }
+ }
+ return $users;
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @param $username
+ * @return string
+ */
+ public function getDisplayName($username) {
+ return $this->manager->get($username)->getDisplayName();
+ }
+
+ /**
+ * @return Event[]
+ */
+ public function getPollsForUser() {
+ return $this->eventMapper->findAllForUser($this->userId);
+ }
+
+ /**
+ * @param $user
+ * @return Event[]
+ */
+ public function getPollsForUserWithInfo($user = null) {
+ if ($user === null) {
+ return $this->eventMapper->findAllForUserWithInfo($this->userId);
+ } else {
+ return $this->eventMapper->findAllForUserWithInfo($user);
+ }
+ }
+ /**
+ * @return array
+ */
+ public function getGroups() {
+ // $this->requireLogin();
+ if (class_exists('\OC_Group', true)) {
+ // Nextcloud <= 11, ownCloud
+ return \OC_Group::getUserGroups($this->userId);
+ }
+ // Nextcloud >= 12
+ $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
+ return array_map(function ($group) {
+ return $group->getGID();
+ }, $groups);
+ }
+
+ /**
+ * @param $poll
+ * @return bool
+ */
+ private function hasUserAccess($poll) {
+ $access = $poll->getAccess();
+ $owner = $poll->getOwner();
+ if ($access === 'public') {
+ return true;
+ }
+ if ($access === 'hidden') {
+ return true;
+ }
+ if ($this->userId === null) {
+ return false;
+ }
+ if ($access === 'registered') {
+ return true;
+ }
+ if ($owner === $this->userId) {
+ return true;
+ }
+ Util::writeLog("polls", $this->userId, Util::ERROR);
+ $user_groups = $this->getGroups();
+ $arr = explode(';', $access);
+ foreach ($arr as $item) {
+ if (strpos($item, 'group_') === 0) {
+ $grp = substr($item, 6);
+ foreach ($user_groups as $user_group) {
+ if ($user_group === $grp) {
+ return true;
+ }
+ }
+ } else {
+ if (strpos($item, 'user_') === 0) {
+ $usr = substr($item, 5);
+ if ($usr === User::getUser()) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php
index fa0481f1..28b5ae35 100644
--- a/lib/Db/Comment.php
+++ b/lib/Db/Comment.php
@@ -36,8 +36,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setPollId(integer $value)
*/
class Comment extends Entity {
- public $userId;
- public $dt;
- public $comment;
- public $pollId;
+ public $userId;
+ public $dt;
+ public $comment;
+ public $pollId;
}
diff --git a/lib/Db/CommentMapper.php b/lib/Db/CommentMapper.php
index 66b863c6..e2bdbcf1 100644
--- a/lib/Db/CommentMapper.php
+++ b/lib/Db/CommentMapper.php
@@ -28,41 +28,41 @@ use OCP\IDBConnection;
class CommentMapper extends Mapper {
- /**
- * CommentMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment');
- }
+ /**
+ * CommentMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment');
+ }
- /**
- * @param string $userId
- * @param int $limit
- * @param int $offset
- * @return Comment[]
- */
- public function findDistinctByUser($userId, $limit = null, $offset = null) {
- $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
- return $this->findEntities($sql, [$userId], $limit, $offset);
- }
+ /**
+ * @param string $userId
+ * @param int $limit
+ * @param int $offset
+ * @return Comment[]
+ */
+ public function findDistinctByUser($userId, $limit = null, $offset = null) {
+ $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
+ return $this->findEntities($sql, [$userId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return Comment[]
- */
- public function findByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? ORDER BY Dt DESC';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Comment[]
+ */
+ public function findByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? ORDER BY Dt DESC';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- */
- public function deleteByPoll($pollId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- $this->execute($sql, [$pollId]);
- }
+ /**
+ * @param string $pollId
+ */
+ public function deleteByPoll($pollId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ $this->execute($sql, [$pollId]);
+ }
}
diff --git a/lib/Db/Date.php b/lib/Db/Date.php
index 05ff0a06..d34a9a41 100644
--- a/lib/Db/Date.php
+++ b/lib/Db/Date.php
@@ -32,6 +32,6 @@ use OCP\AppFramework\Db\Entity;
* @method void setPollId(integer $value)
*/
class Date extends Entity {
- public $dt;
- public $pollId;
+ public $dt;
+ public $pollId;
}
diff --git a/lib/Db/DateMapper.php b/lib/Db/DateMapper.php
index d6b2889d..330dc0d8 100644
--- a/lib/Db/DateMapper.php
+++ b/lib/Db/DateMapper.php
@@ -28,30 +28,30 @@ use OCP\IDBConnection;
class DateMapper extends Mapper {
- /**
- * DateMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date');
- }
+ /**
+ * DateMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date');
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return Date[]
- */
- public function findByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Date[]
+ */
+ public function findByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- */
- public function deleteByPoll($pollId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- $this->execute($sql, [$pollId]);
- }
+ /**
+ * @param string $pollId
+ */
+ public function deleteByPoll($pollId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ $this->execute($sql, [$pollId]);
+ }
}
diff --git a/lib/Db/Event.php b/lib/Db/Event.php
index 8882adcb..df4c1ca8 100644
--- a/lib/Db/Event.php
+++ b/lib/Db/Event.php
@@ -48,14 +48,14 @@ use OCP\AppFramework\Db\Entity;
* @method void setFullAnonymous(integer $value)
*/
class Event extends Entity {
- public $type;
- public $title;
- public $description;
- public $owner;
- public $created;
- public $access;
- public $expire;
- public $hash;
- public $isAnonymous;
- public $fullAnonymous;
+ public $type;
+ public $title;
+ public $description;
+ public $owner;
+ public $created;
+ public $access;
+ public $expire;
+ public $hash;
+ public $isAnonymous;
+ public $fullAnonymous;
}
diff --git a/lib/Db/EventMapper.php b/lib/Db/EventMapper.php
index b5088af0..44ed6a84 100644
--- a/lib/Db/EventMapper.php
+++ b/lib/Db/EventMapper.php
@@ -28,79 +28,79 @@ use OCP\IDBConnection;
class EventMapper extends Mapper {
- /**
- * EventMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event');
- }
+ /**
+ * EventMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event');
+ }
- /**
- * @param int $id
- * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
- * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
- * @return Event
- */
- public function find($id) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
- return $this->findEntity($sql, [$id]);
- }
+ /**
+ * @param int $id
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Event
+ */
+ public function find($id) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
+ return $this->findEntity($sql, [$id]);
+ }
- /**
- * @param $hash
- * @param int $limit
- * @param int $offset
- * @return Event
- */
- public function findByHash($hash, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?';
- return $this->findEntity($sql, [$hash], $limit, $offset);
- }
+ /**
+ * @param $hash
+ * @param int $limit
+ * @param int $offset
+ * @return Event
+ */
+ public function findByHash($hash, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?';
+ return $this->findEntity($sql, [$hash], $limit, $offset);
+ }
- /**
- * @param $userId
- * @param int $limit
- * @param int $offset
- * @return Event[]
- */
- public function findAllForUser($userId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?';
- return $this->findEntities($sql, [$userId], $limit, $offset);
- }
+ /**
+ * @param $userId
+ * @param int $limit
+ * @param int $offset
+ * @return Event[]
+ */
+ public function findAllForUser($userId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?';
+ return $this->findEntities($sql, [$userId], $limit, $offset);
+ }
- /**
- * @param string $userId
- * @param int $limit
- * @param int $offset
- * @return Event[]
- */
- public function findAllForUserWithInfo($userId, $limit = null, $offset = null) {
- $sql = 'SELECT DISTINCT *PREFIX*polls_events.id,
- *PREFIX*polls_events.hash,
- *PREFIX*polls_events.type,
- *PREFIX*polls_events.title,
- *PREFIX*polls_events.description,
- *PREFIX*polls_events.owner,
- *PREFIX*polls_events.created,
- *PREFIX*polls_events.access,
- *PREFIX*polls_events.expire,
- *PREFIX*polls_events.is_anonymous,
- *PREFIX*polls_events.full_anonymous
- FROM *PREFIX*polls_events
- LEFT JOIN *PREFIX*polls_particip
- ON *PREFIX*polls_events.id = *PREFIX*polls_particip.id
- LEFT JOIN *PREFIX*polls_comments
- ON *PREFIX*polls_events.id = *PREFIX*polls_comments.id
- WHERE
- (*PREFIX*polls_events.access = ? AND *PREFIX*polls_events.owner = ?)
- OR
- *PREFIX*polls_events.access != ?
- OR
- *PREFIX*polls_particip.user_id = ?
- OR
- *PREFIX*polls_comments.user_id = ?
- ORDER BY created';
- return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset);
- }
+ /**
+ * @param string $userId
+ * @param int $limit
+ * @param int $offset
+ * @return Event[]
+ */
+ public function findAllForUserWithInfo($userId, $limit = null, $offset = null) {
+ $sql = 'SELECT DISTINCT *PREFIX*polls_events.id,
+ *PREFIX*polls_events.hash,
+ *PREFIX*polls_events.type,
+ *PREFIX*polls_events.title,
+ *PREFIX*polls_events.description,
+ *PREFIX*polls_events.owner,
+ *PREFIX*polls_events.created,
+ *PREFIX*polls_events.access,
+ *PREFIX*polls_events.expire,
+ *PREFIX*polls_events.is_anonymous,
+ *PREFIX*polls_events.full_anonymous
+ FROM *PREFIX*polls_events
+ LEFT JOIN *PREFIX*polls_particip
+ ON *PREFIX*polls_events.id = *PREFIX*polls_particip.id
+ LEFT JOIN *PREFIX*polls_comments
+ ON *PREFIX*polls_events.id = *PREFIX*polls_comments.id
+ WHERE
+ (*PREFIX*polls_events.access = ? AND *PREFIX*polls_events.owner = ?)
+ OR
+ *PREFIX*polls_events.access != ?
+ OR
+ *PREFIX*polls_particip.user_id = ?
+ OR
+ *PREFIX*polls_comments.user_id = ?
+ ORDER BY created';
+ return $this->findEntities($sql, ['hidden', $userId, 'hidden', $userId, $userId], $limit, $offset);
+ }
}
diff --git a/lib/Db/Notification.php b/lib/Db/Notification.php
index 6b2d4408..eb5c2180 100644
--- a/lib/Db/Notification.php
+++ b/lib/Db/Notification.php
@@ -32,6 +32,6 @@ use OCP\AppFramework\Db\Entity;
* @method void setPollId(string $value)
*/
class Notification extends Entity {
- public $userId;
- public $pollId;
+ public $userId;
+ public $pollId;
}
diff --git a/lib/Db/NotificationMapper.php b/lib/Db/NotificationMapper.php
index 1db5fb8a..c5ee3b38 100644
--- a/lib/Db/NotificationMapper.php
+++ b/lib/Db/NotificationMapper.php
@@ -28,62 +28,62 @@ use OCP\IDBConnection;
class NotificationMapper extends Mapper {
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification');
- }
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification');
+ }
- /**
- * @param int $id
- * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
- * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
- * @return Notification
- */
- public function find($id) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
- return $this->findEntity($sql, [$id]);
- }
+ /**
+ * @param int $id
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Notification
+ */
+ public function find($id) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
+ return $this->findEntity($sql, [$id]);
+ }
- /**
- * @param string $userId
- * @param string $from
- * @param string $until
- * @param int $limit
- * @param int $offset
- * @return Notification[]
- */
- public function findBetween($userId, $from, $until, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE userId = ? AND timestamp BETWEEN ? AND ?';
- return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset);
- }
+ /**
+ * @param string $userId
+ * @param string $from
+ * @param string $until
+ * @param int $limit
+ * @param int $offset
+ * @return Notification[]
+ */
+ public function findBetween($userId, $from, $until, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE userId = ? AND timestamp BETWEEN ? AND ?';
+ return $this->findEntities($sql, [$userId, $from, $until], $limit, $offset);
+ }
- /**
- * @param int $limit
- * @param int $offset
- * @return Notification[]
- */
- public function findAll($limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName();
- return $this->findEntities($sql, [], $limit, $offset);
- }
+ /**
+ * @param int $limit
+ * @param int $offset
+ * @return Notification[]
+ */
+ public function findAll($limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
+ return $this->findEntities($sql, [], $limit, $offset);
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return Notification[]
- */
- public function findAllByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Notification[]
+ */
+ public function findAllByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- * @param string $userId
- * @return Notification if not found
- */
- public function findByUserAndPoll($pollId, $userId) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
- return $this->findEntity($sql, [$pollId, $userId]);
- }
+ /**
+ * @param string $pollId
+ * @param string $userId
+ * @return Notification if not found
+ */
+ public function findByUserAndPoll($pollId, $userId) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
+ return $this->findEntity($sql, [$pollId, $userId]);
+ }
}
diff --git a/lib/Db/Participation.php b/lib/Db/Participation.php
index 8e343e18..a8494c86 100644
--- a/lib/Db/Participation.php
+++ b/lib/Db/Participation.php
@@ -36,8 +36,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setType(integer $value)
*/
class Participation extends Entity {
- public $dt;
- public $userId;
- public $pollId;
- public $type;
+ public $dt;
+ public $userId;
+ public $pollId;
+ public $type;
}
diff --git a/lib/Db/ParticipationMapper.php b/lib/Db/ParticipationMapper.php
index 4c3e75e5..dfb2a7c9 100644
--- a/lib/Db/ParticipationMapper.php
+++ b/lib/Db/ParticipationMapper.php
@@ -28,50 +28,50 @@ use OCP\IDBConnection;
class ParticipationMapper extends Mapper {
- /**
- * ParticipationMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_particip', '\OCA\Polls\Db\Participation');
- }
+ /**
+ * ParticipationMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_particip', '\OCA\Polls\Db\Participation');
+ }
- /**
- * @param string $userId
- * @param int $limit
- * @param int $offset
- * @return Participation[]
- */
- public function findDistinctByUser($userId, $limit = null, $offset = null) {
- $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
- return $this->findEntities($sql, [$userId], $limit, $offset);
- }
+ /**
+ * @param string $userId
+ * @param int $limit
+ * @param int $offset
+ * @return Participation[]
+ */
+ public function findDistinctByUser($userId, $limit = null, $offset = null) {
+ $sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
+ return $this->findEntities($sql, [$userId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return Participation[]
- */
- public function findByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Participation[]
+ */
+ public function findByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- */
- public function deleteByPoll($pollId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- $this->execute($sql, [$pollId]);
- }
+ /**
+ * @param string $pollId
+ */
+ public function deleteByPoll($pollId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ $this->execute($sql, [$pollId]);
+ }
- /**
- * @param string $pollId
- * @param string $userId
- */
- public function deleteByPollAndUser($pollId, $userId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
- $this->execute($sql, [$pollId, $userId]);
- }
+ /**
+ * @param string $pollId
+ * @param string $userId
+ */
+ public function deleteByPollAndUser($pollId, $userId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
+ $this->execute($sql, [$pollId, $userId]);
+ }
}
diff --git a/lib/Db/ParticipationText.php b/lib/Db/ParticipationText.php
index 56ac2415..6fd05cca 100644
--- a/lib/Db/ParticipationText.php
+++ b/lib/Db/ParticipationText.php
@@ -36,8 +36,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setType(integer $value)
*/
class ParticipationText extends Entity {
- public $text;
- public $userId;
- public $pollId;
- public $type;
+ public $text;
+ public $userId;
+ public $pollId;
+ public $type;
}
diff --git a/lib/Db/ParticipationTextMapper.php b/lib/Db/ParticipationTextMapper.php
index a5a290df..28a4b127 100644
--- a/lib/Db/ParticipationTextMapper.php
+++ b/lib/Db/ParticipationTextMapper.php
@@ -28,24 +28,24 @@ use OCP\IDBConnection;
class ParticipationTextMapper extends Mapper {
- /**
- * ParticipationTextMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText');
- }
+ /**
+ * ParticipationTextMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText');
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return ParticipationText[]
- */
- public function findByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return ParticipationText[]
+ */
+ public function findByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
/**
* @param string $userId
@@ -58,20 +58,20 @@ class ParticipationTextMapper extends Mapper {
return $this->findEntities($sql, [$userId], $limit, $offset);
}
- /**
- * @param string $pollId
- */
- public function deleteByPoll($pollId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- $this->execute($sql, [$pollId]);
- }
+ /**
+ * @param string $pollId
+ */
+ public function deleteByPoll($pollId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ $this->execute($sql, [$pollId]);
+ }
- /**
- * @param string $pollId
- * @param string $userId
- */
- public function deleteByPollAndUser($pollId, $userId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
- $this->execute($sql, [$pollId, $userId]);
- }
+ /**
+ * @param string $pollId
+ * @param string $userId
+ */
+ public function deleteByPollAndUser($pollId, $userId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
+ $this->execute($sql, [$pollId, $userId]);
+ }
}
diff --git a/lib/Db/Text.php b/lib/Db/Text.php
index e98c168b..792e4caf 100644
--- a/lib/Db/Text.php
+++ b/lib/Db/Text.php
@@ -32,6 +32,6 @@ use OCP\AppFramework\Db\Entity;
* @method void setPollId(integer $value)
*/
class Text extends Entity {
- public $text;
- public $pollId;
+ public $text;
+ public $pollId;
}
diff --git a/lib/Db/TextMapper.php b/lib/Db/TextMapper.php
index fe6626a4..5c4df02d 100644
--- a/lib/Db/TextMapper.php
+++ b/lib/Db/TextMapper.php
@@ -28,30 +28,30 @@ use OCP\IDBConnection;
class TextMapper extends Mapper {
- /**
- * TextMapper constructor.
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $db) {
- parent::__construct($db, 'polls_txts', '\OCA\Polls\Db\Text');
- }
+ /**
+ * TextMapper constructor.
+ * @param IDBConnection $db
+ */
+ public function __construct(IDBConnection $db) {
+ parent::__construct($db, 'polls_txts', '\OCA\Polls\Db\Text');
+ }
- /**
- * @param string $pollId
- * @param int $limit
- * @param int $offset
- * @return Text[]
- */
- public function findByPoll($pollId, $limit = null, $offset = null) {
- $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- return $this->findEntities($sql, [$pollId], $limit, $offset);
- }
+ /**
+ * @param string $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Text[]
+ */
+ public function findByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
- /**
- * @param string $pollId
- */
- public function deleteByPoll($pollId) {
- $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
- $this->execute($sql, [$pollId]);
- }
+ /**
+ * @param string $pollId
+ */
+ public function deleteByPoll($pollId) {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ $this->execute($sql, [$pollId]);
+ }
}