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:
authorVinzenz Rosenkranz <v1r0x@users.noreply.github.com>2017-11-27 12:05:20 +0300
committerGitHub <noreply@github.com>2017-11-27 12:05:20 +0300
commit27b7ce87aaa57156c41db9e01300319a8cd63e22 (patch)
tree14ae7842f9d5903eefe03e0a442b15c9859b1e5e /lib
parentd06d5a38250637116552502c64157e84019ff954 (diff)
parentffb151c2f7cc8368809e73b96025a4e097c84d85 (diff)
Merge branch 'develop' into fix-line-break
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php44
-rw-r--r--lib/Controller/PageController.php242
-rw-r--r--lib/Db/Comment.php20
-rw-r--r--lib/Db/CommentMapper.php4
-rw-r--r--lib/Db/Date.php20
-rw-r--r--lib/Db/DateMapper.php4
-rw-r--r--lib/Db/Event.php42
-rw-r--r--lib/Db/EventMapper.php6
-rw-r--r--lib/Db/Model.php39
-rw-r--r--lib/Db/Notification.php20
-rw-r--r--lib/Db/NotificationMapper.php8
-rw-r--r--lib/Db/Participation.php25
-rw-r--r--lib/Db/ParticipationMapper.php17
-rw-r--r--lib/Db/ParticipationText.php21
-rw-r--r--lib/Db/ParticipationTextMapper.php17
-rw-r--r--lib/Db/Text.php16
-rw-r--r--lib/Db/TextMapper.php4
17 files changed, 320 insertions, 229 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 810362d7..5f7c7ef4 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -25,7 +25,7 @@ namespace OCA\Polls\AppInfo;
use OC\AppFramework\Utility\SimpleContainer;
-use OCP\AppFramework\App;
+use OCA\Polls\Controller\PageController;
use OCA\Polls\Db\CommentMapper;
use OCA\Polls\Db\DateMapper;
use OCA\Polls\Db\EventMapper;
@@ -33,7 +33,7 @@ use OCA\Polls\Db\NotificationMapper;
use OCA\Polls\Db\ParticipationMapper;
use OCA\Polls\Db\ParticipationTextMapper;
use OCA\Polls\Db\TextMapper;
-use OCA\Polls\Controller\PageController;
+use OCP\AppFramework\App;
class Application extends App {
@@ -50,8 +50,7 @@ class Application extends App {
/**
* Controllers
*/
- $container->registerService('PageController', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('PageController', function (SimpleContainer $c) {
return new PageController(
$c->query('AppName'),
$c->query('Request'),
@@ -72,74 +71,63 @@ class Application extends App {
);
});
- $container->registerService('UserManager', function ($c) {
- /** @var SimpleContainer $c */
+ $container->registerService('UserManager', function (SimpleContainer $c) {
return $c->query('ServerContainer')->getUserManager();
});
- $container->registerService('GroupManager', function ($c) {
- /** @var SimpleContainer $c */
+ $container->registerService('GroupManager', function (SimpleContainer $c) {
return $c->query('ServerContainer')->getGroupManager();
});
- $container->registerService('AvatarManager', function ($c) {
- /** @var SimpleContainer $c */
+ $container->registerService('AvatarManager', function (SimpleContainer $c) {
return $c->query('ServerContainer')->getAvatarManager();
});
- $container->registerService('Logger', function ($c) {
- /** @var SimpleContainer $c */
+ $container->registerService('Logger', function (SimpleContainer $c) {
return $c->query('ServerContainer')->getLogger();
});
- $container->registerService('L10N', function ($c) {
+ $container->registerService('L10N', function (SimpleContainer $c) {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});
- $container->registerService('CommentMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('CommentMapper', function (SimpleContainer $c) use ($server) {
return new CommentMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('DateMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('DateMapper', function (SimpleContainer $c) use ($server) {
return new DateMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('EventMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('EventMapper', function (SimpleContainer $c) use ($server) {
return new EventMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('NotificationMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('NotificationMapper', function (SimpleContainer $c) use ($server) {
return new NotificationMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('ParticipationMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('ParticipationMapper', function (SimpleContainer $c) use ($server) {
return new ParticipationMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('ParticipationTextMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('ParticipationTextMapper', function (SimpleContainer $c) use ($server) {
return new ParticipationTextMapper(
$server->getDatabaseConnection()
);
});
- $container->registerService('TextMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
+ $container->registerService('TextMapper', function (SimpleContainer $c) use ($server) {
return new TextMapper(
$server->getDatabaseConnection()
);
@@ -158,7 +146,7 @@ class Application extends App {
'id' => 'polls',
'order' => 77,
'href' => $urlGenerator->linkToRoute('polls.page.index'),
- 'icon' => $urlGenerator->imagePath('polls', 'app-logo-polls.svg'),
+ 'icon' => $urlGenerator->imagePath('polls', 'app.svg'),
'name' => $l10n->t('Polls')
];
});
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 9d33540f..02dcdeeb 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -24,32 +24,33 @@
namespace OCA\Polls\Controller;
use OCA\Polls\Db\Comment;
-use OCA\Polls\Db\Date;
-use OCA\Polls\Db\Event;
-use OCA\Polls\Db\Notification;
-use OCA\Polls\Db\Participation;
-use OCA\Polls\Db\ParticipationText;
-use OCA\Polls\Db\Text;
use OCA\Polls\Db\CommentMapper;
+use OCA\Polls\Db\Date;
use OCA\Polls\Db\DateMapper;
+use OCA\Polls\Db\Event;
use OCA\Polls\Db\EventMapper;
+use OCA\Polls\Db\Notification;
use OCA\Polls\Db\NotificationMapper;
+use OCA\Polls\Db\Participation;
use OCA\Polls\Db\ParticipationMapper;
+use OCA\Polls\Db\ParticipationText;
use OCA\Polls\Db\ParticipationTextMapper;
+use OCA\Polls\Db\Text;
use OCA\Polls\Db\TextMapper;
+use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
-use OCP\IUserManager;
-use OCP\IGroupManager;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\RedirectResponse;
+use OCP\AppFramework\Http\TemplateResponse;
use OCP\IAvatarManager;
-use OCP\ILogger;
+use OCP\IGroupManager;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\IURLGenerator;
+use OCP\IUserManager;
+use OCP\Mail\IMailer;
use OCP\Security\ISecureRandom;
-use OCP\AppFramework\Http\TemplateResponse;
-use OCP\AppFramework\Http\RedirectResponse;
-use OCP\AppFramework\Http\JSONResponse;
-use OCP\AppFramework\Controller;
use OCP\User;
use OCP\Util;
@@ -64,18 +65,17 @@ class PageController extends Controller {
private $participationTextMapper;
private $textMapper;
private $urlGenerator;
- private $manager;
+ private $userMgr;
private $avatarManager;
private $logger;
private $trans;
- private $userMgr;
private $groupManager;
/**
* PageController constructor.
* @param $appName
* @param IRequest $request
- * @param IUserManager $manager
+ * @param IUserManager $userMgr
* @param IGroupManager $groupManager
* @param IAvatarManager $avatarManager
* @param ILogger $logger
@@ -93,7 +93,7 @@ class PageController extends Controller {
public function __construct(
$appName,
IRequest $request,
- IUserManager $manager,
+ IUserManager $userMgr,
IGroupManager $groupManager,
IAvatarManager $avatarManager,
ILogger $logger,
@@ -109,7 +109,7 @@ class PageController extends Controller {
TextMapper $textMapper
) {
parent::__construct($appName, $request);
- $this->manager = $manager;
+ $this->userMgr = $userMgr;
$this->groupManager = $groupManager;
$this->avatarManager = $avatarManager;
$this->logger = $logger;
@@ -123,7 +123,6 @@ class PageController extends Controller {
$this->participationMapper = $ParticipationMapper;
$this->participationTextMapper = $ParticipationTextMapper;
$this->textMapper = $textMapper;
- $this->userMgr = \OC::$server->getUserManager();
}
/**
@@ -141,7 +140,7 @@ class PageController extends Controller {
'participations' => $partic,
'participations_text' => $particText,
'userId' => $this->userId,
- 'userMgr' => $this->manager,
+ 'userMgr' => $this->userMgr,
'urlGenerator' => $this->urlGenerator
]);
if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) {
@@ -152,7 +151,7 @@ class PageController extends Controller {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param string $from
*/
private function sendNotifications($pollId, $from) {
@@ -166,19 +165,20 @@ class PageController extends Controller {
if (strlen($email) === 0 || !isset($email)) {
continue;
}
- $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll',
- array('hash' => $poll->getHash())));
+ $url = $this->urlGenerator->getAbsoluteURL(
+ $this->urlGenerator->linkToRoute('polls.page.goto_poll',
+ array('hash' => $poll->getHash()))
+ );
$recUser = $this->userMgr->get($notification->getUserId());
$sendUser = $this->userMgr->get($from);
- $rec = "";
+ $rec = '';
if ($recUser !== null) {
$rec = $recUser->getDisplayName();
}
+ $sender = $from;
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(
@@ -188,15 +188,17 @@ class PageController extends Controller {
$url
));
- $msg .= "<br/><br/>";
+ $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 . ')';
+ $fromName = $this->trans->t('Polls App') . ' (' . $from . ')';
try {
+ /** @var IMailer $mailer */
$mailer = \OC::$server->getMailer();
+ /** @var \OC\Mail\Message $message */
$message = $mailer->createMessage();
$message->setSubject($subject);
$message->setFrom(array($fromAddress => $fromName));
@@ -205,7 +207,7 @@ class PageController extends Controller {
$mailer->send($message);
} catch (\Exception $e) {
$message = 'Error sending mail to: ' . $toName . ' (' . $email . ')';
- Util::writeLog("polls", $message, Util::ERROR);
+ Util::writeLog('polls', $message, Util::ERROR);
}
}
}
@@ -218,13 +220,19 @@ class PageController extends Controller {
* @return TemplateResponse
*/
public function gotoPoll($hash) {
- $poll = $this->eventMapper->findByHash($hash);
- if ($poll->getType() == '0') {
+ try {
+ $poll = $this->eventMapper->findByHash($hash);
+ } catch (DoesNotExistException $e) {
+ return new TemplateResponse('polls', 'no.acc.tmpl', []);
+ }
+ if ($poll->getType() === 0) {
$dates = $this->dateMapper->findByPoll($poll->getId());
$votes = $this->participationMapper->findByPoll($poll->getId());
+ $participants = $this->participationMapper->findParticipantsByPoll($poll->getId());
} else {
$dates = $this->textMapper->findByPoll($poll->getId());
$votes = $this->participationTextMapper->findByPoll($poll->getId());
+ $participants = $this->participationTextMapper->findParticipantsByPoll($poll->getId());
}
$comments = $this->commentMapper->findByPoll($poll->getId());
try {
@@ -238,9 +246,10 @@ class PageController extends Controller {
'dates' => $dates,
'comments' => $comments,
'votes' => $votes,
+ 'participants' => $participants,
'notification' => $notification,
'userId' => $this->userId,
- 'userMgr' => $this->manager,
+ 'userMgr' => $this->userMgr,
'urlGenerator' => $this->urlGenerator,
'avatarManager' => $this->avatarManager
]);
@@ -253,10 +262,14 @@ class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param string $pollId
- * @return RedirectResponse
+ * @param int $pollId
+ * @return TemplateResponse|RedirectResponse
*/
public function deletePoll($pollId) {
+ $pollToDelete = $this->eventMapper->find($pollId);
+ if ($this->userId !== $pollToDelete->getOwner()) {
+ return new TemplateResponse('polls', 'no.delete.tmpl');
+ }
$poll = new Event();
$poll->setId($pollId);
$this->eventMapper->delete($poll);
@@ -280,7 +293,7 @@ class PageController extends Controller {
if ($this->userId !== $poll->getOwner()) {
return new TemplateResponse('polls', 'no.create.tmpl');
}
- if ($poll->getType() == '0') {
+ if ($poll->getType() === 0) {
$dates = $this->dateMapper->findByPoll($poll->getId());
} else {
$dates = $this->textMapper->findByPoll($poll->getId());
@@ -289,7 +302,7 @@ class PageController extends Controller {
'poll' => $poll,
'dates' => $dates,
'userId' => $this->userId,
- 'userMgr' => $this->manager,
+ 'userMgr' => $this->userMgr,
'urlGenerator' => $this->urlGenerator
]);
}
@@ -297,17 +310,17 @@ class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param $pollId
- * @param $pollType
- * @param $pollTitle
- * @param $pollDesc
- * @param $userId
- * @param $chosenDates
- * @param $expireTs
- * @param $accessType
- * @param $accessValues
- * @param $isAnonymous
- * @param $hideNames
+ * @param int $pollId
+ * @param string $pollType
+ * @param string $pollTitle
+ * @param string $pollDesc
+ * @param string $userId
+ * @param string $chosenDates
+ * @param int $expireTs
+ * @param string $accessType
+ * @param string $accessValues
+ * @param bool $isAnonymous
+ * @param bool $hideNames
* @return RedirectResponse
*/
public function updatePoll(
@@ -352,12 +365,12 @@ class PageController extends Controller {
}
}
$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
+ // Add one day, so it expires at the end of a day
+ $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
}
$event->setExpire($expire);
@@ -393,22 +406,22 @@ class PageController extends Controller {
*/
public function createPoll() {
return new TemplateResponse('polls', 'create.tmpl',
- ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
+ ['userId' => $this->userId, 'userMgr' => $this->userMgr, '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
+ * @param string $pollType
+ * @param string $pollTitle
+ * @param string $pollDesc
+ * @param string $userId
+ * @param string $chosenDates
+ * @param int $expireTs
+ * @param string $accessType
+ * @param string $accessValues
+ * @param bool $isAnonymous
+ * @param bool $hideNames
* @return RedirectResponse
*/
public function insertPoll(
@@ -428,10 +441,12 @@ class PageController extends Controller {
$event->setDescription(htmlspecialchars(strip_tags($pollDesc)));
$event->setOwner($userId);
$event->setCreated(date('Y-m-d H:i:s'));
- $event->setHash(\OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(16,
+ $event->setHash(\OC::$server->getSecureRandom()->generate(
+ 16,
ISecureRandom::CHAR_DIGITS .
ISecureRandom::CHAR_LOWER .
- ISecureRandom::CHAR_UPPER));
+ ISecureRandom::CHAR_UPPER
+ ));
$event->setIsAnonymous($isAnonymous ? 1 : 0);
$event->setFullAnonymous($isAnonymous && $hideNames ? 1 : 0);
@@ -458,12 +473,12 @@ class PageController extends Controller {
}
}
$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
+ // Add one day, so it expires at the end of a day
+ $expire = date('Y-m-d H:i:s', $expireTs + 60 * 60 * 24);
}
$event->setExpire($expire);
@@ -499,17 +514,17 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
- * @param $pollId
- * @param $userId
- * @param $types
- * @param $dates
- * @param $receiveNotifications
- * @param $changed
+ * @param int $pollId
+ * @param string $userId
+ * @param string $types
+ * @param string $dates
+ * @param bool $receiveNotifications
+ * @param bool $changed
* @return RedirectResponse
*/
public function insertVote($pollId, $userId, $types, $dates, $receiveNotifications, $changed) {
if ($this->userId !== null) {
- if ($receiveNotifications === 'true') {
+ if ($receiveNotifications) {
try {
//check if user already set notification for this poll
$this->notificationMapper->findByUserAndPoll($pollId, $userId);
@@ -531,17 +546,17 @@ class PageController extends Controller {
}
}
$poll = $this->eventMapper->find($pollId);
- if ($changed === 'true') {
+ if ($changed) {
$dates = json_decode($dates);
$types = json_decode($types);
$count_dates = count($dates);
- if ($poll->getType() == '0') {
+ 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') {
+ if ($poll->getType() === 0) {
$part = new Participation();
$part->setPollId($pollId);
$part->setUserId($userId);
@@ -569,9 +584,9 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
- * @param $pollId
- * @param $userId
- * @param $commentBox
+ * @param int $pollId
+ * @param string $userId
+ * @param string $commentBox
* @return JSONResponse
*/
public function insertComment($pollId, $userId, $commentBox) {
@@ -582,10 +597,9 @@ class PageController extends Controller {
$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;
+ $newUserId = $userId;
+ if ($this->userMgr->get($userId) !== null) {
+ $newUserId = $this->userMgr->get($userId)->getDisplayName();
}
return new JSONResponse(array(
'comment' => $commentBox,
@@ -597,23 +611,23 @@ class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param $searchTerm
- * @param $groups
- * @param $users
+ * @param string $searchTerm
+ * @param string $groups
+ * @param string $users
* @return array
*/
- public function search($searchTerm, $groups, $users) {
+ public function search($searchTerm, $groups, $users) {
return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param $searchTerm
- * @param $groups
+ * @param string $searchTerm
+ * @param string $groups
* @return array
*/
- public function searchForGroups($searchTerm, $groups) {
+ public function searchForGroups($searchTerm, $groups) {
$selectedGroups = json_decode($groups);
$groups = $this->groupManager->search($searchTerm);
$gids = array();
@@ -635,13 +649,13 @@ class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param $searchTerm
- * @param $users
+ * @param string $searchTerm
+ * @param string $users
* @return array
*/
- public function searchForUsers($searchTerm, $users) {
+ public function searchForUsers($searchTerm, $users) {
$selectedUsers = json_decode($users);
- Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
+ Util::writeLog('polls', print_r($selectedUsers, true), Util::ERROR);
$userNames = $this->userMgr->searchDisplayName($searchTerm);
$users = array();
$sUsers = array();
@@ -669,58 +683,36 @@ class PageController extends Controller {
/**
* @NoAdminRequired
* @NoCSRFRequired
- * @param $username
+ * @param string $username
* @return string
*/
- public function getDisplayName($username) {
- return $this->manager->get($username)->getDisplayName();
+ public function getDisplayName($username) {
+ return $this->userMgr->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
+ * @return \OCP\IGroup[]
*/
- public function getGroups() {
- // $this->requireLogin();
- if (class_exists('\OC_Group', true)) {
+ private function getGroups() {
+ if (class_exists('\OC_Group')) {
// Nextcloud <= 11, ownCloud
return \OC_Group::getUserGroups($this->userId);
}
// Nextcloud >= 12
- $groups = \OC::$server->getGroupManager()->getUserGroups(\OC::$server->getUserSession()->getUser());
+ $groups = $this->groupManager->getUserGroups(\OC::$server->getUserSession()->getUser());
return array_map(function ($group) {
return $group->getGID();
}, $groups);
}
/**
- * @param $poll
+ * @param Event $poll
* @return bool
*/
private function hasUserAccess($poll) {
$access = $poll->getAccess();
$owner = $poll->getOwner();
- if ($access === 'public') {
- return true;
- }
- if ($access === 'hidden') {
+ if ($access === 'public' || $access === 'hidden') {
return true;
}
if ($this->userId === null) {
@@ -732,7 +724,7 @@ class PageController extends Controller {
if ($owner === $this->userId) {
return true;
}
- Util::writeLog("polls", $this->userId, Util::ERROR);
+ Util::writeLog('polls', $this->userId, Util::ERROR);
$user_groups = $this->getGroups();
$arr = explode(';', $access);
foreach ($arr as $item) {
@@ -746,7 +738,7 @@ class PageController extends Controller {
} else {
if (strpos($item, 'user_') === 0) {
$usr = substr($item, 5);
- if ($usr === User::getUser()) {
+ if ($usr === $this->userId) {
return true;
}
}
diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php
index 28b5ae35..add8c4dc 100644
--- a/lib/Db/Comment.php
+++ b/lib/Db/Comment.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,8 +24,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getUserId()
* @method void setUserId(string $value)
@@ -35,9 +34,16 @@ use OCP\AppFramework\Db\Entity;
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Comment extends Entity {
- public $userId;
- public $dt;
- public $comment;
- public $pollId;
+class Comment extends Model {
+ protected $userId;
+ protected $dt;
+ protected $comment;
+ protected $pollId;
+
+ /**
+ * Comment constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ }
}
diff --git a/lib/Db/CommentMapper.php b/lib/Db/CommentMapper.php
index e2bdbcf1..6c116078 100644
--- a/lib/Db/CommentMapper.php
+++ b/lib/Db/CommentMapper.php
@@ -48,7 +48,7 @@ class CommentMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return Comment[]
@@ -59,7 +59,7 @@ class CommentMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
*/
public function deleteByPoll($pollId) {
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
diff --git a/lib/Db/Date.php b/lib/Db/Date.php
index d34a9a41..a4d9894d 100644
--- a/lib/Db/Date.php
+++ b/lib/Db/Date.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,15 +24,20 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
- * @method timestamp getDt()
- * @method void setDt(timestamp $value)
+ * @method string getDt()
+ * @method void setDt(string $value)
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Date extends Entity {
- public $dt;
- public $pollId;
+class Date extends Model {
+ protected $dt;
+ protected $pollId;
+
+ /**
+ * Date constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ }
}
diff --git a/lib/Db/DateMapper.php b/lib/Db/DateMapper.php
index 330dc0d8..07cec763 100644
--- a/lib/Db/DateMapper.php
+++ b/lib/Db/DateMapper.php
@@ -37,7 +37,7 @@ class DateMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return Date[]
@@ -48,7 +48,7 @@ class DateMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
*/
public function deleteByPoll($pollId) {
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
diff --git a/lib/Db/Event.php b/lib/Db/Event.php
index df4c1ca8..8a167495 100644
--- a/lib/Db/Event.php
+++ b/lib/Db/Event.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,8 +24,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method integer getType()
* @method void setType(integer $value)
@@ -34,12 +33,12 @@ use OCP\AppFramework\Db\Entity;
* @method void setDescription(string $value)
* @method string getOwner()
* @method void setOwner(string $value)
- * @method timestamp getCreated()
- * @method void setCreated(timestamp $value)
+ * @method string getCreated()
+ * @method void setCreated(string $value)
* @method string getAccess()
* @method void setAccess(string $value)
- * @method timestamp getExpire()
- * @method void setExpire(timestamp $value)
+ * @method string getExpire()
+ * @method void setExpire(string $value)
* @method string getHash()
* @method void setHash(string $value)
* @method integer getIsAnonymous()
@@ -47,15 +46,24 @@ use OCP\AppFramework\Db\Entity;
* @method integer getFullAnonymous()
* @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;
+class Event extends Model {
+ protected $type;
+ protected $title;
+ protected $description;
+ protected $owner;
+ protected $created;
+ protected $access;
+ protected $expire;
+ protected $hash;
+ protected $isAnonymous;
+ protected $fullAnonymous;
+
+ /**
+ * Event constructor.
+ */
+ public function __construct() {
+ $this->addType('type', 'integer');
+ $this->addType('isAnonymous', 'integer');
+ $this->addType('fullAnonymous', 'integer');
+ }
}
diff --git a/lib/Db/EventMapper.php b/lib/Db/EventMapper.php
index 44ed6a84..bb17be95 100644
--- a/lib/Db/EventMapper.php
+++ b/lib/Db/EventMapper.php
@@ -48,9 +48,11 @@ class EventMapper extends Mapper {
}
/**
- * @param $hash
+ * @param string $hash
* @param int $limit
* @param int $offset
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Event
*/
public function findByHash($hash, $limit = null, $offset = null) {
@@ -59,7 +61,7 @@ class EventMapper extends Mapper {
}
/**
- * @param $userId
+ * @param string $userId
* @param int $limit
* @param int $offset
* @return Event[]
diff --git a/lib/Db/Model.php b/lib/Db/Model.php
new file mode 100644
index 00000000..087f4842
--- /dev/null
+++ b/lib/Db/Model.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
+ *
+ * @author Kai Schröer <git@schroeer.co>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Db;
+
+use OCP\AppFramework\Db\Entity;
+
+abstract class Model extends Entity {
+ /**
+ * FactoryMuffin checks for the existence of setters with method_exists($obj, $attr) but that returns false.
+ * By overwriting the __set() magic method we can trigger the changed flag on $obj->attr assignment.
+ *
+ * @param $name
+ * @param $value
+ */
+ public function __set($name, $value) {
+ $this->setter($name, [$value]);
+ }
+}
diff --git a/lib/Db/Notification.php b/lib/Db/Notification.php
index eb5c2180..55ebbb79 100644
--- a/lib/Db/Notification.php
+++ b/lib/Db/Notification.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,15 +24,20 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getUserId()
* @method void setUserId(string $value)
- * @method string getPollId()
- * @method void setPollId(string $value)
+ * @method integer getPollId()
+ * @method void setPollId(integer $value)
*/
-class Notification extends Entity {
- public $userId;
- public $pollId;
+class Notification extends Model {
+ protected $userId;
+ protected $pollId;
+
+ /**
+ * Notification constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ }
}
diff --git a/lib/Db/NotificationMapper.php b/lib/Db/NotificationMapper.php
index c5ee3b38..f39451bb 100644
--- a/lib/Db/NotificationMapper.php
+++ b/lib/Db/NotificationMapper.php
@@ -67,7 +67,7 @@ class NotificationMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return Notification[]
@@ -78,9 +78,11 @@ class NotificationMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param string $userId
- * @return Notification if not found
+ * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
+ * @return Notification
*/
public function findByUserAndPoll($pollId, $userId) {
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
diff --git a/lib/Db/Participation.php b/lib/Db/Participation.php
index a8494c86..d22be610 100644
--- a/lib/Db/Participation.php
+++ b/lib/Db/Participation.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,11 +24,9 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
- * @method timestamp getDt()
- * @method void setDt(timestamp $value)
+ * @method string getDt()
+ * @method void setDt(string $value)
* @method string getUserId()
* @method void setUserId(string $value)
* @method integer getPollId()
@@ -35,9 +34,17 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class Participation extends Entity {
- public $dt;
- public $userId;
- public $pollId;
- public $type;
+class Participation extends Model {
+ protected $dt;
+ protected $userId;
+ protected $pollId;
+ protected $type;
+
+ /**
+ * Participation constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ $this->addType('type', 'integer');
+ }
}
diff --git a/lib/Db/ParticipationMapper.php b/lib/Db/ParticipationMapper.php
index dfb2a7c9..53d780e1 100644
--- a/lib/Db/ParticipationMapper.php
+++ b/lib/Db/ParticipationMapper.php
@@ -48,7 +48,7 @@ class ParticipationMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return Participation[]
@@ -59,7 +59,18 @@ class ParticipationMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return Participation[]
+ */
+ public function findParticipantsByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
+
+ /**
+ * @param int $pollId
*/
public function deleteByPoll($pollId) {
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
@@ -67,7 +78,7 @@ class ParticipationMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param string $userId
*/
public function deleteByPollAndUser($pollId, $userId) {
diff --git a/lib/Db/ParticipationText.php b/lib/Db/ParticipationText.php
index 6fd05cca..83ef4b52 100644
--- a/lib/Db/ParticipationText.php
+++ b/lib/Db/ParticipationText.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,8 +24,6 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method text getText()
* @method void setText(text $value)
@@ -35,9 +34,17 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class ParticipationText extends Entity {
- public $text;
- public $userId;
- public $pollId;
- public $type;
+class ParticipationText extends Model {
+ protected $text;
+ protected $userId;
+ protected $pollId;
+ protected $type;
+
+ /**
+ * ParticipationText constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ $this->addType('type', 'integer');
+ }
}
diff --git a/lib/Db/ParticipationTextMapper.php b/lib/Db/ParticipationTextMapper.php
index 28a4b127..23bc33d2 100644
--- a/lib/Db/ParticipationTextMapper.php
+++ b/lib/Db/ParticipationTextMapper.php
@@ -37,7 +37,7 @@ class ParticipationTextMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return ParticipationText[]
@@ -59,7 +59,18 @@ class ParticipationTextMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
+ * @param int $limit
+ * @param int $offset
+ * @return ParticipationText[]
+ */
+ public function findParticipantsByPoll($pollId, $limit = null, $offset = null) {
+ $sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
+ return $this->findEntities($sql, [$pollId], $limit, $offset);
+ }
+
+ /**
+ * @param int $pollId
*/
public function deleteByPoll($pollId) {
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
@@ -67,7 +78,7 @@ class ParticipationTextMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param string $userId
*/
public function deleteByPollAndUser($pollId, $userId) {
diff --git a/lib/Db/Text.php b/lib/Db/Text.php
index 792e4caf..9ef423c2 100644
--- a/lib/Db/Text.php
+++ b/lib/Db/Text.php
@@ -3,6 +3,7 @@
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
+ * @author Kai Schröer <git@schroeer.co>
*
* @license GNU AGPL version 3 or any later version
*
@@ -23,15 +24,20 @@
namespace OCA\Polls\Db;
-use OCP\AppFramework\Db\Entity;
-
/**
* @method string getText()
* @method void setText(string $value)
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Text extends Entity {
- public $text;
- public $pollId;
+class Text extends Model {
+ protected $text;
+ protected $pollId;
+
+ /**
+ * Text constructor.
+ */
+ public function __construct() {
+ $this->addType('pollId', 'integer');
+ }
}
diff --git a/lib/Db/TextMapper.php b/lib/Db/TextMapper.php
index 5c4df02d..de3923f0 100644
--- a/lib/Db/TextMapper.php
+++ b/lib/Db/TextMapper.php
@@ -37,7 +37,7 @@ class TextMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
* @param int $limit
* @param int $offset
* @return Text[]
@@ -48,7 +48,7 @@ class TextMapper extends Mapper {
}
/**
- * @param string $pollId
+ * @param int $pollId
*/
public function deleteByPoll($pollId) {
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';