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:
authorsplitt3r <splitt3r@users.noreply.github.com>2017-10-08 17:38:42 +0300
committersplitt3r <splitt3r@users.noreply.github.com>2017-10-08 17:38:42 +0300
commita5aad195d7359bd4ef7aac0295a44f19f7a94ea5 (patch)
treec270acc26e65f973195300918e8cf09b710b747d /lib
parent4b47fe4f06ae99c01771b6cb26af8f84b2f5b604 (diff)
Refactored db layer
Diffstat (limited to 'lib')
-rw-r--r--lib/AppInfo/Application.php195
-rw-r--r--lib/Controller/PageController.php236
-rw-r--r--lib/Controller/PollController.php3
-rw-r--r--lib/Db/Access.php3
-rw-r--r--lib/Db/AccessMapper.php24
-rw-r--r--lib/Db/Comment.php3
-rw-r--r--lib/Db/CommentMapper.php41
-rw-r--r--lib/Db/Date.php3
-rw-r--r--lib/Db/DateMapper.php34
-rw-r--r--lib/Db/Event.php3
-rw-r--r--lib/Db/EventMapper.php48
-rw-r--r--lib/Db/Notification.php3
-rw-r--r--lib/Db/NotificationMapper.php40
-rw-r--r--lib/Db/Participation.php3
-rw-r--r--lib/Db/ParticipationMapper.php46
-rw-r--r--lib/Db/ParticipationText.php3
-rw-r--r--lib/Db/ParticipationTextMapper.php50
-rw-r--r--lib/Db/Text.php3
-rw-r--r--lib/Db/TextMapper.php27
19 files changed, 453 insertions, 315 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php
index 0c660506..7adf7558 100644
--- a/lib/AppInfo/Application.php
+++ b/lib/AppInfo/Application.php
@@ -35,59 +35,61 @@ use \OCA\Polls\Db\ParticipationTextMapper;
use \OCA\Polls\Db\TextMapper;
use \OCA\Polls\Controller\PageController;
-class Application extends App {
+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('AccessMapper'),
- $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) {
+ 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('AccessMapper'),
+ $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();
- });
+ return $c->query('ServerContainer')->getUserManager();
+ });
$container->registerService('GroupManager', function ($c) {
/** @var SimpleContainer $c */
return $c->query('ServerContainer')->getGroupManager();
});
- $container->registerService('AvatarManager', function ($c) {
+ $container->registerService('AvatarManager', function ($c) {
/** @var SimpleContainer $c */
- return $c->query('ServerContainer')->getAvatarManager();
- });
+ return $c->query('ServerContainer')->getAvatarManager();
+ });
$container->registerService('Logger', function ($c) {
/** @var SimpleContainer $c */
@@ -98,67 +100,68 @@ class Application extends App {
return $c->query('ServerContainer')->getL10N($c->query('AppName'));
});
- $container->registerService('AccessMapper', function ($c) use ($server) {
- /** @var SimpleContainer $c */
- return new AccessMapper(
- $server->getDatabaseConnection()
- );
- });
-
- $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()
- );
- });
- }
+ $container->registerService('AccessMapper', function ($c) use ($server) {
+ /** @var SimpleContainer $c */
+ return new AccessMapper(
+ $server->getDatabaseConnection()
+ );
+ });
+
+ $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() {
+ public function registerNavigationEntry()
+ {
$container = $this->getContainer();
$container->query('OCP\INavigationManager')->add(function () use ($container) {
$urlGenerator = $container->query('OCP\IURLGenerator');
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php
index 408a01bb..76e468bd 100644
--- a/lib/Controller/PageController.php
+++ b/lib/Controller/PageController.php
@@ -52,7 +52,8 @@ use \OCP\AppFramework\Http\RedirectResponse;
use \OCP\AppFramework\Http\JSONResponse;
use \OCP\AppFramework\Controller;
-class PageController extends Controller {
+class PageController extends Controller
+{
private $userId;
private $accessMapper;
@@ -71,22 +72,25 @@ class PageController extends Controller {
private $userMgr;
private $groupManager;
- public function __construct($appName, IRequest $request,
- IUserManager $manager,
- IGroupManager $groupManager,
- IAvatarManager $avatarManager,
- ILogger $logger,
- IL10N $trans,
- IURLGenerator $urlGenerator,
- $userId,
- AccessMapper $accessMapper,
- CommentMapper $commentMapper,
- DateMapper $dateMapper,
- EventMapper $eventMapper,
- NotificationMapper $notificationMapper,
- ParticipationMapper $ParticipationMapper,
- ParticipationTextMapper $ParticipationTextMapper,
- TextMapper $textMapper) {
+ public function __construct(
+ $appName,
+ IRequest $request,
+ IUserManager $manager,
+ IGroupManager $groupManager,
+ IAvatarManager $avatarManager,
+ ILogger $logger,
+ IL10N $trans,
+ IURLGenerator $urlGenerator,
+ $userId,
+ AccessMapper $accessMapper,
+ CommentMapper $commentMapper,
+ DateMapper $dateMapper,
+ EventMapper $eventMapper,
+ NotificationMapper $notificationMapper,
+ ParticipationMapper $ParticipationMapper,
+ ParticipationTextMapper $ParticipationTextMapper,
+ TextMapper $textMapper
+ ) {
parent::__construct($appName, $request);
$this->manager = $manager;
$this->groupManager = $groupManager;
@@ -110,11 +114,19 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function index() {
+ public function index()
+ {
$polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
$comments = $this->commentMapper->findDistinctByUser($this->userId);
$partic = $this->participationMapper->findDistinctByUser($this->userId);
- $response = new TemplateResponse('polls', 'main.tmpl', ['polls' => $polls, 'comments' => $comments, 'participations' => $partic, 'userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
+ $response = new TemplateResponse('polls', 'main.tmpl', [
+ 'polls' => $polls,
+ 'comments' => $comments,
+ 'participations' => $partic,
+ '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);
@@ -122,32 +134,39 @@ class PageController extends Controller {
return $response;
}
- private function sendNotifications($pollId, $from) {
+ private function sendNotifications($pollId, $from)
+ {
$poll = $this->eventMapper->find($pollId);
$notifs = $this->notificationMapper->findAllByPoll($pollId);
foreach ($notifs as $notif) {
if ($from === $notif->getUserId()) {
- continue;
+ continue;
}
$email = \OC::$server->getConfig()->getUserValue($notif->getUserId(), 'settings', 'email');
if (strlen($email) === 0 || !isset($email)) {
- continue;
+ continue;
}
- $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll', array('hash' => $poll->getHash())));
+ $url = \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getURLGenerator()->linkToRoute('polls.page.goto_poll',
+ array('hash' => $poll->getHash())));
$recUser = $this->userMgr->get($notif->getUserId());
$sendUser = $this->userMgr->get($from);
$rec = "";
if ($recUser !== null) {
- $rec = $recUser->getDisplayName();
+ $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 = $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/>";
@@ -176,7 +195,8 @@ class PageController extends Controller {
* @NoCSRFRequired
* @PublicPage
*/
- public function gotoPoll($hash) {
+ public function gotoPoll($hash)
+ {
$poll = $this->eventMapper->findByHash($hash);
if ($poll->getType() == '0') {
$dates = $this->dateMapper->findByPoll($poll->getId());
@@ -188,11 +208,21 @@ class PageController extends Controller {
$comments = $this->commentMapper->findByPoll($poll->getId());
try {
$notification = $this->notificationMapper->findByUserAndPoll($poll->getId(), $this->userId);
- } catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
+ } catch (\OCP\AppFramework\Db\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]);
+ 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 {
\OCP\User::checkLoggedIn();
return new TemplateResponse('polls', 'no.acc.tmpl', []);
@@ -203,7 +233,8 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function deletePoll($pollId) {
+ public function deletePoll($pollId)
+ {
$poll = new Event();
$poll->setId($pollId);
$this->eventMapper->delete($poll);
@@ -220,24 +251,41 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function editPoll($hash) {
+ public function editPoll($hash)
+ {
$poll = $this->eventMapper->findByHash($hash);
if ($this->userId !== $poll->getOwner()) {
- return new TemplateResponse('polls', 'no.create.tmpl');
+ return new TemplateResponse('polls', 'no.create.tmpl');
}
if ($poll->getType() == '0') {
- $dates = $this->dateMapper->findByPoll($poll->getId());
+ $dates = $this->dateMapper->findByPoll($poll->getId());
} else {
- $dates = $this->textMapper->findByPoll($poll->getId());
+ $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]);
+ return new TemplateResponse('polls', 'create.tmpl', [
+ 'poll' => $poll,
+ 'dates' => $dates,
+ 'userId' => $this->userId,
+ 'userMgr' => $this->manager,
+ 'urlGenerator' => $this->urlGenerator
+ ]);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function updatePoll($pollId, $pollType, $pollTitle, $pollDesc, $userId, $chosenDates, $expireTs, $accessType, $accessValues) {
+ public function updatePoll(
+ $pollId,
+ $pollType,
+ $pollTitle,
+ $pollDesc,
+ $userId,
+ $chosenDates,
+ $expireTs,
+ $accessType,
+ $accessValues
+ ) {
$event = $this->eventMapper->find($pollId);
$event->setTitle(htmlspecialchars($pollTitle));
$event->setDescription(htmlspecialchars($pollDesc));
@@ -249,10 +297,10 @@ class PageController extends Controller {
$groups = array();
$users = array();
if ($accessValues->groups !== null) {
- $groups = $accessValues->groups;
+ $groups = $accessValues->groups;
}
if ($accessValues->users !== null) {
- $users = $accessValues->users;
+ $users = $accessValues->users;
}
$accessType = '';
foreach ($groups as $gid) {
@@ -270,7 +318,7 @@ class PageController extends Controller {
$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
+ $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);
@@ -304,26 +352,39 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function createPoll() {
- return new TemplateResponse('polls', 'create.tmpl', ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
+ public function createPoll()
+ {
+ return new TemplateResponse('polls', 'create.tmpl',
+ ['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function insertPoll($pollType, $pollTitle, $pollDesc, $userId, $chosenDates, $expireTs, $accessType, $accessValues, $isAnonymous, $hideNames) {
+ 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');
+ 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)) {
@@ -332,10 +393,10 @@ class PageController extends Controller {
$groups = array();
$users = array();
if ($accessValues->groups !== null) {
- $groups = $accessValues->groups;
+ $groups = $accessValues->groups;
}
if ($accessValues->users !== null) {
- $users = $accessValues->users;
+ $users = $accessValues->users;
}
$accessType = '';
foreach ($groups as $gid) {
@@ -353,7 +414,7 @@ class PageController extends Controller {
$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
+ $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);
@@ -390,13 +451,14 @@ class PageController extends Controller {
* @NoCSRFRequired
* @PublicPage
*/
- public function insertVote($pollId, $userId, $types, $dates, $notif, $changed) {
+ public function insertVote($pollId, $userId, $types, $dates, $notif, $changed)
+ {
if ($this->userId !== null) {
if ($notif === 'true') {
try {
//check if user already set notification for this poll
$this->notificationMapper->findByUserAndPoll($pollId, $userId);
- } catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
+ } catch (\OCP\AppFramework\Db\DoesNotExistException $e) {
//insert if not exist
$not = new Notification();
$not->setUserId($userId);
@@ -408,7 +470,7 @@ class PageController extends Controller {
//delete if entry is in db
$not = $this->notificationMapper->findByUserAndPoll($pollId, $userId);
$this->notificationMapper->delete($not);
- } catch(\OCP\AppFramework\Db\DoesNotExistException $e) {
+ } catch (\OCP\AppFramework\Db\DoesNotExistException $e) {
//doesn't exist in db, nothing to do
}
}
@@ -421,11 +483,11 @@ class PageController extends Controller {
$dates = json_decode($dates);
$types = json_decode($types);
if ($poll->getType() == '0') {
- $this->participationMapper->deleteByPollAndUser($pollId, $userId);
+ $this->participationMapper->deleteByPollAndUser($pollId, $userId);
} else {
- $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
+ $this->participationTextMapper->deleteByPollAndUser($pollId, $userId);
}
- for ($i=0; $i<count($dates); $i++) {
+ for ($i = 0; $i < count($dates); $i++) {
if ($poll->getType() == '0') {
$part = new Participation();
$part->setPollId($pollId);
@@ -455,7 +517,8 @@ class PageController extends Controller {
* @NoCSRFRequired
* @PublicPage
*/
- public function insertComment($pollId, $userId, $commentBox) {
+ public function insertComment($pollId, $userId, $commentBox)
+ {
$poll = $this->eventMapper->find($pollId);
$comment = new Comment();
$comment->setPollId($pollId);
@@ -471,14 +534,19 @@ class PageController extends Controller {
} else {
$newUserId = $userId;
}
- return new JSONResponse(array('comment' => $commentBox, 'date' => date('Y-m-d H:i:s'), 'userName' => $newUserId));
+ return new JSONResponse(array(
+ 'comment' => $commentBox,
+ 'date' => date('Y-m-d H:i:s'),
+ 'userName' => $newUserId
+ ));
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function search($searchTerm, $groups, $users) {
+ public function search($searchTerm, $groups, $users)
+ {
return array_merge($this->searchForGroups($searchTerm, $groups), $this->searchForUsers($searchTerm, $users));
}
@@ -486,7 +554,8 @@ class PageController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function searchForGroups($searchTerm, $groups) {
+ public function searchForGroups($searchTerm, $groups)
+ {
$selectedGroups = json_decode($groups);
$groups = $this->groupManager->search($searchTerm);
$gids = array();
@@ -503,13 +572,14 @@ class PageController extends Controller {
$gids[] = ['gid' => $g, 'isGroup' => true];
}
return $gids;
- }
+ }
- /**
+ /**
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function searchForUsers($searchTerm, $users) {
+ public function searchForUsers($searchTerm, $users)
+ {
$selectedUsers = json_decode($users);
\OCP\Util::writeLog("polls", print_r($selectedUsers, true), \OCP\Util::ERROR);
$userNames = $this->userMgr->searchDisplayName($searchTerm);
@@ -534,26 +604,33 @@ class PageController extends Controller {
}
}
return $users;
- }
+ }
- /**
+ /**
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function getDisplayName($username) {
- return $this->manager->get($username)->getDisplayName();
- }
+ public function getDisplayName($username)
+ {
+ return $this->manager->get($username)->getDisplayName();
+ }
- public function getPollsForUser() {
+ public function getPollsForUser()
+ {
return $this->eventMapper->findAllForUser($this->userId);
}
- public function getPollsForUserWithInfo($user = null) {
- if($user === null) return $this->eventMapper->findAllForUserWithInfo($this->userId);
- else return $this->eventMapper->findAllForUserWithInfo($user);
+ public function getPollsForUserWithInfo($user = null)
+ {
+ if ($user === null) {
+ return $this->eventMapper->findAllForUserWithInfo($this->userId);
+ } else {
+ return $this->eventMapper->findAllForUserWithInfo($user);
+ }
}
- public function getGroups() {
+ public function getGroups()
+ {
// $this->requireLogin();
if (class_exists('\OC_Group', true)) {
// Nextcloud <= 11, ownCloud
@@ -566,7 +643,8 @@ class PageController extends Controller {
}, $groups);
}
- private function hasUserAccess($poll) {
+ private function hasUserAccess($poll)
+ {
$access = $poll->getAccess();
$owner = $poll->getOwner();
if ($access === 'public') {
@@ -595,10 +673,12 @@ class PageController extends Controller {
return true;
}
}
- } else if (strpos($item, 'user_') === 0) {
- $usr = substr($item, 5);
- if ($usr === \OCP\User::getUser()) {
- return true;
+ } else {
+ if (strpos($item, 'user_') === 0) {
+ $usr = substr($item, 5);
+ if ($usr === \OCP\User::getUser()) {
+ return true;
+ }
}
}
}
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index 70fd9691..d2bc68d3 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -25,6 +25,7 @@ namespace OCA\Polls\Controller;
use \OCP\AppFramework\Controller;
-class PollController extends Controller {
+class PollController extends Controller
+{
}
diff --git a/lib/Db/Access.php b/lib/Db/Access.php
index 6456cf74..7eac1ead 100644
--- a/lib/Db/Access.php
+++ b/lib/Db/Access.php
@@ -31,7 +31,8 @@ use OCP\AppFramework\Db\Entity;
* @method string getAccessType()
* @method void setAccessType(string $value)
*/
-class Access extends Entity {
+class Access extends Entity
+{
public $pId;
public $accessType;
}
diff --git a/lib/Db/AccessMapper.php b/lib/Db/AccessMapper.php
index fa391214..0085a322 100644
--- a/lib/Db/AccessMapper.php
+++ b/lib/Db/AccessMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class AccessMapper extends Mapper {
+class AccessMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_access', '\OCA\Polls\Db\Access');
}
@@ -38,9 +40,9 @@ class AccessMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Favorite
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_access` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -52,10 +54,9 @@ class AccessMapper extends Mapper {
* @param int $offset
* @return Favorite[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_access` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -64,8 +65,9 @@ class AccessMapper extends Mapper {
* @param int $offset
* @return Favorite[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_access`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
}
diff --git a/lib/Db/Comment.php b/lib/Db/Comment.php
index fa0481f1..e67d8b42 100644
--- a/lib/Db/Comment.php
+++ b/lib/Db/Comment.php
@@ -35,7 +35,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Comment extends Entity {
+class Comment extends Entity
+{
public $userId;
public $dt;
public $comment;
diff --git a/lib/Db/CommentMapper.php b/lib/Db/CommentMapper.php
index 10cad506..7ba389b4 100644
--- a/lib/Db/CommentMapper.php
+++ b/lib/Db/CommentMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class CommentMapper extends Mapper {
+class CommentMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment');
}
@@ -38,9 +40,9 @@ class CommentMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Comment
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_comments` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -52,10 +54,9 @@ class CommentMapper extends Mapper {
* @param int $offset
* @return Comment[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_comments` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -64,8 +65,9 @@ class CommentMapper extends Mapper {
* @param int $offset
* @return Comment[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_comments`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
@@ -75,27 +77,30 @@ class CommentMapper extends Mapper {
* @param int $offset
* @return Comment[]
*/
- public function findDistinctByUser($userId, $limit=null, $offset=null) {
- $sql = 'SELECT DISTINCT * FROM `*PREFIX*polls_comments` WHERE user_id=?';
+ 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 string $pollId
* @param int $limit
* @param int $offset
* @return Comment[]
*/
- public function findByPoll($pollId, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_comments` WHERE poll_id=? ORDER BY Dt DESC';
+ 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 `*PREFIX*polls_comments` WHERE poll_id=?';
+ 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..af66cb35 100644
--- a/lib/Db/Date.php
+++ b/lib/Db/Date.php
@@ -31,7 +31,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Date extends Entity {
+class Date extends Entity
+{
public $dt;
public $pollId;
}
diff --git a/lib/Db/DateMapper.php b/lib/Db/DateMapper.php
index 9a16ebda..df1f340c 100644
--- a/lib/Db/DateMapper.php
+++ b/lib/Db/DateMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class DateMapper extends Mapper {
+class DateMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date');
}
@@ -38,9 +40,9 @@ class DateMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Date
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_dts` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -52,10 +54,9 @@ class DateMapper extends Mapper {
* @param int $offset
* @return Date[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_dts` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -64,8 +65,9 @@ class DateMapper extends Mapper {
* @param int $offset
* @return Date[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_dts`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
@@ -75,16 +77,18 @@ class DateMapper extends Mapper {
* @param int $offset
* @return Date[]
*/
- public function findByPoll($pollId, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_dts` WHERE poll_id=?';
+ 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 `*PREFIX*polls_dts` WHERE poll_id=?';
+ 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..6dc74594 100644
--- a/lib/Db/Event.php
+++ b/lib/Db/Event.php
@@ -47,7 +47,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getFullAnonymous()
* @method void setFullAnonymous(integer $value)
*/
-class Event extends Entity {
+class Event extends Entity
+{
public $type;
public $title;
public $description;
diff --git a/lib/Db/EventMapper.php b/lib/Db/EventMapper.php
index 862bc475..a00182a6 100644
--- a/lib/Db/EventMapper.php
+++ b/lib/Db/EventMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class EventMapper extends Mapper {
+class EventMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event');
}
@@ -38,9 +40,9 @@ class EventMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Event
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_events` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -52,10 +54,9 @@ class EventMapper extends Mapper {
* @param int $offset
* @return Event[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_events` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -64,37 +65,44 @@ class EventMapper extends Mapper {
* @param int $offset
* @return Event[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_events`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
/**
+ * @param $hash
* @param int $limit
* @param int $offset
* @return Event
*/
- public function findByHash($hash, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_events` WHERE `hash`=?';
+ 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 `*PREFIX*polls_events` WHERE `owner`=?';
+ 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) {
+ public function findAllForUserWithInfo($userId, $limit = null, $offset = null)
+ {
$sql = 'SELECT DISTINCT *PREFIX*polls_events.id,
*PREFIX*polls_events.hash,
*PREFIX*polls_events.type,
@@ -112,13 +120,13 @@ class EventMapper extends Mapper {
LEFT JOIN *PREFIX*polls_comments
ON *PREFIX*polls_events.id = *PREFIX*polls_comments.id
WHERE
- (*PREFIX*polls_events.access =? and *PREFIX*polls_events.owner =?)
+ (*PREFIX*polls_events.access = ? AND *PREFIX*polls_events.owner = ?)
OR
- *PREFIX*polls_events.access !=?
+ *PREFIX*polls_events.access != ?
OR
- *PREFIX*polls_particip.user_id =?
+ *PREFIX*polls_particip.user_id = ?
OR
- *PREFIX*polls_comments.user_id =?
+ *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..b17049e2 100644
--- a/lib/Db/Notification.php
+++ b/lib/Db/Notification.php
@@ -31,7 +31,8 @@ use OCP\AppFramework\Db\Entity;
* @method string getPollId()
* @method void setPollId(string $value)
*/
-class Notification extends Entity {
+class Notification extends Entity
+{
public $userId;
public $pollId;
}
diff --git a/lib/Db/NotificationMapper.php b/lib/Db/NotificationMapper.php
index 95978f0f..b1d92acf 100644
--- a/lib/Db/NotificationMapper.php
+++ b/lib/Db/NotificationMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class NotificationMapper extends Mapper {
+class NotificationMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_notif', '\OCA\Polls\Db\Notification');
}
@@ -38,9 +40,9 @@ class NotificationMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Notification
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_notif` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -52,10 +54,9 @@ class NotificationMapper extends Mapper {
* @param int $offset
* @return Notification[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_notif` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -64,27 +65,32 @@ class NotificationMapper extends Mapper {
* @param int $offset
* @return Notification[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_notif`';
+ 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 `*PREFIX*polls_notif` WHERE `poll_id`=?';
+ public function findAllByPoll($pollId, $limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
return $this->findEntities($sql, [$pollId], $limit, $offset);
}
/**
- * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
- * @return Notification
+ * @param string $pollId
+ * @param string $userId
+ * @return Notification if not found
*/
- public function findByUserAndPoll($pollId, $userId) {
- $sql = 'SELECT * FROM `*PREFIX*polls_notif` WHERE `poll_id`=? AND `user_id`=?';
+ 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..98ab985c 100644
--- a/lib/Db/Participation.php
+++ b/lib/Db/Participation.php
@@ -35,7 +35,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class Participation extends Entity {
+class Participation extends Entity
+{
public $dt;
public $userId;
public $pollId;
diff --git a/lib/Db/ParticipationMapper.php b/lib/Db/ParticipationMapper.php
index 054e1d90..69bc10a5 100644
--- a/lib/Db/ParticipationMapper.php
+++ b/lib/Db/ParticipationMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class ParticipationMapper extends Mapper {
+class ParticipationMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_particip', '\OCA\Polls\Db\Participation');
}
@@ -38,14 +40,15 @@ class ParticipationMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Participation
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
- public function deleteByPollAndUser($pollId, $userId) {
- $sql = 'DELETE FROM `*PREFIX*polls_particip` WHERE poll_id=? AND user_id=?';
+ public function deleteByPollAndUser($pollId, $userId)
+ {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
$this->execute($sql, [$pollId, $userId]);
}
@@ -57,10 +60,9 @@ class ParticipationMapper extends Mapper {
* @param int $offset
* @return Participation[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -69,8 +71,9 @@ class ParticipationMapper extends Mapper {
* @param int $offset
* @return Participation[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
@@ -80,27 +83,30 @@ class ParticipationMapper extends Mapper {
* @param int $offset
* @return Participation[]
*/
- public function findDistinctByUser($userId, $limit=null, $offset=null) {
- $sql = 'SELECT DISTINCT * FROM `*PREFIX*polls_particip` WHERE user_id=?';
+ 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 string $pollId
* @param int $limit
* @param int $offset
* @return Participation[]
*/
- public function findByPoll($pollId, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip` WHERE poll_id=?';
+ 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 `*PREFIX*polls_particip` WHERE poll_id=?';
+ public function deleteByPoll($pollId)
+ {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
$this->execute($sql, [$pollId]);
}
}
diff --git a/lib/Db/ParticipationText.php b/lib/Db/ParticipationText.php
index 56ac2415..4777122d 100644
--- a/lib/Db/ParticipationText.php
+++ b/lib/Db/ParticipationText.php
@@ -35,7 +35,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getType()
* @method void setType(integer $value)
*/
-class ParticipationText extends Entity {
+class ParticipationText extends Entity
+{
public $text;
public $userId;
public $pollId;
diff --git a/lib/Db/ParticipationTextMapper.php b/lib/Db/ParticipationTextMapper.php
index efa30820..fdf59ece 100644
--- a/lib/Db/ParticipationTextMapper.php
+++ b/lib/Db/ParticipationTextMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class ParticipationTextMapper extends Mapper {
+class ParticipationTextMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText');
}
@@ -38,14 +40,19 @@ class ParticipationTextMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return ParticipationText
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip_text` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
- public function deleteByPollAndUser($pollId, $userId) {
- $sql = 'DELETE FROM `*PREFIX*polls_particip_text` WHERE poll_id=? AND user_id=?';
+ /**
+ * @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]);
}
@@ -57,10 +64,9 @@ class ParticipationTextMapper extends Mapper {
* @param int $offset
* @return ParticipationText[]
*/
- public function findBetween($userId, $from, $until, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip_text` '.
- 'WHERE `userId` = ?'.
- 'AND `timestamp` BETWEEN ? and ?';
+ 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);
}
@@ -69,8 +75,9 @@ class ParticipationTextMapper extends Mapper {
* @param int $offset
* @return ParticipationText[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip_text`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
@@ -80,27 +87,30 @@ class ParticipationTextMapper extends Mapper {
* @param int $offset
* @return ParticipationText[]
*/
- public function findDistinctByUser($userId, $limit=null, $offset=null) {
- $sql = 'SELECT DISTINCT * FROM `*PREFIX*polls_particip_text` WHERE user_id=?';
+ 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 string $pollId
* @param int $limit
* @param int $offset
* @return ParticipationText[]
*/
- public function findByPoll($pollId, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_particip_text` WHERE poll_id=?';
+ 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 `*PREFIX*polls_particip_text` WHERE poll_id=?';
+ public function deleteByPoll($pollId)
+ {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
$this->execute($sql, [$pollId]);
}
}
diff --git a/lib/Db/Text.php b/lib/Db/Text.php
index e98c168b..7dc4ee6b 100644
--- a/lib/Db/Text.php
+++ b/lib/Db/Text.php
@@ -31,7 +31,8 @@ use OCP\AppFramework\Db\Entity;
* @method integer getPollId()
* @method void setPollId(integer $value)
*/
-class Text extends Entity {
+class Text extends Entity
+{
public $text;
public $pollId;
}
diff --git a/lib/Db/TextMapper.php b/lib/Db/TextMapper.php
index dde08890..8fb64158 100644
--- a/lib/Db/TextMapper.php
+++ b/lib/Db/TextMapper.php
@@ -26,9 +26,11 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
-class TextMapper extends Mapper {
+class TextMapper extends Mapper
+{
- public function __construct(IDBConnection $db) {
+ public function __construct(IDBConnection $db)
+ {
parent::__construct($db, 'polls_txts', '\OCA\Polls\Db\Text');
}
@@ -38,9 +40,9 @@ class TextMapper extends Mapper {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Text
*/
- public function find($id) {
- $sql = 'SELECT * FROM `*PREFIX*polls_txts` '.
- 'WHERE `id` = ?';
+ public function find($id)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
return $this->findEntity($sql, [$id]);
}
@@ -49,8 +51,9 @@ class TextMapper extends Mapper {
* @param int $offset
* @return Text[]
*/
- public function findAll($limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_txts`';
+ public function findAll($limit = null, $offset = null)
+ {
+ $sql = 'SELECT * FROM ' . $this->getTableName();
return $this->findEntities($sql, [], $limit, $offset);
}
@@ -60,16 +63,18 @@ class TextMapper extends Mapper {
* @param int $offset
* @return Text[]
*/
- public function findByPoll($pollId, $limit=null, $offset=null) {
- $sql = 'SELECT * FROM `*PREFIX*polls_txts` WHERE poll_id=?';
+ 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 `*PREFIX*polls_txts` WHERE poll_id=?';
+ public function deleteByPoll($pollId)
+ {
+ $sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
$this->execute($sql, [$pollId]);
}
}