Match NC style guide
This commit is contained in:
Родитель
0faa40a07a
Коммит
19ecdc08a3
|
@ -34,15 +34,13 @@ 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())
|
||||
{
|
||||
public function __construct(array $urlParams = array()) {
|
||||
parent::__construct('polls', $urlParams);
|
||||
|
||||
$container = $this->getContainer();
|
||||
|
@ -150,8 +148,7 @@ class Application extends App
|
|||
/**
|
||||
* 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');
|
||||
|
|
|
@ -38,6 +38,7 @@ use \OCA\Polls\Db\NotificationMapper;
|
|||
use \OCA\Polls\Db\ParticipationMapper;
|
||||
use \OCA\Polls\Db\ParticipationTextMapper;
|
||||
use \OCA\Polls\Db\TextMapper;
|
||||
use \OCP\AppFramework\Db\DoesNotExistException;
|
||||
use \OCP\IUserManager;
|
||||
use \OCP\IGroupManager;
|
||||
use \OCP\IAvatarManager;
|
||||
|
@ -45,14 +46,15 @@ use \OCP\ILogger;
|
|||
use \OCP\IL10N;
|
||||
use \OCP\IRequest;
|
||||
use \OCP\IURLGenerator;
|
||||
use OCP\Security\ISecureRandom;
|
||||
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;
|
||||
|
||||
class PageController extends Controller
|
||||
{
|
||||
class PageController extends Controller {
|
||||
|
||||
private $userId;
|
||||
private $commentMapper;
|
||||
|
@ -129,8 +131,7 @@ 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);
|
||||
|
@ -153,22 +154,21 @@ class PageController extends Controller
|
|||
* @param string $pollId
|
||||
* @param string $from
|
||||
*/
|
||||
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()) {
|
||||
$notifications = $this->notificationMapper->findAllByPoll($pollId);
|
||||
foreach ($notifications as $notification) {
|
||||
if ($from === $notification->getUserId()) {
|
||||
continue;
|
||||
}
|
||||
$email = \OC::$server->getConfig()->getUserValue($notif->getUserId(), 'settings', 'email');
|
||||
$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($notif->getUserId());
|
||||
$recUser = $this->userMgr->get($notification->getUserId());
|
||||
$sendUser = $this->userMgr->get($from);
|
||||
$rec = "";
|
||||
if ($recUser !== null) {
|
||||
|
@ -189,9 +189,9 @@ class PageController extends Controller
|
|||
|
||||
$msg .= "<br/><br/>";
|
||||
|
||||
$toname = $this->userMgr->get($notif->getUserId())->getDisplayName();
|
||||
$toname = $this->userMgr->get($notification->getUserId())->getDisplayName();
|
||||
$subject = $this->trans->t('ownCloud Polls - New Comment');
|
||||
$fromaddress = \OCP\Util::getDefaultEmailAddress('no-reply');
|
||||
$fromaddress = Util::getDefaultEmailAddress('no-reply');
|
||||
$fromname = $this->trans->t("ownCloud Polls") . ' (' . $from . ')';
|
||||
|
||||
try {
|
||||
|
@ -204,7 +204,7 @@ class PageController extends Controller
|
|||
$mailer->send($message);
|
||||
} catch (\Exception $e) {
|
||||
$message = 'error sending mail to: ' . $toname . ' (' . $email . ')';
|
||||
\OCP\Util::writeLog("polls", $message, \OCP\Util::ERROR);
|
||||
Util::writeLog("polls", $message, Util::ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -216,8 +216,7 @@ class PageController extends Controller
|
|||
* @param string $hash
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function gotoPoll($hash)
|
||||
{
|
||||
public function gotoPoll($hash) {
|
||||
$poll = $this->eventMapper->findByHash($hash);
|
||||
if ($poll->getType() == '0') {
|
||||
$dates = $this->dateMapper->findByPoll($poll->getId());
|
||||
|
@ -229,7 +228,7 @@ 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 (DoesNotExistException $e) {
|
||||
$notification = null;
|
||||
}
|
||||
if ($this->hasUserAccess($poll)) {
|
||||
|
@ -245,7 +244,7 @@ class PageController extends Controller
|
|||
'avatarManager' => $this->avatarManager
|
||||
]);
|
||||
} else {
|
||||
\OCP\User::checkLoggedIn();
|
||||
User::checkLoggedIn();
|
||||
return new TemplateResponse('polls', 'no.acc.tmpl', []);
|
||||
}
|
||||
}
|
||||
|
@ -256,8 +255,7 @@ class PageController extends Controller
|
|||
* @param string $pollId
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function deletePoll($pollId)
|
||||
{
|
||||
public function deletePoll($pollId) {
|
||||
$poll = new Event();
|
||||
$poll->setId($pollId);
|
||||
$this->eventMapper->delete($poll);
|
||||
|
@ -276,8 +274,7 @@ class PageController extends Controller
|
|||
* @param string $hash
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
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');
|
||||
|
@ -387,8 +384,7 @@ class PageController extends Controller
|
|||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function createPoll()
|
||||
{
|
||||
public function createPoll() {
|
||||
return new TemplateResponse('polls', 'create.tmpl',
|
||||
['userId' => $this->userId, 'userMgr' => $this->manager, 'urlGenerator' => $this->urlGenerator]);
|
||||
}
|
||||
|
@ -504,14 +500,13 @@ class PageController extends Controller
|
|||
* @param $changed
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
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 (DoesNotExistException $e) {
|
||||
//insert if not exist
|
||||
$not = new Notification();
|
||||
$not->setUserId($userId);
|
||||
|
@ -523,7 +518,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 (DoesNotExistException $e) {
|
||||
//doesn't exist in db, nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -571,8 +566,7 @@ class PageController extends Controller
|
|||
* @param $commentBox
|
||||
* @return JSONResponse
|
||||
*/
|
||||
public function insertComment($pollId, $userId, $commentBox)
|
||||
{
|
||||
public function insertComment($pollId, $userId, $commentBox) {
|
||||
$comment = new Comment();
|
||||
$comment->setPollId($pollId);
|
||||
$comment->setUserId($userId);
|
||||
|
@ -600,8 +594,7 @@ class PageController extends Controller
|
|||
* @param $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));
|
||||
}
|
||||
|
||||
|
@ -612,8 +605,7 @@ class PageController extends Controller
|
|||
* @param $groups
|
||||
* @return array
|
||||
*/
|
||||
public function searchForGroups($searchTerm, $groups)
|
||||
{
|
||||
public function searchForGroups($searchTerm, $groups) {
|
||||
$selectedGroups = json_decode($groups);
|
||||
$groups = $this->groupManager->search($searchTerm);
|
||||
$gids = array();
|
||||
|
@ -639,10 +631,9 @@ class PageController extends Controller
|
|||
* @param $users
|
||||
* @return array
|
||||
*/
|
||||
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);
|
||||
Util::writeLog("polls", print_r($selectedUsers, true), Util::ERROR);
|
||||
$userNames = $this->userMgr->searchDisplayName($searchTerm);
|
||||
$users = array();
|
||||
$sUsers = array();
|
||||
|
@ -671,18 +662,16 @@ class PageController extends Controller
|
|||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @param $username
|
||||
* @return
|
||||
* @return string
|
||||
*/
|
||||
public function getDisplayName($username)
|
||||
{
|
||||
public function getDisplayName($username) {
|
||||
return $this->manager->get($username)->getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Event[]
|
||||
*/
|
||||
public function getPollsForUser()
|
||||
{
|
||||
public function getPollsForUser() {
|
||||
return $this->eventMapper->findAllForUser($this->userId);
|
||||
}
|
||||
|
||||
|
@ -690,8 +679,7 @@ class PageController extends Controller
|
|||
* @param null $user
|
||||
* @return Event[]
|
||||
*/
|
||||
public function getPollsForUserWithInfo($user = null)
|
||||
{
|
||||
public function getPollsForUserWithInfo($user = null) {
|
||||
if ($user === null) {
|
||||
return $this->eventMapper->findAllForUserWithInfo($this->userId);
|
||||
} else {
|
||||
|
@ -702,8 +690,7 @@ class PageController extends Controller
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
public function getGroups() {
|
||||
// $this->requireLogin();
|
||||
if (class_exists('\OC_Group', true)) {
|
||||
// Nextcloud <= 11, ownCloud
|
||||
|
@ -720,8 +707,7 @@ class PageController extends Controller
|
|||
* @param $poll
|
||||
* @return bool
|
||||
*/
|
||||
private function hasUserAccess($poll)
|
||||
{
|
||||
private function hasUserAccess($poll) {
|
||||
$access = $poll->getAccess();
|
||||
$owner = $poll->getOwner();
|
||||
if ($access === 'public') {
|
||||
|
@ -739,7 +725,7 @@ class PageController extends Controller
|
|||
if ($owner === $this->userId) {
|
||||
return true;
|
||||
}
|
||||
\OCP\Util::writeLog("polls", $this->userId, \OCP\Util::ERROR);
|
||||
Util::writeLog("polls", $this->userId, Util::ERROR);
|
||||
$user_groups = $this->getGroups();
|
||||
$arr = explode(';', $access);
|
||||
foreach ($arr as $item) {
|
||||
|
@ -753,7 +739,7 @@ class PageController extends Controller
|
|||
} else {
|
||||
if (strpos($item, 'user_') === 0) {
|
||||
$usr = substr($item, 5);
|
||||
if ($usr === \OCP\User::getUser()) {
|
||||
if ($usr === User::getUser()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
*
|
||||
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
* @author Kai Schröer <kai@schroeer.co>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
|
@ -25,7 +25,6 @@ namespace OCA\Polls\Controller;
|
|||
|
||||
use \OCP\AppFramework\Controller;
|
||||
|
||||
class PollController extends Controller
|
||||
{
|
||||
class PollController extends Controller {
|
||||
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ 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;
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class CommentMapper extends Mapper
|
||||
{
|
||||
class CommentMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* CommentMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_comments', '\OCA\Polls\Db\Comment');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class CommentMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Comment[]
|
||||
*/
|
||||
public function findDistinctByUser($userId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findDistinctByUser($userId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
|
||||
return $this->findEntities($sql, [$userId], $limit, $offset);
|
||||
}
|
||||
|
@ -56,8 +53,7 @@ class CommentMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Comment[]
|
||||
*/
|
||||
public function findByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -65,8 +61,7 @@ class CommentMapper extends Mapper
|
|||
/**
|
||||
* @param string $pollId
|
||||
*/
|
||||
public function deleteByPoll($pollId)
|
||||
{
|
||||
public function deleteByPoll($pollId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
$this->execute($sql, [$pollId]);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@ 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;
|
||||
}
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class DateMapper extends Mapper
|
||||
{
|
||||
class DateMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* DateMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_dts', '\OCA\Polls\Db\Date');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class DateMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Date[]
|
||||
*/
|
||||
public function findByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findByPoll($pollId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
return $this->findEntities($sql, [$pollId], $limit, $offset);
|
||||
}
|
||||
|
@ -53,8 +50,7 @@ class DateMapper extends Mapper
|
|||
/**
|
||||
* @param string $pollId
|
||||
*/
|
||||
public function deleteByPoll($pollId)
|
||||
{
|
||||
public function deleteByPoll($pollId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
$this->execute($sql, [$pollId]);
|
||||
}
|
||||
|
|
|
@ -47,8 +47,7 @@ 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;
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class EventMapper extends Mapper
|
||||
{
|
||||
class EventMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* EventMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class EventMapper extends Mapper
|
|||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
* @return Event
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
|
||||
return $this->findEntity($sql, [$id]);
|
||||
}
|
||||
|
@ -56,8 +53,7 @@ class EventMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Event
|
||||
*/
|
||||
public function findByHash($hash, $limit = null, $offset = null)
|
||||
{
|
||||
public function findByHash($hash, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE hash = ?';
|
||||
return $this->findEntity($sql, [$hash], $limit, $offset);
|
||||
}
|
||||
|
@ -68,8 +64,7 @@ class EventMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Event[]
|
||||
*/
|
||||
public function findAllForUser($userId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findAllForUser($userId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE owner = ?';
|
||||
return $this->findEntities($sql, [$userId], $limit, $offset);
|
||||
}
|
||||
|
@ -80,8 +75,7 @@ class EventMapper extends Mapper
|
|||
* @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,
|
||||
|
|
|
@ -31,8 +31,7 @@ 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;
|
||||
}
|
||||
|
|
|
@ -26,11 +26,9 @@ 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');
|
||||
}
|
||||
|
||||
|
@ -40,8 +38,7 @@ class NotificationMapper extends Mapper
|
|||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
* @return Notification
|
||||
*/
|
||||
public function find($id)
|
||||
{
|
||||
public function find($id) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE id = ?';
|
||||
return $this->findEntity($sql, [$id]);
|
||||
}
|
||||
|
@ -54,8 +51,7 @@ class NotificationMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function findBetween($userId, $from, $until, $limit = null, $offset = null)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -65,8 +61,7 @@ class NotificationMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function findAll($limit = null, $offset = null)
|
||||
{
|
||||
public function findAll($limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName();
|
||||
return $this->findEntities($sql, [], $limit, $offset);
|
||||
}
|
||||
|
@ -77,8 +72,7 @@ class NotificationMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function findAllByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findAllByPoll($pollId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
return $this->findEntities($sql, [$pollId], $limit, $offset);
|
||||
}
|
||||
|
@ -88,8 +82,7 @@ class NotificationMapper extends Mapper
|
|||
* @param string $userId
|
||||
* @return Notification if not found
|
||||
*/
|
||||
public function findByUserAndPoll($pollId, $userId)
|
||||
{
|
||||
public function findByUserAndPoll($pollId, $userId) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
|
||||
return $this->findEntity($sql, [$pollId, $userId]);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ 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;
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class ParticipationMapper extends Mapper
|
||||
{
|
||||
class ParticipationMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* ParticipationMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_particip', '\OCA\Polls\Db\Participation');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class ParticipationMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Participation[]
|
||||
*/
|
||||
public function findDistinctByUser($userId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findDistinctByUser($userId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
|
||||
return $this->findEntities($sql, [$userId], $limit, $offset);
|
||||
}
|
||||
|
@ -56,8 +53,7 @@ class ParticipationMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Participation[]
|
||||
*/
|
||||
public function findByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findByPoll($pollId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
return $this->findEntities($sql, [$pollId], $limit, $offset);
|
||||
}
|
||||
|
@ -65,8 +61,7 @@ class ParticipationMapper extends Mapper
|
|||
/**
|
||||
* @param string $pollId
|
||||
*/
|
||||
public function deleteByPoll($pollId)
|
||||
{
|
||||
public function deleteByPoll($pollId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
$this->execute($sql, [$pollId]);
|
||||
}
|
||||
|
@ -75,8 +70,7 @@ class ParticipationMapper extends Mapper
|
|||
* @param string $pollId
|
||||
* @param string $userId
|
||||
*/
|
||||
public function deleteByPollAndUser($pollId, $userId)
|
||||
{
|
||||
public function deleteByPollAndUser($pollId, $userId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
|
||||
$this->execute($sql, [$pollId, $userId]);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,7 @@ 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;
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class ParticipationTextMapper extends Mapper
|
||||
{
|
||||
class ParticipationTextMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* ParticipationTextMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_particip_text', '\OCA\Polls\Db\ParticipationText');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class ParticipationTextMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return ParticipationText[]
|
||||
*/
|
||||
public function findByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findByPoll($pollId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
return $this->findEntities($sql, [$pollId], $limit, $offset);
|
||||
}
|
||||
|
@ -53,8 +50,7 @@ class ParticipationTextMapper extends Mapper
|
|||
/**
|
||||
* @param string $pollId
|
||||
*/
|
||||
public function deleteByPoll($pollId)
|
||||
{
|
||||
public function deleteByPoll($pollId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
$this->execute($sql, [$pollId]);
|
||||
}
|
||||
|
@ -63,8 +59,7 @@ class ParticipationTextMapper extends Mapper
|
|||
* @param string $pollId
|
||||
* @param string $userId
|
||||
*/
|
||||
public function deleteByPollAndUser($pollId, $userId)
|
||||
{
|
||||
public function deleteByPollAndUser($pollId, $userId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ? AND user_id = ?';
|
||||
$this->execute($sql, [$pollId, $userId]);
|
||||
}
|
||||
|
|
|
@ -31,8 +31,7 @@ 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;
|
||||
}
|
||||
|
|
|
@ -26,15 +26,13 @@ namespace OCA\Polls\Db;
|
|||
use OCP\AppFramework\Db\Mapper;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class TextMapper extends Mapper
|
||||
{
|
||||
class TextMapper extends Mapper {
|
||||
|
||||
/**
|
||||
* TextMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db)
|
||||
{
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_txts', '\OCA\Polls\Db\Text');
|
||||
}
|
||||
|
||||
|
@ -44,8 +42,7 @@ class TextMapper extends Mapper
|
|||
* @param int $offset
|
||||
* @return Text[]
|
||||
*/
|
||||
public function findByPoll($pollId, $limit = null, $offset = null)
|
||||
{
|
||||
public function findByPoll($pollId, $limit = null, $offset = null) {
|
||||
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
return $this->findEntities($sql, [$pollId], $limit, $offset);
|
||||
}
|
||||
|
@ -53,8 +50,7 @@ class TextMapper extends Mapper
|
|||
/**
|
||||
* @param string $pollId
|
||||
*/
|
||||
public function deleteByPoll($pollId)
|
||||
{
|
||||
public function deleteByPoll($pollId) {
|
||||
$sql = 'DELETE FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
|
||||
$this->execute($sql, [$pollId]);
|
||||
}
|
||||
|
|
|
@ -21,31 +21,23 @@
|
|||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Polls\Tests\Integration\Controller;
|
||||
namespace OCA\Polls\Tests\Integration;
|
||||
|
||||
use Test\TestCase;
|
||||
|
||||
use OCP\AppFramework\App;
|
||||
use \OCP\AppFramework\App;
|
||||
|
||||
/**
|
||||
* This test shows how to make a small Integration Test. Query your class
|
||||
* directly from the container, only pass in mocks if needed and run your tests
|
||||
* against the database
|
||||
*/
|
||||
class AppTest extends TestCase
|
||||
{
|
||||
class AppTest extends TestCase {
|
||||
|
||||
private $container;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$app = new App('polls');
|
||||
$this->container = $app->getContainer();
|
||||
}
|
||||
|
||||
public function testAppInstalled()
|
||||
{
|
||||
public function testAppInstalled() {
|
||||
$appManager = $this->container->query('OCP\App\IAppManager');
|
||||
$this->assertTrue($appManager->isInstalled('polls'));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
*
|
||||
* @author Kai Schröer <kai@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\Tests\Unit\Controller;
|
||||
|
||||
use OCA\Polls\Controller\PageController;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
|
||||
class PageControllerTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
private $controller;
|
||||
private $userId = 'john';
|
||||
|
||||
public function setUp() {
|
||||
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
|
||||
|
||||
$this->controller = new PageController(
|
||||
'polls', $request, $this->userId
|
||||
);
|
||||
}
|
||||
|
||||
public function testIndex() {
|
||||
$result = $this->controller->index();
|
||||
|
||||
$this->assertEquals('main.tmpl', $result->getTemplateName());
|
||||
$this->assertTrue($result instanceof TemplateResponse);
|
||||
}
|
||||
}
|
|
@ -21,4 +21,20 @@
|
|||
*
|
||||
*/
|
||||
|
||||
require_once __DIR__ . '/../../../tests/bootstrap.php';
|
||||
if (!defined('PHPUNIT_RUN')) {
|
||||
define('PHPUNIT_RUN', 1);
|
||||
}
|
||||
|
||||
require_once(__DIR__.'/../../../lib/base.php');
|
||||
|
||||
// Fix for "Autoload path not allowed: .../tests/lib/testcase.php"
|
||||
\OC::$loader->addValidRoot(OC::$SERVERROOT . '/tests');
|
||||
|
||||
// Fix for "Autoload path not allowed: .../polls/tests/testcase.php"
|
||||
\OC_App::loadApp('polls');
|
||||
|
||||
if (!class_exists('PHPUnit_Framework_TestCase')) {
|
||||
require_once('PHPUnit/Autoload.php');
|
||||
}
|
||||
|
||||
OC_Hook::clear();
|
||||
|
|
Загрузка…
Ссылка в новой задаче