renamed event to poll in the entire project (#695)
* renamed event to poll in the entire project * Migration polls_event to polls_polls * use timestamp
This commit is contained in:
Родитель
527ecb8125
Коммит
217492e10f
|
@ -48,10 +48,10 @@ return [
|
|||
['name' => 'option#remove', 'url' => '/option/remove/', 'verb' => 'POST'],
|
||||
['name' => 'option#getByToken', 'url' => '/options/get/s/{token}', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'event#list', 'url' => '/events/get/', 'verb' => 'GET'],
|
||||
['name' => 'event#get', 'url' => '/event/get/{pollId}', 'verb' => 'GET'],
|
||||
['name' => 'event#write', 'url' => '/event/write/', 'verb' => 'POST'],
|
||||
['name' => 'event#getByToken', 'url' => '/event/get/s/{token}', 'verb' => 'GET'],
|
||||
['name' => 'poll#list', 'url' => '/polls/get/', 'verb' => 'GET'],
|
||||
['name' => 'poll#get', 'url' => '/poll/get/{pollId}', 'verb' => 'GET'],
|
||||
['name' => 'poll#write', 'url' => '/poll/write/', 'verb' => 'POST'],
|
||||
['name' => 'poll#getByToken', 'url' => '/poll/get/s/{token}', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'share#getShares', 'url' => '/shares/get/{pollId}', 'verb' => 'GET'],
|
||||
['name' => 'share#write', 'url' => '/share/write/', 'verb' => 'POST'],
|
||||
|
|
|
@ -26,14 +26,14 @@ namespace OCA\Polls\AppInfo;
|
|||
// use OCA\Polls\Controller\PageController;
|
||||
// use OCA\Polls\Controller\ApiController;
|
||||
// use OCA\Polls\Controller\CommentController;
|
||||
// use OCA\Polls\Controller\EventController;
|
||||
// use OCA\Polls\Controller\PollController;
|
||||
// use OCA\Polls\Controller\NotificationController;
|
||||
// use OCA\Polls\Controller\OptionController;
|
||||
// use OCA\Polls\Controller\VoteController;
|
||||
// use OCA\Polls\Controller\ShareController;
|
||||
// use OCA\Polls\Db\CommentMapper;
|
||||
// use OCA\Polls\Db\OptionMapper;
|
||||
// use OCA\Polls\Db\EventMapper;
|
||||
// use OCA\Polls\Db\PollMapper;
|
||||
// use OCA\Polls\Db\NotificationMapper;
|
||||
// use OCA\Polls\Db\VoteMapper;
|
||||
// use OCA\Polls\Db\ShareMapper;
|
||||
|
|
|
@ -35,8 +35,8 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
|
||||
use OCP\IGroupManager;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Comment;
|
||||
use OCA\Polls\Db\CommentMapper;
|
||||
use OCA\Polls\Service\AnonymizeService;
|
||||
|
@ -51,7 +51,7 @@ class CommentController extends Controller {
|
|||
private $logger;
|
||||
|
||||
private $groupManager;
|
||||
private $eventMapper;
|
||||
private $pollMapper;
|
||||
private $anonymizer;
|
||||
private $acl;
|
||||
|
||||
|
@ -61,7 +61,7 @@ class CommentController extends Controller {
|
|||
* @param $UserId
|
||||
* @param CommentMapper $mapper
|
||||
* @param IGroupManager $groupManager
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param AnonymizeService $anonymizer
|
||||
* @param Acl $acl
|
||||
*/
|
||||
|
@ -73,7 +73,7 @@ class CommentController extends Controller {
|
|||
ILogger $logger,
|
||||
CommentMapper $mapper,
|
||||
IGroupManager $groupManager,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
AnonymizeService $anonymizer,
|
||||
Acl $acl
|
||||
) {
|
||||
|
@ -82,7 +82,7 @@ class CommentController extends Controller {
|
|||
$this->mapper = $mapper;
|
||||
$this->logger = $logger;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->anonymizer = $anonymizer;
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
use OCP\IGroupManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Option;
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Service\LogService;
|
||||
|
@ -47,7 +47,7 @@ class OptionController extends Controller {
|
|||
private $mapper;
|
||||
|
||||
private $groupManager;
|
||||
private $eventMapper;
|
||||
private $pollMapper;
|
||||
private $logService;
|
||||
private $acl;
|
||||
|
||||
|
@ -58,7 +58,7 @@ class OptionController extends Controller {
|
|||
* @param IRequest $request
|
||||
* @param OptionMapper $mapper
|
||||
* @param IGroupManager $groupManager
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param LogService $logService
|
||||
* @param Acl $acl
|
||||
*/
|
||||
|
@ -69,7 +69,7 @@ class OptionController extends Controller {
|
|||
IRequest $request,
|
||||
OptionMapper $mapper,
|
||||
IGroupManager $groupManager,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
LogService $logService,
|
||||
Acl $acl
|
||||
) {
|
||||
|
@ -77,7 +77,7 @@ class OptionController extends Controller {
|
|||
$this->userId = $UserId;
|
||||
$this->mapper = $mapper;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->logService = $logService;
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
@ -97,28 +97,7 @@ class OptionController extends Controller {
|
|||
$this->acl->setPollId($pollId);
|
||||
}
|
||||
|
||||
$options = $this->mapper->findByPoll($pollId);
|
||||
|
||||
foreach ($options as &$Option) {
|
||||
// Fix for empty timestamps on date polls
|
||||
// generate timestamp from pollOptionText
|
||||
if ($Option->getTimestamp() > 0) {
|
||||
$ts = $Option->getTimestamp();
|
||||
} else if (strtotime($Option->getPollOptionText())) {
|
||||
$ts = strtotime($Option->getPollOptionText());
|
||||
} else {
|
||||
$ts = 0;
|
||||
}
|
||||
|
||||
|
||||
$Option = (object) [
|
||||
'id' => $Option->getId(),
|
||||
'pollId' => $Option->getPollId(),
|
||||
'pollOptionText' => htmlspecialchars_decode($Option->getPollOptionText()),
|
||||
'timestamp' => $ts
|
||||
];
|
||||
}
|
||||
return new DataResponse($options, Http::STATUS_OK);
|
||||
return new DataResponse((array) $this->mapper->findByPoll($pollId), Http::STATUS_OK);
|
||||
|
||||
} catch (DoesNotExistException $e) {
|
||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
||||
|
@ -140,6 +119,7 @@ class OptionController extends Controller {
|
|||
try {
|
||||
$this->acl->setToken($token);
|
||||
return $this->get($this->acl->getPollId());
|
||||
return new DataResponse((array) $this->get($this->acl->getPollId()), Http::STATUS_OK);
|
||||
|
||||
} catch (DoesNotExistException $e) {
|
||||
return new DataResponse($e, Http::STATUS_NOT_FOUND);
|
||||
|
@ -155,7 +135,7 @@ class OptionController extends Controller {
|
|||
public function add($option) {
|
||||
|
||||
try {
|
||||
$Event = $this->eventMapper->find($option['pollId']);
|
||||
$Poll = $this->pollMapper->find($option['pollId']);
|
||||
$this->acl->setPollId($option['pollId']);
|
||||
|
||||
if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) {
|
||||
|
|
|
@ -37,22 +37,22 @@ use OCP\IUser;
|
|||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Service\EventService;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Service\PollService;
|
||||
use OCA\Polls\Service\LogService;
|
||||
use OCA\Polls\Service\MailService;
|
||||
use OCA\Polls\Model\Acl;
|
||||
|
||||
class EventController extends Controller {
|
||||
class PollController extends Controller {
|
||||
|
||||
private $userId;
|
||||
private $mapper;
|
||||
private $logger;
|
||||
private $groupManager;
|
||||
private $userManager;
|
||||
private $eventService;
|
||||
private $event;
|
||||
private $pollService;
|
||||
private $poll;
|
||||
private $logService;
|
||||
private $MailService;
|
||||
private $acl;
|
||||
|
@ -63,10 +63,10 @@ class EventController extends Controller {
|
|||
* @param $userId
|
||||
* @param IRequest $request
|
||||
* @param ILogger $logger
|
||||
* @param EventMapper $mapper
|
||||
* @param PollMapper $mapper
|
||||
* @param IGroupManager $groupManager
|
||||
* @param IUserManager $userManager
|
||||
* @param EventService $eventService
|
||||
* @param PollService $pollService
|
||||
* @param LogService $logService
|
||||
* @param MailService $mailService
|
||||
* @param Acl $acl
|
||||
|
@ -77,11 +77,11 @@ class EventController extends Controller {
|
|||
$userId,
|
||||
IRequest $request,
|
||||
ILogger $logger,
|
||||
EventMapper $mapper,
|
||||
Event $event,
|
||||
PollMapper $mapper,
|
||||
Poll $poll,
|
||||
IGroupManager $groupManager,
|
||||
IUserManager $userManager,
|
||||
EventService $eventService,
|
||||
PollService $pollService,
|
||||
LogService $logService,
|
||||
MailService $mailService,
|
||||
Acl $acl
|
||||
|
@ -92,8 +92,8 @@ class EventController extends Controller {
|
|||
$this->logger = $logger;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userManager = $userManager;
|
||||
$this->eventService = $eventService;
|
||||
$this->event = $event;
|
||||
$this->pollService = $pollService;
|
||||
$this->poll = $poll;
|
||||
$this->logService = $logService;
|
||||
$this->mailService = $mailService;
|
||||
$this->acl = $acl;
|
||||
|
@ -103,26 +103,22 @@ class EventController extends Controller {
|
|||
* Get all polls
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
* @return DataResponse
|
||||
*/
|
||||
|
||||
public function list() {
|
||||
$events = [];
|
||||
$polls = [];
|
||||
// TODO: Remove this, because it's just for easy testing purposes
|
||||
// $this->mailService->sendNotifications();
|
||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
||||
try {
|
||||
|
||||
$events = array_filter($this->mapper->findAll(), function($item) {
|
||||
if ($this->acl->setPollId($item->getId())->getAllowView()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return new DataResponse($events, Http::STATUS_OK);
|
||||
$polls = array_values(array_filter($this->mapper->findAll(), function($item) {
|
||||
return $this->acl->setPollId($item->getId())->getAllowView();
|
||||
}));
|
||||
return new DataResponse($polls, Http::STATUS_OK);
|
||||
} catch (DoesNotExistException $e) {
|
||||
$events = [];
|
||||
$polls = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,39 +138,23 @@ class EventController extends Controller {
|
|||
$this->acl->setPollId($pollId);
|
||||
}
|
||||
|
||||
$this->event = $this->mapper->find($pollId);
|
||||
|
||||
if ($this->event->getType() == 0) {
|
||||
$pollType = 'datePoll';
|
||||
} else {
|
||||
$pollType = 'textPoll';
|
||||
}
|
||||
$this->poll = $this->mapper->find($pollId);
|
||||
// if ($this->poll->getType() == 0) {
|
||||
// $pollType = 'datePoll';
|
||||
// } else {
|
||||
// $pollType = 'textPoll';
|
||||
// }
|
||||
|
||||
// TODO: add migration for this
|
||||
if ($this->event->getAccess() === 'public' || $this->event->getAccess() === 'registered') {
|
||||
$this->event->setAccess('public');
|
||||
} else {
|
||||
$this->event->setAccess('hidden');
|
||||
}
|
||||
// if ($this->poll->getAccess() === 'public' || $this->poll->getAccess() === 'registered') {
|
||||
// $this->poll->setAccess('public');
|
||||
// } else {
|
||||
// $this->poll->setAccess('hidden');
|
||||
// }
|
||||
|
||||
return new DataResponse((object) [
|
||||
'id' => $this->event->getId(),
|
||||
'type' => $pollType,
|
||||
'title' => $this->event->getTitle(),
|
||||
'description' => $this->event->getDescription(),
|
||||
'owner' => $this->event->getOwner(),
|
||||
'created' => $this->event->getCreated(),
|
||||
'access' => $this->event->getAccess(),
|
||||
'expire' => $this->event->getExpire(),
|
||||
'expiration' => $this->event->getExpiration(),
|
||||
'isAnonymous' => boolval($this->event->getIsAnonymous()),
|
||||
'fullAnonymous' => boolval($this->event->getFullAnonymous()),
|
||||
'allowMaybe' => boolval($this->event->getAllowMaybe()),
|
||||
'voteLimit' => $this->event->getVoteLimit(),
|
||||
'showResults' => $this->event->getShowResults(),
|
||||
'deleted' => boolval($this->event->getDeleted()),
|
||||
'deleteDate' => $this->event->getDeleteDate()
|
||||
],
|
||||
return new DataResponse((object)
|
||||
$this->poll
|
||||
,
|
||||
Http::STATUS_OK);
|
||||
|
||||
} catch (DoesNotExistException $e) {
|
||||
|
@ -206,16 +186,16 @@ class EventController extends Controller {
|
|||
/**
|
||||
* Write poll (create/update)
|
||||
* @NoAdminRequired
|
||||
* @param Array $event
|
||||
* @param Array $poll
|
||||
* @return DataResponse
|
||||
*/
|
||||
|
||||
public function write($event) {
|
||||
public function write($poll) {
|
||||
|
||||
try {
|
||||
// Find existing poll
|
||||
$this->event = $this->mapper->find($event['id']);
|
||||
$this->acl->setPollId($this->event->getId());
|
||||
$this->poll = $this->mapper->find($poll['id']);
|
||||
$this->acl->setPollId($this->poll->getId());
|
||||
|
||||
if (!$this->acl->getAllowEdit()) {
|
||||
$this->logger->alert('Unauthorized write attempt from user ' . $this->userId);
|
||||
|
@ -224,55 +204,37 @@ class EventController extends Controller {
|
|||
|
||||
$logMessageId = 'updatePoll';
|
||||
|
||||
if (boolval($this->event->getDeleted()) !== boolval($event['deleted'])) {
|
||||
if ($event['deleted']) {
|
||||
$logMessageId = 'deletePoll';
|
||||
$this->event->setDeleteDate(date('Y-m-d'));
|
||||
} else {
|
||||
$logMessageId = 'restorePoll';
|
||||
$this->event->setDeleteDate('0');
|
||||
}
|
||||
$this->event->setDeleted($event['deleted']);
|
||||
}
|
||||
$this->event->setDeleted($event['deleted']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->event = new Event();
|
||||
|
||||
$this->poll = new Poll();
|
||||
|
||||
$this->poll->setType($poll['type']);
|
||||
$this->poll->setOwner($this->userId);
|
||||
$this->poll->setCreated(time());
|
||||
$this->acl->setPollId(0);
|
||||
|
||||
if ($event['type'] === 'datePoll') {
|
||||
$this->event->setType(0);
|
||||
} elseif ($event['type'] === 'textPoll') {
|
||||
$this->event->setType(1);
|
||||
} else {
|
||||
$this->event->setType($event['type']);
|
||||
}
|
||||
|
||||
$this->event->setOwner($this->userId);
|
||||
$this->event->setCreated(date('Y-m-d H:i:s',time()));
|
||||
|
||||
} finally {
|
||||
$this->event->setTitle($event['title']);
|
||||
$this->event->setDescription($event['description']);
|
||||
|
||||
$this->event->setAccess($event['access']);
|
||||
$this->event->setExpiration($event['expiration']);
|
||||
$this->event->setExpire(date('Y-m-d H:i:s', strtotime($event['expire'])));
|
||||
$this->event->setIsAnonymous(intval($event['isAnonymous']));
|
||||
$this->event->setFullAnonymous(intval($event['fullAnonymous']));
|
||||
$this->event->setAllowMaybe(intval($event['allowMaybe']));
|
||||
$this->event->setVoteLimit(intval($event['voteLimit']));
|
||||
$this->event->setShowResults($event['showResults']);
|
||||
$this->poll->setTitle($poll['title']);
|
||||
$this->poll->setDescription($poll['description']);
|
||||
$this->poll->setAccess($poll['access']);
|
||||
$this->poll->setExpire($poll['expire']);
|
||||
$this->poll->setAnonymous(intval($poll['anonymous']));
|
||||
$this->poll->setFullAnonymous(intval($poll['fullAnonymous']));
|
||||
$this->poll->setAllowMaybe(intval($poll['allowMaybe']));
|
||||
$this->poll->setVoteLimit(intval($poll['voteLimit']));
|
||||
$this->poll->setSettings(json_encode($poll));
|
||||
$this->poll->setOptions($poll['options']);
|
||||
$this->poll->setShowResults($poll['showResults']);
|
||||
$this->poll->setDeleted($poll['deleted']);
|
||||
$this->poll->setAdminAccess($poll['adminAccess']);
|
||||
|
||||
if ($this->acl->getPollId() > 0) {
|
||||
$this->mapper->update($this->event);
|
||||
$this->logService->setLog($this->event->getId(), $logMessageId);
|
||||
$this->mapper->update($this->poll);
|
||||
$this->logService->setLog($this->poll->getId(), $logMessageId);
|
||||
} else {
|
||||
$this->mapper->insert($this->event);
|
||||
$this->logService->setLog($this->event->getId(), 'addPoll');
|
||||
$this->mapper->insert($this->poll);
|
||||
$this->logService->setLog($this->poll->getId(), 'addPoll');
|
||||
}
|
||||
$this->event = $this->get($this->event->getId());
|
||||
return new DataResponse($this->event, Http::STATUS_OK);
|
||||
return new DataResponse($this->poll, Http::STATUS_OK);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,10 +35,10 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\Poll;
|
||||
|
||||
use OCA\Polls\Model\Acl;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Service\MailService;
|
||||
|
@ -52,7 +52,7 @@ class ShareController extends Controller {
|
|||
private $mapper;
|
||||
private $userId;
|
||||
|
||||
private $eventMapper;
|
||||
private $pollMapper;
|
||||
private $systemController;
|
||||
private $mailService;
|
||||
|
||||
|
@ -63,7 +63,7 @@ class ShareController extends Controller {
|
|||
* @param IRequest $request
|
||||
* @param ILogger $logger
|
||||
* @param ShareMapper $mapper
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param SystemController $systemController
|
||||
* @param MailService $mailService
|
||||
* @param Acl $acl
|
||||
|
@ -74,7 +74,7 @@ class ShareController extends Controller {
|
|||
IRequest $request,
|
||||
ILogger $logger,
|
||||
ShareMapper $mapper,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
SystemController $systemController,
|
||||
MailService $mailService,
|
||||
Acl $acl
|
||||
|
@ -83,7 +83,7 @@ class ShareController extends Controller {
|
|||
$this->logger = $logger;
|
||||
$this->userId = $userId;
|
||||
$this->mapper = $mapper;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->systemController = $systemController;
|
||||
$this->mailService = $mailService;
|
||||
$this->acl = $acl;
|
||||
|
|
|
@ -35,8 +35,8 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
|
||||
use OCP\IGroupManager;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Vote;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Db\Share;
|
||||
|
@ -51,7 +51,7 @@ class VoteController extends Controller {
|
|||
private $logger;
|
||||
private $mapper;
|
||||
private $groupManager;
|
||||
private $eventMapper;
|
||||
private $pollMapper;
|
||||
private $shareMapper;
|
||||
private $anonymizer;
|
||||
private $logService;
|
||||
|
@ -65,7 +65,7 @@ class VoteController extends Controller {
|
|||
* @param ILogger $logger
|
||||
* @param VoteMapper $mapper
|
||||
* @param IGroupManager $groupManager
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param ShareMapper $shareMapper
|
||||
* @param AnonymizeService $anonymizer
|
||||
* @param LogService $logService
|
||||
|
@ -78,7 +78,7 @@ class VoteController extends Controller {
|
|||
ILogger $logger,
|
||||
VoteMapper $mapper,
|
||||
IGroupManager $groupManager,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
ShareMapper $shareMapper,
|
||||
AnonymizeService $anonymizer,
|
||||
LogService $logService,
|
||||
|
@ -89,7 +89,7 @@ class VoteController extends Controller {
|
|||
$this->mapper = $mapper;
|
||||
$this->logger = $logger;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->anonymizer = $anonymizer;
|
||||
$this->logService = $logService;
|
||||
|
|
|
@ -30,27 +30,52 @@ use JsonSerializable;
|
|||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
/**
|
||||
* @method integer getId()
|
||||
* @method void setId(integer $value)
|
||||
* @method integer getPollId()
|
||||
* @method void setPollId(integer $value)
|
||||
* @method string getUserId()
|
||||
* @method void setUserId(string $value)
|
||||
* @method string getDt()
|
||||
* @method void setDt(string $value)
|
||||
* @method string getComment()
|
||||
* @method void setComment(string $value)
|
||||
* @method integer getPollId()
|
||||
* @method void setPollId(integer $value)
|
||||
*/
|
||||
class Comment extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var string $userId */
|
||||
protected $userId;
|
||||
|
||||
/** @var string $dt */
|
||||
protected $dt;
|
||||
|
||||
/** @var int $timestamp */
|
||||
protected $timestamp;
|
||||
|
||||
/** @var string $comment */
|
||||
protected $comment;
|
||||
|
||||
public function jsonSerialize() {
|
||||
|
||||
// too lazy for a migration
|
||||
// use timestamp if is set,
|
||||
// otherwise use dt and convert to timestamp
|
||||
|
||||
if (intval($this->timestamp) > 0) {
|
||||
$timestamp = $this->timestamp;
|
||||
} else {
|
||||
$timestamp = strtotime($this->dt);
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'pollId' => $this->pollId,
|
||||
'id' => intval($this->id),
|
||||
'pollId' => intval($this->pollId),
|
||||
'userId' => $this->userId,
|
||||
'dt' => $this->dt,
|
||||
'timestamp' => intval($timestamp),
|
||||
'comment' => $this->comment
|
||||
];
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setPollId(integer $value)
|
||||
* @method integer getCreated()
|
||||
* @method void setCreated(integer $value)
|
||||
* @method integer getProcessed()
|
||||
* @method void setProcessed(integer $value)
|
||||
* @method integer getUserId()
|
||||
* @method void setUserId(string $value)
|
||||
* @method string getDisplayName()
|
||||
|
@ -43,20 +45,34 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setMessage(string $value)
|
||||
*/
|
||||
class Log extends Entity implements JsonSerializable {
|
||||
protected $created;
|
||||
protected $processed;
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var int $created */
|
||||
protected $created;
|
||||
|
||||
/** @var int $processed */
|
||||
protected $processed;
|
||||
|
||||
/** @var string $userId */
|
||||
protected $userId;
|
||||
|
||||
/** @var string $displayName */
|
||||
protected $displayName;
|
||||
|
||||
/** @var string $messageId */
|
||||
protected $messageId;
|
||||
|
||||
/** @var string $message */
|
||||
protected $message;
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'created' => $this->created,
|
||||
'processed' => $this->processed,
|
||||
'pollId' => $this->pollId,
|
||||
'id' => intval($this->id),
|
||||
'pollId' => intval($this->pollId),
|
||||
'created' => intval($this->created),
|
||||
'processed' => intval($this->processed),
|
||||
'userId' => $this->userId,
|
||||
'displayName' => $this->displayName,
|
||||
'message_id' => $this->messageId,
|
||||
|
|
|
@ -30,6 +30,8 @@ use JsonSerializable;
|
|||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
/**
|
||||
* @method integer getId()
|
||||
* @method void setId(integer $value)
|
||||
* @method integer getPollId()
|
||||
* @method void setPollId(integer $value)
|
||||
* @method string getPollOptionText()
|
||||
|
@ -38,17 +40,30 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setTimestamp(integer $value)
|
||||
*/
|
||||
class Option extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var string $pollOptionText */
|
||||
protected $pollOptionText;
|
||||
|
||||
/** @var int $timestamp */
|
||||
protected $timestamp;
|
||||
|
||||
public function jsonSerialize() {
|
||||
if (intval($this->timestamp) > 0) {
|
||||
$timestamp = $this->timestamp;
|
||||
} elseif (strtotime($this->pollOptionText)) {
|
||||
$timestamp = strtotime($this->pollOptionText);
|
||||
} else {
|
||||
$timestamp = 0;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'pollId' => $this->pollId,
|
||||
'pollOptionText' => $this->pollOptionText,
|
||||
'timestamp' => $this->timestamp
|
||||
'id' => intval($this->id),
|
||||
'pollId' => intval($this->pollId),
|
||||
'pollOptionText' => htmlspecialchars_decode($this->pollOptionText),
|
||||
'timestamp' => intval($timestamp)
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ use OCP\AppFramework\Db\Entity;
|
|||
|
||||
/**
|
||||
* @method integer getType()
|
||||
* @method void setType(integer $value)
|
||||
* @method void setType(string $value)
|
||||
* @method string getTitle()
|
||||
* @method void setTitle(string $value)
|
||||
* @method string getDescription()
|
||||
|
@ -39,64 +39,99 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method string getOwner()
|
||||
* @method void setOwner(string $value)
|
||||
* @method string getCreated()
|
||||
* @method void setCreated(string $value)
|
||||
* @method void setCreated(integer $value)
|
||||
* @method string getExpire()
|
||||
* @method void setExpire(integer $value)
|
||||
* @method integer getDeleted()
|
||||
* @method void setDeleted(integer $value)
|
||||
* @method string getAccess()
|
||||
* @method void setAccess(string $value)
|
||||
* @method string getExpire()
|
||||
* @method void setExpire(string $value)
|
||||
* @method string getExpiration()
|
||||
* @method void setExpiration(string $value)
|
||||
* @method integer getIsAnonymous()
|
||||
* @method void setIsAnonymous(integer $value)
|
||||
* @method integer getAnonymous()
|
||||
* @method void setAnonymous(integer $value)
|
||||
* @method integer getFullAnonymous()
|
||||
* @method void setFullAnonymous(integer $value)
|
||||
* @method integer getAllowMaybe()
|
||||
* @method void setAllowMaybe(integer $value)
|
||||
* @method integer getShowResults()
|
||||
* @method void setShowResults(integer $value)
|
||||
* @method integer getOptions()
|
||||
* @method void setOptions(string $value)
|
||||
* @method integer getSettings()
|
||||
* @method void setSettings(string $value)
|
||||
* @method integer getVoteLimit()
|
||||
* @method void setVoteLimit(integer $value)
|
||||
* @method integer getDeleted()
|
||||
* @method void setDeleted(integer $value)
|
||||
* @method integer getDeleteDate()
|
||||
* @method void setDeleteDate(string $value)
|
||||
* @method integer getShowResults()
|
||||
* @method void setShowResults(string $value)
|
||||
* @method integer getAdminAccess()
|
||||
* @method void setAdminAccess(integer $value)
|
||||
*/
|
||||
class Event extends Entity implements JsonSerializable {
|
||||
class Poll extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var string $type */
|
||||
protected $type;
|
||||
|
||||
/** @var string $title */
|
||||
protected $title;
|
||||
|
||||
/** @var string $description */
|
||||
protected $description;
|
||||
|
||||
/** @var string $owner */
|
||||
protected $owner;
|
||||
|
||||
/** @var int $created */
|
||||
protected $created;
|
||||
protected $access;
|
||||
protected $expiration;
|
||||
|
||||
/** @var int $expire */
|
||||
protected $expire;
|
||||
protected $isAnonymous;
|
||||
protected $fullAnonymous;
|
||||
protected $allowMaybe;
|
||||
protected $voteLimit;
|
||||
protected $showResults;
|
||||
|
||||
/** @var int $deleted */
|
||||
protected $deleted;
|
||||
protected $deleteDate;
|
||||
protected $hash;
|
||||
|
||||
/** @var string $access */
|
||||
protected $access;
|
||||
|
||||
/** @var int $anonymous */
|
||||
protected $anonymous;
|
||||
|
||||
/** @var int $fullAnonymous */
|
||||
protected $fullAnonymous;
|
||||
|
||||
/** @var int $allowMaybe */
|
||||
protected $allowMaybe;
|
||||
|
||||
/** @var string $options */
|
||||
protected $options;
|
||||
|
||||
/** @var string $settings*/
|
||||
protected $settings;
|
||||
|
||||
/** @var int $voteLimit*/
|
||||
protected $voteLimit;
|
||||
|
||||
/** @var string $showResults */
|
||||
protected $showResults;
|
||||
|
||||
/** @var int $adminAccess*/
|
||||
protected $adminAccess;
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'id' => intval($this->id),
|
||||
'type' => $this->type,
|
||||
'title' => $this->title,
|
||||
'description' => $this->description,
|
||||
'owner' => $this->owner,
|
||||
'created' => $this->created,
|
||||
'created' => intval($this->created),
|
||||
'expire' => intval($this->expire),
|
||||
'deleted' => intval($this->deleted),
|
||||
'access' => $this->access,
|
||||
'expire' => $this->expire,
|
||||
'expiration' => $this->expiration,
|
||||
'isAnonymous' => boolval($this->isAnonymous),
|
||||
'fullAnonymous' => boolval($this->fullAnonymous),
|
||||
'allowMaybe' => boolval($this->allowMaybe),
|
||||
'voteLimit' => $this->voteLimit,
|
||||
'anonymous' => intval($this->anonymous),
|
||||
'fullAnonymous' => intval($this->fullAnonymous),
|
||||
'allowMaybe' => intval($this->allowMaybe),
|
||||
'options' => $this->options,
|
||||
'settings' => $this->settings,
|
||||
'voteLimit' => intval($this->voteLimit),
|
||||
'showResults' => $this->showResults,
|
||||
'deleted' => boolval($this->deleted),
|
||||
'deleteDate' => $this->deleteDate
|
||||
'adminAccess' => $this->adminAccess
|
||||
];
|
||||
}
|
||||
}
|
|
@ -29,21 +29,21 @@ use OCP\IDBConnection;
|
|||
use OCP\AppFramework\Db\QBMapper;
|
||||
use \OCP\AppFramework\Db\DoesNotExistException;
|
||||
|
||||
class EventMapper extends QBMapper {
|
||||
class PollMapper extends QBMapper {
|
||||
|
||||
/**
|
||||
* EventMapper constructor.
|
||||
* PollMapper constructor.
|
||||
* @param IDBConnection $db
|
||||
*/
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'polls_events', '\OCA\Polls\Db\Event');
|
||||
parent::__construct($db, 'polls_polls', '\OCA\Polls\Db\Poll');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
* @return Event
|
||||
* @return Poll
|
||||
*/
|
||||
public function find($id) {
|
||||
$qb = $this->db->getQueryBuilder();
|
|
@ -29,34 +29,50 @@ use OCP\AppFramework\Db\Entity;
|
|||
|
||||
/**
|
||||
* @method string getId()
|
||||
* @method void setId(int $value)
|
||||
* @method void setId(integer $value)
|
||||
* @method string getToken()
|
||||
* @method void setToken(string $value)
|
||||
* @method string getType()
|
||||
* @method void setType(string $value)
|
||||
* @method integer getPollId()
|
||||
* @method void setPollId(int $value)
|
||||
* @method void setPollId(integer $value)
|
||||
* @method string getUserId()
|
||||
* @method void setUserId(string $value)
|
||||
* @method string getUserEmail()
|
||||
* @method void setUserEmail(string $value)
|
||||
* @method string getUser()
|
||||
* @method void setUser(string $value)
|
||||
*/
|
||||
class Share extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var string $token */
|
||||
protected $token;
|
||||
|
||||
/** @var string $type */
|
||||
protected $type;
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var string $userId */
|
||||
protected $userId;
|
||||
|
||||
/** @var string $userEmail */
|
||||
protected $userEmail;
|
||||
|
||||
/** @var string $user */
|
||||
protected $user;
|
||||
|
||||
public function jsonSerialize() {
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'id' => intval($this->id),
|
||||
'token' => $this->token,
|
||||
'type' => $this->type,
|
||||
'pollId' => $this->pollId,
|
||||
'pollId' => intval($this->pollId),
|
||||
'userId' => $this->userId,
|
||||
'userEmail' => $this->userEmail
|
||||
'userEmail' => $this->userEmail,
|
||||
'user' => $this->user
|
||||
];
|
||||
|
||||
}
|
||||
|
|
|
@ -29,20 +29,26 @@ use JsonSerializable;
|
|||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
/**
|
||||
* @method string getUserId()
|
||||
* @method void setUserId(string $value)
|
||||
* @method integer getId()
|
||||
* @method void setId(integer $value)
|
||||
* @method integer getPollId()
|
||||
* @method void setPollId(integer $value)
|
||||
* @method string getUserId()
|
||||
* @method void setUserId(string $value)
|
||||
*/
|
||||
class Subscription extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var string $userId */
|
||||
protected $userId;
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'pollId' => $this->pollId,
|
||||
'userId' => $this->userId,
|
||||
'id' => intval($this->id),
|
||||
'pollId' => intval($this->pollId),
|
||||
'userId' => $this->userId
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,28 @@ use OCP\AppFramework\Db\Entity;
|
|||
* @method void setVoteAnswer(string $value)
|
||||
*/
|
||||
class Vote extends Entity implements JsonSerializable {
|
||||
|
||||
/** @var int $pollId */
|
||||
protected $pollId;
|
||||
|
||||
/** @var string $userId */
|
||||
protected $userId;
|
||||
|
||||
/** @var int $voteOptionId */
|
||||
protected $voteOptionId;
|
||||
|
||||
/** @var string $voteOptionText */
|
||||
protected $voteOptionText;
|
||||
|
||||
/** @var string $voteAnswer */
|
||||
protected $voteAnswer;
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'pollId' => $this->pollId,
|
||||
'id' => intval($this->id),
|
||||
'pollId' => intval($this->pollId),
|
||||
'userId' => $this->userId,
|
||||
'voteOptionId' => $this->voteOptionId,
|
||||
'voteOptionId' => intval($this->voteOptionId),
|
||||
'voteOptionText' => $this->voteOptionText,
|
||||
'voteAnswer' => $this->voteAnswer
|
||||
];
|
||||
|
|
|
@ -66,40 +66,101 @@ class Version0010Date20191227063812 extends SimpleMigrationStep {
|
|||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if ($schema->hasTable('polls_events')) {
|
||||
$table = $schema->getTable('polls_events');
|
||||
if (!$table->hasColumn('expiration')) {
|
||||
$table->addColumn('expiration', Type::BOOLEAN, [
|
||||
if ($schema->hasTable('polls_comments')) {
|
||||
$table = $schema->getTable('polls_comments');
|
||||
if (!$table->hasColumn('timestamp')) {
|
||||
$table->addColumn('timestamp', Type::INTEGER, [
|
||||
'length' => 11,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
}
|
||||
if (!$table->hasColumn('deleted')) {
|
||||
$table->addColumn('deleted', Type::BOOLEAN, [
|
||||
'notnull' => false,
|
||||
'default' => 0
|
||||
]);
|
||||
}
|
||||
if (!$table->hasColumn('delete_date')) {
|
||||
$table->addColumn('delete_date', Type::DATETIME, [
|
||||
'notnull' => false
|
||||
]);
|
||||
}
|
||||
if (!$table->hasColumn('vote_limit')) {
|
||||
$table->addColumn('vote_limit', Type::INTEGER, [
|
||||
'notnull' => false,
|
||||
'default' => 0
|
||||
]);
|
||||
}
|
||||
if (!$table->hasColumn('show_results')) {
|
||||
$table->addColumn('show_results', Type::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 64,
|
||||
'default' => 'always'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$schema->hasTable('polls_polls')) {
|
||||
$table = $schema->createTable('polls_polls');
|
||||
$table->addColumn('id', Type::INTEGER, [
|
||||
'autoincrement' => true,
|
||||
'length' => 11,
|
||||
'notnull' => true
|
||||
]);
|
||||
$table->addColumn('type', Type::STRING, [
|
||||
'length' => 64,
|
||||
'notnull' => true,
|
||||
'default' => 'datePoll'
|
||||
]);
|
||||
$table->addColumn('title', Type::STRING, [
|
||||
'length' => 128,
|
||||
'notnull' => true
|
||||
]);
|
||||
$table->addColumn('description', Type::STRING, [
|
||||
'length' => 1024,
|
||||
'notnull' => true
|
||||
]);
|
||||
$table->addColumn('owner', Type::STRING, [
|
||||
'length' => 64,
|
||||
'notnull' => true
|
||||
]);
|
||||
$table->addColumn('created', Type::INTEGER, [
|
||||
'length' => 11,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
$table->addColumn('expire', Type::INTEGER, [
|
||||
'length' => 11,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
$table->addColumn('deleted', Type::INTEGER, [
|
||||
'length' => 11,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
$table->addColumn('access', Type::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 1024,
|
||||
'default' => 'hidden'
|
||||
]);
|
||||
$table->addColumn('anonymous', Type::INTEGER, [
|
||||
'length' => 8,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
$table->addColumn('full_anonymous', Type::INTEGER, [
|
||||
'notnull' => true,
|
||||
'default' => 0,
|
||||
]);
|
||||
$table->addColumn('allow_maybe', Type::INTEGER, [
|
||||
'notnull' => true,
|
||||
'default' => 1
|
||||
]);
|
||||
$table->addColumn('options', Type::TEXT, [
|
||||
'notnull' => true,
|
||||
'default' => ''
|
||||
]);
|
||||
$table->addColumn('settings', Type::TEXT, [
|
||||
'notnull' => true,
|
||||
'default' => ''
|
||||
]);
|
||||
$table->addColumn('vote_limit', Type::INTEGER, [
|
||||
'length' => 11,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
$table->addColumn('show_results', Type::STRING, [
|
||||
'length' => 64,
|
||||
'notnull' => true,
|
||||
'default' => 'always'
|
||||
]);
|
||||
$table->addColumn('admin_access', Type::INTEGER, [
|
||||
'length' => 8,
|
||||
'notnull' => true,
|
||||
'default' => 0
|
||||
]);
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
}
|
||||
|
||||
if (!$schema->hasTable('polls_share')) {
|
||||
$table = $schema->createTable('polls_share');
|
||||
$table->addColumn('id', Type::INTEGER, [
|
||||
|
@ -112,18 +173,22 @@ class Version0010Date20191227063812 extends SimpleMigrationStep {
|
|||
]);
|
||||
$table->addColumn('type', Type::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 128,
|
||||
'length' => 64
|
||||
]);
|
||||
$table->addColumn('poll_id', Type::INTEGER, [
|
||||
'notnull' => true
|
||||
]);
|
||||
$table->addColumn('user_id', Type::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 64,
|
||||
'length' => 64
|
||||
]);
|
||||
$table->addColumn('user_email', Type::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 254,
|
||||
'length' => 254
|
||||
]);
|
||||
$table->addColumn('user', Type::TEXT, [
|
||||
'notnull' => true,
|
||||
'default' => ''
|
||||
]);
|
||||
$table->setPrimaryKey(['id']);
|
||||
}
|
||||
|
@ -179,26 +244,86 @@ class Version0010Date20191227063812 extends SimpleMigrationStep {
|
|||
/** @var ISchemaWrapper $schema */
|
||||
$schema = $schemaClosure();
|
||||
|
||||
if ($schema->hasTable('polls_events')) {
|
||||
$this->setExpiration();
|
||||
if ($schema->hasTable('polls_polls')) {
|
||||
$this->migrateEvents();
|
||||
}
|
||||
|
||||
if ($schema->hasTable('polls_share')) {
|
||||
$this->copyTokens();
|
||||
// $this->copyInvitationTokens();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function resolveAccess($access) {
|
||||
if ($access === 'public') {
|
||||
return 'public';
|
||||
} else {
|
||||
return 'hidden';
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveOptions($maybe) {
|
||||
if ($maybe) {
|
||||
return json_encode(['yes', 'no', 'maybe']);
|
||||
} else {
|
||||
return json_encode(['yes', 'no']);
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveType($type) {
|
||||
if ($type) {
|
||||
return 'textPoll';
|
||||
} else {
|
||||
return 'datePoll';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set expiration if expire is filled
|
||||
*/
|
||||
protected function setExpiration() {
|
||||
* Copy public tokens
|
||||
*/
|
||||
protected function migrateEvents() {
|
||||
$insert = $this->connection->getQueryBuilder();
|
||||
$insert
|
||||
->insert('polls_polls')
|
||||
->values([
|
||||
'id' => $insert->createParameter('id'),
|
||||
'type' => $insert->createParameter('type'),
|
||||
'title' => $insert->createParameter('title'),
|
||||
'description' => $insert->createParameter('description'),
|
||||
'owner' => $insert->createParameter('owner'),
|
||||
'created' => $insert->createParameter('created'),
|
||||
'expire' => $insert->createParameter('expire'),
|
||||
'deleted' => $insert->createParameter('deleted'),
|
||||
'access' => $insert->createParameter('access'),
|
||||
'anonymous' => $insert->createParameter('anonymous'),
|
||||
'full_anonymous' => $insert->createParameter('full_anonymous'),
|
||||
'allow_maybe' => $insert->createParameter('allow_maybe'),
|
||||
'options' => $insert->createParameter('options'),
|
||||
]);
|
||||
$query = $this->connection->getQueryBuilder();
|
||||
$query->select('*')->from('polls_events');
|
||||
$result = $query->execute();
|
||||
|
||||
$update = $this->connection->getQueryBuilder();
|
||||
$update->update('polls_events')
|
||||
->set('expiration', $update->createNamedParameter(true))
|
||||
->where('expire IS NOT NULL');
|
||||
$result = $update->execute();
|
||||
while ($row = $result->fetch()) {
|
||||
$insert
|
||||
->setParameter('id', $row['id'])
|
||||
->setParameter('type', $this->resolveType($row['type']))
|
||||
->setParameter('title', $row['title'])
|
||||
->setParameter('description', $row['description'])
|
||||
->setParameter('owner', $row['owner'])
|
||||
->setParameter('created', intval(strtotime($row['created'])))
|
||||
->setParameter('expire', intval(strtotime($row['expire'])))
|
||||
->setParameter('deleted', intval(strtotime($row['deleted'])))
|
||||
->setParameter('access', $this->resolveAccess($row['access']))
|
||||
->setParameter('anonymous', intval( $row['full_anonymous'] ) * 2 + intval($row['is_anonymous']))
|
||||
->setParameter('full_anonymous', $row['full_anonymous'])
|
||||
->setParameter('allow_maybe', $row['allow_maybe'])
|
||||
->setParameter('options', $this->resolveOptions($row['allow_maybe']));
|
||||
$insert->execute();
|
||||
|
||||
}
|
||||
|
||||
$result->closeCursor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,9 +30,9 @@ use OCP\AppFramework\Db\DoesNotExistException;
|
|||
|
||||
use OCP\IGroupManager;
|
||||
use OCP\ILogger;
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
|
||||
/**
|
||||
|
@ -62,14 +62,14 @@ class Acl implements JsonSerializable {
|
|||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/** @var ShareMapper */
|
||||
private $shareMapper;
|
||||
|
||||
/** @var Event */
|
||||
private $event;
|
||||
/** @var Poll */
|
||||
private $poll;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -78,25 +78,25 @@ class Acl implements JsonSerializable {
|
|||
* @param string $userId
|
||||
* @param ILogger $logger
|
||||
* @param IGroupManager $groupManager
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param ShareMapper $shareMapper
|
||||
* @param Event $eventMapper
|
||||
* @param Poll $pollMapper
|
||||
*
|
||||
*/
|
||||
public function __construct(
|
||||
$userId,
|
||||
ILogger $logger,
|
||||
IGroupManager $groupManager,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
ShareMapper $shareMapper,
|
||||
Event $event
|
||||
Poll $poll
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->logger = $logger;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->event = $event;
|
||||
$this->poll = $poll;
|
||||
}
|
||||
|
||||
|
||||
|
@ -131,7 +131,7 @@ class Acl implements JsonSerializable {
|
|||
*/
|
||||
public function setPollId(int $pollId): Acl {
|
||||
$this->pollId = $pollId;
|
||||
$this->event = $this->eventMapper->find($this->pollId);
|
||||
$this->poll = $this->pollMapper->find($this->pollId);
|
||||
$this->shares = $this->shareMapper->findByPoll($this->pollId);
|
||||
|
||||
return $this;
|
||||
|
@ -143,7 +143,7 @@ class Acl implements JsonSerializable {
|
|||
*/
|
||||
public function getIsOwner(): bool {
|
||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
||||
return ($this->event->getOwner() === $this->userId);
|
||||
return ($this->poll->getOwner() === $this->userId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ class Acl implements JsonSerializable {
|
|||
*/
|
||||
public function getIsAdmin(): bool {
|
||||
if (\OC::$server->getUserSession()->isLoggedIn()) {
|
||||
return $this->groupManager->isAdmin($this->userId);
|
||||
return ($this->groupManager->isAdmin($this->userId) && $this->poll->getAdminAccess());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -169,9 +169,9 @@ class Acl implements JsonSerializable {
|
|||
return (
|
||||
$this->getIsOwner()
|
||||
|| $this->getIsAdmin()
|
||||
|| ($this->getGroupShare() && !$this->event->getDeleted())
|
||||
|| ($this->getPersonalShare() && !$this->event->getDeleted())
|
||||
|| $this->event->getAccess() !== 'hidden'
|
||||
|| ($this->getGroupShare() && !$this->poll->getDeleted())
|
||||
|| ($this->getPersonalShare() && !$this->poll->getDeleted())
|
||||
|| $this->poll->getAccess() !== 'hidden'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -204,12 +204,27 @@ class Acl implements JsonSerializable {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @return bool
|
||||
*/
|
||||
public function getExpired(): bool {
|
||||
return (
|
||||
$this->poll->getExpire() > 0
|
||||
&& $this->poll->getExpire() > time()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @return bool
|
||||
*/
|
||||
public function getAllowVote(): bool {
|
||||
if ($this->getAllowView() && !$this->event->getDeleted() && strtotime($this->event->getExpire()) > time()) {
|
||||
if (
|
||||
$this->getAllowView()
|
||||
&& !$this->getExpired()
|
||||
&& !$this->poll->getDeleted()
|
||||
) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -237,7 +252,7 @@ class Acl implements JsonSerializable {
|
|||
* @return bool
|
||||
*/
|
||||
public function getAllowSeeUsernames(): bool {
|
||||
return !(($this->event->getIsAnonymous() && !$this->getIsOwner()) || $this->event->getFullAnonymous());;
|
||||
return !(($this->poll->getAnonymous() && !$this->getIsOwner()) || $this->poll->getFullAnonymous());;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -311,11 +326,11 @@ class Acl implements JsonSerializable {
|
|||
public function getAccessLevel(): string {
|
||||
if ($this->getIsOwner()) {
|
||||
return 'owner';
|
||||
} elseif ($this->event->getAccess() === 'public') {
|
||||
} elseif ($this->poll->getAccess() === 'public') {
|
||||
return 'public';
|
||||
} elseif ($this->event->getAccess() === 'registered' && \OC::$server->getUserSession()->getUser()->getUID() === $this->userId) {
|
||||
} elseif ($this->poll->getAccess() === 'registered' && \OC::$server->getUserSession()->getUser()->getUID() === $this->userId) {
|
||||
return 'registered';
|
||||
} elseif ($this->event->getAccess() === 'hidden' && $this->getisOwner()) {
|
||||
} elseif ($this->poll->getAccess() === 'hidden' && $this->getisOwner()) {
|
||||
return 'hidden';
|
||||
} elseif ($this->getIsAdmin()) {
|
||||
return 'admin';
|
||||
|
|
|
@ -35,8 +35,8 @@ use OCP\ILogger;
|
|||
|
||||
use OCA\Polls\Db\SubscriptionMapper;
|
||||
use OCA\Polls\Db\Subscription;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
use OCA\Polls\Db\Share;
|
||||
use OCA\Polls\Db\LogMapper;
|
||||
|
@ -54,7 +54,7 @@ class MailService {
|
|||
|
||||
private $shareMapper;
|
||||
private $subscriptionMapper;
|
||||
private $eventMapper;
|
||||
private $pollMapper;
|
||||
private $logMapper;
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ class MailService {
|
|||
* @param ILogger $logger
|
||||
* @param SubscriptionMapper $subscriptionMapper
|
||||
* @param ShareMapper $shareMapper
|
||||
* @param EventMapper $eventMapper
|
||||
* @param PollMapper $pollMapper
|
||||
* @param LogMapper $logMapper
|
||||
*/
|
||||
|
||||
|
@ -84,7 +84,7 @@ class MailService {
|
|||
ILogger $logger,
|
||||
ShareMapper $shareMapper,
|
||||
SubscriptionMapper $subscriptionMapper,
|
||||
EventMapper $eventMapper,
|
||||
PollMapper $pollMapper,
|
||||
LogMapper $logMapper
|
||||
) {
|
||||
$this->config = $config;
|
||||
|
@ -97,7 +97,7 @@ class MailService {
|
|||
$this->logger = $logger;
|
||||
$this->shareMapper = $shareMapper;
|
||||
$this->subscriptionMapper = $subscriptionMapper;
|
||||
$this->eventMapper = $eventMapper;
|
||||
$this->pollMapper = $pollMapper;
|
||||
$this->logMapper = $logMapper;
|
||||
}
|
||||
|
||||
|
@ -225,13 +225,13 @@ class MailService {
|
|||
*/
|
||||
public function sendInvitationMail($token) {
|
||||
$share = $this->shareMapper->findByToken($token);
|
||||
$event = $this->eventMapper->find($share->getPollId());
|
||||
$owner = $this->userManager->get($event->getOwner());
|
||||
$poll = $this->pollMapper->find($share->getPollId());
|
||||
$owner = $this->userManager->get($poll->getOwner());
|
||||
|
||||
$recipients = $this->getRecipientsByShare(
|
||||
$this->shareMapper->findByToken($token),
|
||||
$this->config->getUserValue($event->getOwner(), 'core', 'lang'),
|
||||
$event->getOwner()
|
||||
$this->config->getUserValue($poll->getOwner(), 'core', 'lang'),
|
||||
$poll->getOwner()
|
||||
);
|
||||
$this->logger->debug(json_encode($recipients));
|
||||
|
||||
|
@ -241,17 +241,17 @@ class MailService {
|
|||
|
||||
$emailTemplate = $this->mailer->createEMailTemplate('polls.Invitation', [
|
||||
'owner' => $owner->getDisplayName(),
|
||||
'title' => $event->getTitle(),
|
||||
'title' => $poll->getTitle(),
|
||||
'link' => $recipient['link']
|
||||
]);
|
||||
|
||||
$emailTemplate->setSubject($trans->t('Poll invitation "%s"', $event->getTitle()));
|
||||
$emailTemplate->setSubject($trans->t('Poll invitation "%s"', $poll->getTitle()));
|
||||
$emailTemplate->addHeader();
|
||||
$emailTemplate->addHeading($trans->t('Poll invitation "%s"', $event->getTitle()), false);
|
||||
$emailTemplate->addHeading($trans->t('Poll invitation "%s"', $poll->getTitle()), false);
|
||||
|
||||
$emailTemplate->addBodyText(str_replace(
|
||||
['{owner}', '{title}'],
|
||||
[$owner->getDisplayName(), $event->getTitle()],
|
||||
[$owner->getDisplayName(), $poll->getTitle()],
|
||||
$trans->t('{owner} invited you to take part in the poll "{title}"' )
|
||||
));
|
||||
|
||||
|
@ -295,7 +295,7 @@ class MailService {
|
|||
continue;
|
||||
}
|
||||
|
||||
$event = $this->eventMapper->find($subscription->getPollId());
|
||||
$poll = $this->pollMapper->find($subscription->getPollId());
|
||||
$trans = $this->transFactory->get('polls', $lang);
|
||||
|
||||
$url = $this->urlGenerator->getAbsoluteURL(
|
||||
|
@ -306,7 +306,7 @@ class MailService {
|
|||
);
|
||||
|
||||
$emailTemplate = $this->mailer->createEMailTemplate('polls.Invitation', [
|
||||
'title' => $event->getTitle(),
|
||||
'title' => $poll->getTitle(),
|
||||
'link' => $url
|
||||
]);
|
||||
$emailTemplate->setSubject($trans->t('Polls App - New Activity'));
|
||||
|
@ -314,7 +314,7 @@ class MailService {
|
|||
$emailTemplate->addHeading($trans->t('Polls App - New Activity'), false);
|
||||
$emailTemplate->addBodyText(str_replace(
|
||||
['{title}'],
|
||||
[$event->getTitle()],
|
||||
[$poll->getTitle()],
|
||||
$trans->t('"{title}" had recent activity: ')
|
||||
));
|
||||
|
||||
|
|
|
@ -25,16 +25,16 @@ namespace OCA\Polls\Service;
|
|||
|
||||
use OCP\IGroupManager;
|
||||
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\ShareMapper;
|
||||
|
||||
class EventService {
|
||||
class PollService {
|
||||
private $mapper;
|
||||
private $shareMapper;
|
||||
private $groupManager;
|
||||
|
||||
public function __construct(
|
||||
EventMapper $mapper,
|
||||
PollMapper $mapper,
|
||||
ShareMapper $shareMapper,
|
||||
IGroupManager $groupManager
|
||||
) {
|
||||
|
@ -75,7 +75,7 @@ class EventService {
|
|||
|
||||
/**
|
||||
* Set the access right of the current user for the poll
|
||||
* @param Array $event
|
||||
* @param Array $poll
|
||||
* @param Array $shares
|
||||
* @return String
|
||||
*/
|
||||
|
@ -84,17 +84,17 @@ class EventService {
|
|||
$currentUser = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
}
|
||||
|
||||
$event = $this->mapper->find($pollId);
|
||||
$poll = $this->mapper->find($pollId);
|
||||
|
||||
$grantAccessAs = 'none';
|
||||
|
||||
if ($event->getOwner() === $currentUser) {
|
||||
if ($poll->getOwner() === $currentUser) {
|
||||
$grantAccessAs = 'owner';
|
||||
} elseif ($event->getAccess() === 'public') {
|
||||
} elseif ($poll->getAccess() === 'public') {
|
||||
$grantAccessAs = 'public';
|
||||
} elseif ($event->getAccess() === 'registered' && \OC::$server->getUserSession()->isLoggedIn()) {
|
||||
} elseif ($poll->getAccess() === 'registered' && \OC::$server->getUserSession()->isLoggedIn()) {
|
||||
$grantAccessAs = 'registered';
|
||||
} elseif ($event->getAccess() === 'hidden' && ($event->getowner() === \OC::$server->getUserSession()->getUser())) {
|
||||
} elseif ($poll->getAccess() === 'hidden' && ($poll->getowner() === \OC::$server->getUserSession()->getUser())) {
|
||||
$grantAccessAs = 'hidden';
|
||||
// } elseif ($this->checkUserAccess($shares)) {
|
||||
// $grantAccessAs = 'userInvitation';
|
|
@ -33,7 +33,7 @@
|
|||
<input id="datePoll" v-model="type" value="datePoll"
|
||||
:disabled="protect" type="radio" class="radio">
|
||||
<label for="datePoll">
|
||||
{{ t('polls', 'Event schedule') }}
|
||||
{{ t('polls', 'Poll schedule') }}
|
||||
</label>
|
||||
<input id="textPoll" v-model="type" value="textPoll"
|
||||
:disabled="protect" type="radio" class="radio">
|
||||
|
@ -47,7 +47,7 @@
|
|||
{{ t('polls', 'Cancel') }}
|
||||
</button>
|
||||
<button :disabled="titleEmpty" class="button primary" @click="confirm">
|
||||
{{ t('polls', 'Publish') }}
|
||||
{{ t('polls', 'Apply') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -68,7 +68,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event
|
||||
poll: state => state.poll
|
||||
}),
|
||||
|
||||
titleEmpty() {
|
||||
|
@ -77,7 +77,7 @@ export default {
|
|||
},
|
||||
|
||||
methods: {
|
||||
...mapMutations([ 'setEventProperty', 'resetEvent', 'reset' ]),
|
||||
...mapMutations([ 'setPollProperty', 'resetPoll', 'reset' ]),
|
||||
|
||||
cancel() {
|
||||
this.title = ''
|
||||
|
@ -86,19 +86,19 @@ export default {
|
|||
},
|
||||
|
||||
confirm() {
|
||||
this.resetEvent()
|
||||
this.resetPoll()
|
||||
this.reset()
|
||||
this.setEventProperty({ 'id': 0 })
|
||||
this.setEventProperty({ 'title': this.title })
|
||||
this.setEventProperty({ 'type': this.type })
|
||||
this.$store.dispatch('writeEventPromise')
|
||||
this.setPollProperty({ 'id': 0 })
|
||||
this.setPollProperty({ 'title': this.title })
|
||||
this.setPollProperty({ 'type': this.type })
|
||||
this.$store.dispatch('writePollPromise')
|
||||
.then((response) => {
|
||||
this.cancel()
|
||||
OC.Notification.showTemporary(t('polls', 'Poll "%n" added', 1, this.event.title), { type: 'success' })
|
||||
this.$router.push({ name: 'vote', params: { id: this.event.id } })
|
||||
OC.Notification.showTemporary(t('polls', 'Poll "%n" added', 1, this.poll.title), { type: 'success' })
|
||||
this.$router.push({ name: 'vote', params: { id: this.poll.id } })
|
||||
})
|
||||
.catch(() => {
|
||||
OC.Notification.showTemporary(t('polls', 'Error while creating Poll "%n"', 1, this.event.title), { type: 'error' })
|
||||
OC.Notification.showTemporary(t('polls', 'Error while creating Poll "%n"', 1, this.poll.title), { type: 'error' })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
v-for="(poll) in allPolls"
|
||||
:key="poll.id"
|
||||
:title="poll.title"
|
||||
:icon="eventIcon(poll.type)"
|
||||
:icon="pollIcon(poll.type)"
|
||||
:to="{name: 'vote', params: {id: poll.id}}" />
|
||||
</ul>
|
||||
</AppNavigationItem>
|
||||
|
@ -51,7 +51,7 @@
|
|||
v-for="(poll) in myPolls"
|
||||
:key="poll.id"
|
||||
:title="poll.title"
|
||||
:icon="eventIcon(poll.type)"
|
||||
:icon="pollIcon(poll.type)"
|
||||
:to="{name: 'vote', params: {id: poll.id}}" />
|
||||
</ul>
|
||||
</AppNavigationItem>
|
||||
|
@ -66,7 +66,7 @@
|
|||
v-for="(poll) in publicPolls"
|
||||
:key="poll.id"
|
||||
:title="poll.title"
|
||||
:icon="eventIcon(poll.type)"
|
||||
:icon="pollIcon(poll.type)"
|
||||
:to="{name: 'vote', params: {id: poll.id}}" />
|
||||
</ul>
|
||||
</AppNavigationItem>
|
||||
|
@ -81,7 +81,7 @@
|
|||
v-for="(poll) in hiddenPolls"
|
||||
:key="poll.id"
|
||||
:title="poll.title"
|
||||
:icon="eventIcon(poll.type)"
|
||||
:icon="pollIcon(poll.type)"
|
||||
:to="{name: 'vote', params: {id: poll.id}}" />
|
||||
</ul>
|
||||
</AppNavigationItem>
|
||||
|
@ -96,26 +96,19 @@
|
|||
v-for="(poll) in deletedPolls"
|
||||
:key="poll.id"
|
||||
:title="poll.title"
|
||||
:icon="eventIcon(poll.type)"
|
||||
:icon="pollIcon(poll.type)"
|
||||
:to="{name: 'vote', params: {id: poll.id}}" />
|
||||
</ul>
|
||||
</AppNavigationItem>
|
||||
</ul>
|
||||
|
||||
<AppNavigationSettings>
|
||||
<router-link :to="{ name: 'list'}">
|
||||
List
|
||||
</router-link>
|
||||
</AppNavigationSettings>
|
||||
</AppNavigation>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import { AppNavigation, AppNavigationNew, AppNavigationItem, AppNavigationSettings } from '@nextcloud/vue'
|
||||
import { AppNavigation, AppNavigationNew, AppNavigationItem } from '@nextcloud/vue'
|
||||
import { mapGetters } from 'vuex'
|
||||
import CreateDlg from '../Create/CreateDlg'
|
||||
import state from './store/polls.js'
|
||||
|
||||
export default {
|
||||
name: 'Navigation',
|
||||
|
@ -123,7 +116,6 @@ export default {
|
|||
AppNavigation,
|
||||
AppNavigationNew,
|
||||
AppNavigationItem,
|
||||
AppNavigationSettings,
|
||||
CreateDlg
|
||||
},
|
||||
|
||||
|
@ -134,7 +126,6 @@ export default {
|
|||
},
|
||||
|
||||
computed: {
|
||||
|
||||
...mapGetters([
|
||||
'allPolls',
|
||||
'myPolls',
|
||||
|
@ -165,7 +156,6 @@ export default {
|
|||
},
|
||||
|
||||
created() {
|
||||
this.$store.registerModule('polls', state)
|
||||
this.refreshPolls()
|
||||
},
|
||||
|
||||
|
@ -178,7 +168,7 @@ export default {
|
|||
this.createDlg = !this.createDlg
|
||||
},
|
||||
|
||||
eventIcon(type) {
|
||||
pollIcon(type) {
|
||||
if (type === '0') {
|
||||
return 'icon-calendar'
|
||||
} else {
|
||||
|
|
|
@ -130,24 +130,14 @@ export default {
|
|||
},
|
||||
|
||||
expired() {
|
||||
if (this.poll.expire === null) {
|
||||
return false
|
||||
} else if (Date.parse(this.poll.expire) < Date.now()) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
return (this.poll.expire > 0 && moment.unix(this.poll.expire).diff() < 0)
|
||||
},
|
||||
|
||||
accessType() {
|
||||
if (this.aType === 'public') {
|
||||
return t('polls', 'Public access')
|
||||
} else if (this.aType === 'registered') {
|
||||
return t('polls', 'Registered users only')
|
||||
return t('polls', 'Visible')
|
||||
} else if (this.aType === 'hidden') {
|
||||
return t('polls', 'Hidden poll')
|
||||
} else if (this.aType === 'select') {
|
||||
return t('polls', 'Only shared')
|
||||
return t('polls', 'Hidden')
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
@ -166,22 +156,24 @@ export default {
|
|||
},
|
||||
|
||||
pollType() {
|
||||
if (this.pType === 'textPoll') {
|
||||
if (this.poll.type === 'textPoll') {
|
||||
// TRANSLATORS This means that this is the type of the poll. Another type is a 'date poll'.
|
||||
return t('polls', 'Text poll')
|
||||
} else {
|
||||
} else if (this.poll.type === 'datePoll') {
|
||||
// TRANSLATORS This means that this is the type of the poll. Another type is a 'text poll'.
|
||||
return t('polls', 'Date poll')
|
||||
} else {
|
||||
return t('polls', 'Unknown')
|
||||
}
|
||||
},
|
||||
|
||||
timeSpanCreated() {
|
||||
return moment.utc(this.poll.created).fromNow()
|
||||
return moment.unix(this.poll.created).fromNow()
|
||||
},
|
||||
|
||||
timeSpanExpiration() {
|
||||
if (this.poll.expire) {
|
||||
return moment.utc(this.poll.expire).fromNow()
|
||||
return moment.unix(this.poll.expire).fromNow()
|
||||
} else {
|
||||
return t('polls', 'never')
|
||||
}
|
||||
|
@ -193,12 +185,6 @@ export default {
|
|||
|
||||
menuItems() {
|
||||
let items = [
|
||||
{
|
||||
key: 'copyLink',
|
||||
icon: 'icon-clippy',
|
||||
text: t('polls', 'Copy Link'),
|
||||
action: this.copyLink
|
||||
},
|
||||
{
|
||||
key: 'clonePoll',
|
||||
icon: 'icon-confirm',
|
||||
|
@ -208,12 +194,6 @@ export default {
|
|||
]
|
||||
|
||||
if (this.poll.owner === OC.getCurrentUser().uid) {
|
||||
// items.push({
|
||||
// key: 'editPoll',
|
||||
// icon: 'icon-rename',
|
||||
// text: t('polls', 'Edit poll'),
|
||||
// action: this.editPoll
|
||||
// })
|
||||
items.push({
|
||||
key: 'deletePoll',
|
||||
icon: 'icon-delete',
|
||||
|
@ -221,12 +201,6 @@ export default {
|
|||
action: this.deletePoll
|
||||
})
|
||||
} else if (OC.isUserAdmin()) {
|
||||
// items.push({
|
||||
// key: 'editPoll',
|
||||
// icon: 'icon-rename',
|
||||
// text: t('polls', 'Edit poll as admin'),
|
||||
// action: this.editPoll
|
||||
// })
|
||||
items.push({
|
||||
key: 'deletePoll',
|
||||
icon: 'icon-delete',
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
-->
|
||||
|
||||
<template>
|
||||
<AppSidebar :active="initialTab" :title="t('polls', 'Details')" @close="$emit('closeSideBar')">
|
||||
<UserDiv slot="primary-actions" :user-id="event.owner" :description="t('polls', 'Owner')" />
|
||||
<AppSidebar ref="sideBar" :title="t('polls', 'Details')" @close="$emit('closeSideBar')">
|
||||
<UserDiv slot="primary-actions" :user-id="poll.owner" :description="t('polls', 'Owner')" />
|
||||
|
||||
<AppSidebarTab :name="t('polls', 'Comments')" icon="icon-comment">
|
||||
<SideBarTabComments />
|
||||
</AppSidebarTab>
|
||||
|
||||
<AppSidebarTab :name="t('polls', 'options')" icon="icon-toggle-filelist">
|
||||
<AppSidebarTab v-if="acl.allowEdit" :name="t('polls', 'options')" icon="icon-toggle-filelist">
|
||||
<SideBarTabOptions />
|
||||
</AppSidebarTab>
|
||||
|
||||
|
@ -62,15 +62,9 @@ export default {
|
|||
AppSidebarTab
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
initialTab: 'comments'
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,51 +29,51 @@
|
|||
|
||||
<div v-if="acl.allowEdit" class="configBox">
|
||||
<label class="icon-sound title"> {{ t('polls', 'Title') }} </label>
|
||||
<input v-model="eventTitle" :class="{ error: titleEmpty }" type="text">
|
||||
<input v-model="pollTitle" :class="{ error: titleEmpty }" type="text">
|
||||
</div>
|
||||
|
||||
<div v-if="acl.allowEdit" class="configBox">
|
||||
<label class="icon-edit title"> {{ t('polls', 'Description') }} </label>
|
||||
<textarea v-model="eventDescription" />
|
||||
<textarea v-model="pollDescription" />
|
||||
</div>
|
||||
|
||||
<div class="configBox">
|
||||
<label class="title icon-category-customization"> {{ t('polls', 'Poll configurations') }} </label>
|
||||
|
||||
<input id="allowMaybe" v-model="eventAllowMaybe"
|
||||
<input id="allowMaybe" v-model="pollAllowMaybe"
|
||||
type="checkbox" class="checkbox">
|
||||
<label for="allowMaybe" class="title"> {{ t('polls', 'Allow "maybe" vote') }} </label>
|
||||
|
||||
<input id="anonymous" v-model="eventIsAnonymous"
|
||||
<input id="anonymous" v-model="pollAnonymous"
|
||||
type="checkbox" class="checkbox">
|
||||
<label for="anonymous" class="title"> {{ t('polls', 'Anonymous poll') }} </label>
|
||||
|
||||
<input v-show="event.isAnonymous" id="trueAnonymous" v-model="eventFullAnonymous"
|
||||
<input v-show="poll.anonymous" id="trueAnonymous" v-model="pollFullAnonymous"
|
||||
type="checkbox" class="checkbox">
|
||||
<label v-show="event.isAnonymous" class="title" for="trueAnonymous"> {{ t('polls', 'Hide user names for admin') }} </label>
|
||||
<label v-show="poll.anonymous" class="title" for="trueAnonymous"> {{ t('polls', 'Hide user names for admin') }} </label>
|
||||
|
||||
<input id="expiration" v-model="eventExpiration"
|
||||
<input id="expiration" v-model="pollExpiration"
|
||||
type="checkbox" class="checkbox">
|
||||
<label class="title" for="expiration"> {{ t('polls', 'Expires') }} </label>
|
||||
|
||||
<DatePicker v-show="eventExpiration"
|
||||
v-model="eventExpire" v-bind="expirationDatePicker" style="width:170px" />
|
||||
<DatePicker v-show="pollExpiration"
|
||||
v-model="pollExpire" v-bind="expirationDatePicker" style="width:170px" />
|
||||
</div>
|
||||
|
||||
<div class="configBox">
|
||||
<label class="title icon-category-auth"> {{ t('polls', 'Access') }} </label>
|
||||
|
||||
<input id="hidden" v-model="eventAccess" value="hidden"
|
||||
<input id="hidden" v-model="pollAccess" value="hidden"
|
||||
type="radio" class="radio">
|
||||
<label for="hidden" class="title">{{ t('polls', 'Hidden to other users') }} </label>
|
||||
|
||||
<input id="public" v-model="eventAccess" value="public"
|
||||
<input id="public" v-model="pollAccess" value="public"
|
||||
type="radio" class="radio">
|
||||
<label for="public" class="title">{{ t('polls', 'Visible to other users') }} </label>
|
||||
</div>
|
||||
|
||||
<button class="button btn primary" @click="switchDeleted()">
|
||||
<span v-if="event.deleted">{{ t('polls', 'Restore poll') }}</span>
|
||||
<span v-if="poll.deleted">{{ t('polls', 'Restore poll') }}</span>
|
||||
<span v-else>{{ t('polls', 'Delete poll') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
@ -90,98 +90,99 @@ export default {
|
|||
return {
|
||||
writingPoll: false,
|
||||
sidebar: false,
|
||||
titleEmpty: false
|
||||
titleEmpty: false,
|
||||
setExpiration: false
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
||||
// Add bindings
|
||||
eventDescription: {
|
||||
pollDescription: {
|
||||
get() {
|
||||
return this.event.description
|
||||
return this.poll.description
|
||||
},
|
||||
set(value) {
|
||||
this.writeValueDebounced({ 'description': value })
|
||||
}
|
||||
},
|
||||
|
||||
eventTitle: {
|
||||
pollTitle: {
|
||||
get() {
|
||||
return this.event.title
|
||||
return this.poll.title
|
||||
},
|
||||
set(value) {
|
||||
this.writeValueDebounced({ 'title': value })
|
||||
}
|
||||
},
|
||||
|
||||
eventAccess: {
|
||||
pollAccess: {
|
||||
get() {
|
||||
return this.event.access
|
||||
return this.poll.access
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'access': value })
|
||||
}
|
||||
},
|
||||
|
||||
eventExpire: {
|
||||
pollExpire: {
|
||||
get() {
|
||||
return moment.utc(this.event.expire).local()
|
||||
return moment.unix(this.poll.expire)
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'expire': moment.local(value).utc().format() })
|
||||
|
||||
this.writeValue({ 'expire': moment(value).unix() })
|
||||
}
|
||||
},
|
||||
|
||||
eventExpiration: {
|
||||
pollExpiration: {
|
||||
get() {
|
||||
return this.event.expiration
|
||||
return this.poll.expire
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'expiration': value })
|
||||
if (value) {
|
||||
this.writeValue({ 'expire': moment().unix() })
|
||||
} else {
|
||||
this.writeValue({ 'expire': 0 })
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
eventFullAnonymous: {
|
||||
pollFullAnonymous: {
|
||||
get() {
|
||||
return this.event.fullAnonymous
|
||||
return (this.poll.Fullanonymous > 0)
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'fullAnonymous': value })
|
||||
}
|
||||
},
|
||||
|
||||
eventIsAnonymous: {
|
||||
pollAnonymous: {
|
||||
get() {
|
||||
return this.event.isAnonymous
|
||||
return (this.poll.anonymous > 0)
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'isAnonymous': value })
|
||||
this.writeValue({ 'anonymous': value })
|
||||
}
|
||||
},
|
||||
|
||||
eventAllowMaybe: {
|
||||
pollAllowMaybe: {
|
||||
get() {
|
||||
return this.event.allowMaybe
|
||||
return this.poll.allowMaybe
|
||||
},
|
||||
set(value) {
|
||||
this.writeValue({ 'allowMaybe': value })
|
||||
if (value) {
|
||||
this.writeValue({ 'options': ['yes', 'no', 'maybe'] })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// eventExpiration: {
|
||||
// get() {
|
||||
// return this.$store.state.event.expiration
|
||||
// },
|
||||
// set(value) {
|
||||
// this.writeValue({ 'expiration': value })
|
||||
// }
|
||||
// },
|
||||
|
||||
langPicker() {
|
||||
return {
|
||||
formatLocale: {
|
||||
|
@ -236,21 +237,25 @@ export default {
|
|||
},
|
||||
methods: {
|
||||
|
||||
...mapMutations([ 'setEventProperty' ]),
|
||||
...mapActions([ 'writeEventPromise' ]),
|
||||
...mapMutations([ 'setPollProperty' ]),
|
||||
...mapActions([ 'writePollPromise' ]),
|
||||
|
||||
writeValueDebounced: debounce(function(e) {
|
||||
this.writeValue(e)
|
||||
}, 1500),
|
||||
|
||||
writeValue(e) {
|
||||
this.$store.commit('setEventProperty', e)
|
||||
this.$store.commit('setPollProperty', e)
|
||||
this.writingPoll = true
|
||||
this.writePoll()
|
||||
},
|
||||
|
||||
switchDeleted() {
|
||||
this.writeValue({ 'deleted': !this.event.deleted })
|
||||
if (this.poll.deleted) {
|
||||
this.writeValue({ 'deleted': 0 })
|
||||
} else {
|
||||
this.writeValue({ 'deleted': moment.utc().unix() })
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
@ -258,9 +263,9 @@ export default {
|
|||
if (this.titleEmpty) {
|
||||
OC.Notification.showTemporary(t('polls', 'Title must not be empty!'), { type: 'success' })
|
||||
} else {
|
||||
this.$store.dispatch('writeEventPromise')
|
||||
this.$store.dispatch('writePollPromise')
|
||||
.then(() => {
|
||||
OC.Notification.showTemporary(t('polls', '%n successfully saved', 1, this.event.title), { type: 'success' })
|
||||
OC.Notification.showTemporary(t('polls', '%n successfully saved', 1, this.poll.title), { type: 'success' })
|
||||
this.$root.$emit('updatePolls')
|
||||
})
|
||||
this.writingPoll = false
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
v-bind="optionDatePicker"
|
||||
style="width:100%"
|
||||
confirm
|
||||
@change="addOption($event)" />
|
||||
@change="addOption($poll)" />
|
||||
</div>
|
||||
|
||||
<div class="configBox">
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
<template>
|
||||
<div>
|
||||
<SideBarTabDateOptions v-if="acl.allowEdit && event.type === 'datePoll'" />
|
||||
<SideBarTabTextOptions v-if="acl.allowEdit && event.type === 'textPoll'" />
|
||||
<SideBarTabDateOptions v-if="acl.allowEdit && poll.type === 'datePoll'" />
|
||||
<SideBarTabTextOptions v-if="acl.allowEdit && poll.type === 'textPoll'" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -53,7 +53,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
})
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ export default {
|
|||
computed: {
|
||||
...mapState({
|
||||
subscription: state => state.subscription,
|
||||
event: state => state.event
|
||||
poll: state => state.poll
|
||||
}),
|
||||
|
||||
subscribe: {
|
||||
|
@ -45,7 +45,7 @@ export default {
|
|||
},
|
||||
set(value) {
|
||||
this.$store.commit('setSubscription', value)
|
||||
this.$store.dispatch('writeSubscriptionPromise', { pollId: this.event.id })
|
||||
this.$store.dispatch('writeSubscriptionPromise', { pollId: this.poll.id })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -23,13 +23,13 @@
|
|||
<template>
|
||||
<div class="voteHeader">
|
||||
<h2>
|
||||
{{ event.title }}
|
||||
<span v-if="expired" class="label error">{{ t('polls', 'Expired since %n', 1, moment.utc(event.expire).local().format('LLLL')) }}</span>
|
||||
<span v-if="!expired && event.expiration" class="label success">{{ t('polls', 'Place your votes until %n', 1, moment.utc(event.expire).local().format('LLLL')) }}</span>
|
||||
<span v-if="event.deleted" class="label error">{{ t('polls', 'Deleted') }}</span>
|
||||
{{ poll.title }}
|
||||
<span v-if="expired" class="label error">{{ t('polls', 'Expired since %n', 1, moment.unix(poll.expire).format('LLLL')) }}</span>
|
||||
<span v-if="!expired && poll.expire" class="label success">{{ t('polls', 'Place your votes until %n', 1, moment.unix(poll.expire).format('LLLL')) }}</span>
|
||||
<span v-if="poll.deleted" class="label error">{{ t('polls', 'Deleted') }}</span>
|
||||
</h2>
|
||||
<h3>
|
||||
{{ event.description }}
|
||||
{{ poll.description }}
|
||||
</h3>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -50,7 +50,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event
|
||||
poll: state => state.poll
|
||||
}),
|
||||
|
||||
...mapGetters([
|
||||
|
|
|
@ -73,7 +73,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
||||
|
@ -116,7 +116,7 @@ export default {
|
|||
validatePublicUsername: debounce(function() {
|
||||
if (this.userName.length > 2) {
|
||||
this.checkingUserName = true
|
||||
return axios.post(OC.generateUrl('apps/polls/check/username'), { pollId: this.event.id, userName: this.userName, token: this.$route.params.token })
|
||||
return axios.post(OC.generateUrl('apps/polls/check/username'), { pollId: this.poll.id, userName: this.userName, token: this.$route.params.token })
|
||||
.then((response) => {
|
||||
this.checkingUserName = false
|
||||
this.isValidName = true
|
||||
|
@ -146,7 +146,7 @@ export default {
|
|||
this.$router.replace({ name: 'publicVote', params: { 'token': response.token } })
|
||||
})
|
||||
.catch(() => {
|
||||
OC.Notification.showTemporary(t('polls', 'Error saving user name', 1, event.title), { type: 'error' })
|
||||
OC.Notification.showTemporary(t('polls', 'Error saving user name', 1, this.poll.title), { type: 'error' })
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<VoteTableHeader v-for="(option) in sortedOptions"
|
||||
:key="option.id"
|
||||
:option="option"
|
||||
:poll-type="event.type" />
|
||||
:poll-type="poll.type" />
|
||||
</div>
|
||||
|
||||
<div v-for="(participant) in participants" :key="participant" :class="{currentuser: (participant === currentUser) }">
|
||||
|
@ -63,7 +63,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
||||
|
|
|
@ -26,18 +26,18 @@
|
|||
{{ option.pollOptionText }}
|
||||
</div>
|
||||
|
||||
<div v-if="datePoll" v-tooltip.auto="localFullDate" class="date-box">
|
||||
<div v-if="datePoll" v-tooltip.auto="moment.unix(option.timestamp).format('llll')" class="date-box">
|
||||
<div class="month">
|
||||
{{ monthY }}
|
||||
{{ moment.unix(option.timestamp).format('MMM') + " '" + moment.unix(option.timestamp).format('YY') }}
|
||||
</div>
|
||||
<div class="day">
|
||||
{{ day }}
|
||||
{{ moment.unix(option.timestamp).format('Do') }}
|
||||
</div>
|
||||
<div class="dow">
|
||||
{{ dow }}
|
||||
{{ moment.unix(option.timestamp).format('ddd') }}
|
||||
</div>
|
||||
<div class="time">
|
||||
{{ time }}
|
||||
{{ moment.unix(option.timestamp).format('LT') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
|||
<div class="yes">
|
||||
<span> {{ yesVotes }} </span>
|
||||
</div>
|
||||
<div v-if="event.allowMaybe" class="maybe">
|
||||
<div v-if="poll.allowMaybe" class="maybe">
|
||||
<span> {{ maybeVotes }} </span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -79,7 +79,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
votes: state => state.votes.list
|
||||
}),
|
||||
...mapGetters([
|
||||
|
@ -135,63 +135,11 @@ export default {
|
|||
},
|
||||
|
||||
datePoll() {
|
||||
return (this.event.type === 'datePoll')
|
||||
return (this.poll.type === 'datePoll')
|
||||
},
|
||||
|
||||
textPoll() {
|
||||
return (this.event.type === 'textPoll')
|
||||
},
|
||||
|
||||
localFullDate() {
|
||||
return moment(this.option.timestamp * 1000).format('llll')
|
||||
},
|
||||
|
||||
day() {
|
||||
return moment(this.option.timestamp * 1000).format('Do')
|
||||
},
|
||||
|
||||
dow() {
|
||||
return moment(this.option.timestamp * 1000).format('ddd')
|
||||
},
|
||||
|
||||
month() {
|
||||
return moment(this.option.timestamp * 1000).format('MMM')
|
||||
},
|
||||
|
||||
monthY() {
|
||||
return this.month + " '" + moment(this.option.timestamp * 1000).format('YY')
|
||||
},
|
||||
|
||||
year() {
|
||||
return moment(this.option.timestamp * 1000).format('YYYY')
|
||||
},
|
||||
|
||||
time() {
|
||||
return moment(this.option.timestamp * 1000).format('LT')
|
||||
},
|
||||
|
||||
localFullDateT() {
|
||||
return moment(this.option.pollOptionText).format('llll')
|
||||
},
|
||||
|
||||
dayT() {
|
||||
return moment(this.option.pollOptionText).format('Do')
|
||||
},
|
||||
|
||||
dowT() {
|
||||
return moment(this.option.pollOptionText).format('ddd')
|
||||
},
|
||||
|
||||
monthT() {
|
||||
return moment(this.option.pollOptionText).format('MMM')
|
||||
},
|
||||
|
||||
yearT() {
|
||||
return moment(this.option.pollOptionText).format('YYYY')
|
||||
},
|
||||
|
||||
timeT() {
|
||||
return moment(this.option.pollOptionText).format('LT')
|
||||
return (this.poll.type === 'textPoll')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
||||
|
@ -65,7 +65,7 @@ export default {
|
|||
},
|
||||
|
||||
isActive() {
|
||||
return (this.isValidUser && this.acl.userId === this.userId && !this.event.expired)
|
||||
return (this.isValidUser && this.acl.userId === this.userId && !this.poll.expired)
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -26,7 +26,8 @@ import Vue from 'vue'
|
|||
import Vuex from 'vuex'
|
||||
import acl from './modules/acl'
|
||||
import comments from './modules/comments'
|
||||
import event from './modules/event'
|
||||
import poll from './modules/poll'
|
||||
import polls from './modules/polls'
|
||||
import subscription from './modules/subscription'
|
||||
import votes from './modules/votes'
|
||||
import options from './modules/options'
|
||||
|
@ -42,7 +43,8 @@ export default new Vuex.Store({
|
|||
modules: {
|
||||
acl,
|
||||
comments,
|
||||
event,
|
||||
poll,
|
||||
polls,
|
||||
subscription,
|
||||
votes,
|
||||
options,
|
||||
|
|
|
@ -89,7 +89,7 @@ const actions = {
|
|||
}
|
||||
|
||||
return axios.post(OC.generateUrl(endPoint), {
|
||||
pollId: rootState.event.id,
|
||||
pollId: rootState.poll.id,
|
||||
token: rootState.acl.token,
|
||||
message: payload.message,
|
||||
userId: rootState.acl.userId
|
||||
|
|
|
@ -109,13 +109,13 @@ const actions = {
|
|||
let option = {}
|
||||
|
||||
option.id = 0
|
||||
option.pollId = rootState.event.id
|
||||
option.pollId = rootState.poll.id
|
||||
|
||||
if (rootState.event.type === 'datePoll') {
|
||||
if (rootState.poll.type === 'datePoll') {
|
||||
option.timestamp = moment(payload.pollOptionText).unix()
|
||||
option.pollOptionText = moment.utc(payload.pollOptionText).format()
|
||||
|
||||
} else if (rootState.event.type === 'textPoll') {
|
||||
} else if (rootState.poll.type === 'textPoll') {
|
||||
option.timestamp = 0
|
||||
option.pollOptionText = payload.pollOptionText
|
||||
}
|
||||
|
|
|
@ -23,39 +23,40 @@
|
|||
|
||||
import axios from '@nextcloud/axios'
|
||||
|
||||
const defaultEvent = () => {
|
||||
const defaultPoll = () => {
|
||||
return {
|
||||
id: 0,
|
||||
type: 'datePoll',
|
||||
title: '',
|
||||
description: '',
|
||||
owner: undefined,
|
||||
created: '',
|
||||
access: 'public',
|
||||
expire: null,
|
||||
expiration: false,
|
||||
isAnonymous: false,
|
||||
fullAnonymous: false,
|
||||
allowMaybe: false,
|
||||
voteLimit: null,
|
||||
showResults: true,
|
||||
deleted: false,
|
||||
deleteDate: null
|
||||
owner: '',
|
||||
created: 0,
|
||||
expire: 0,
|
||||
deleted: 0,
|
||||
access: 'hidden',
|
||||
anonymous: 0,
|
||||
fullAnonymous: 0,
|
||||
allowMaybe: 0,
|
||||
voteLimit: 0,
|
||||
showResults: 'always',
|
||||
adminAccess: 0,
|
||||
settings: '',
|
||||
options: ''
|
||||
}
|
||||
}
|
||||
|
||||
const state = defaultEvent()
|
||||
const state = defaultPoll()
|
||||
|
||||
const mutations = {
|
||||
setEvent(state, payload) {
|
||||
Object.assign(state, payload.event)
|
||||
setPoll(state, payload) {
|
||||
Object.assign(state, payload.poll)
|
||||
},
|
||||
|
||||
resetEvent(state) {
|
||||
Object.assign(state, defaultEvent())
|
||||
resetPoll(state) {
|
||||
Object.assign(state, defaultPoll())
|
||||
},
|
||||
|
||||
setEventProperty(state, payload) {
|
||||
setPollProperty(state, payload) {
|
||||
Object.assign(state, payload)
|
||||
}
|
||||
|
||||
|
@ -64,16 +65,12 @@ const mutations = {
|
|||
const getters = {
|
||||
|
||||
expired: (state, getters) => {
|
||||
return (state.expiration && moment(state.expire).diff() < 0)
|
||||
return (state.expire > 0 && moment.unix(state.expire).diff() < 0)
|
||||
},
|
||||
|
||||
accessType: (state, getters, rootState) => {
|
||||
if (rootState.acl.accessLevel === 'public') {
|
||||
return t('polls', 'Public access')
|
||||
} else if (rootState.acl.accessLevel === 'select') {
|
||||
return t('polls', 'Only shared')
|
||||
} else if (rootState.acl.accessLevel === 'registered') {
|
||||
return t('polls', 'Registered users only')
|
||||
} else if (rootState.acl.accessLevel === 'hidden') {
|
||||
return t('polls', 'Hidden poll')
|
||||
} else {
|
||||
|
@ -89,8 +86,8 @@ const getters = {
|
|||
|
||||
const actions = {
|
||||
|
||||
loadEvent({ commit }, payload) {
|
||||
let endPoint = 'apps/polls/event/get/'
|
||||
loadPollMain({ commit }, payload) {
|
||||
let endPoint = 'apps/polls/poll/get/'
|
||||
|
||||
if (payload.token !== undefined) {
|
||||
endPoint = endPoint.concat('s/', payload.token)
|
||||
|
@ -99,44 +96,43 @@ const actions = {
|
|||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
return axios.get(OC.generateUrl(endPoint))
|
||||
.then((response) => {
|
||||
commit('setEvent', { 'event': response.data })
|
||||
commit('setPoll', { 'poll': response.data })
|
||||
}, (error) => {
|
||||
if (error.response.status !== '404') {
|
||||
console.error('Error loading event', { 'error': error.response }, { 'payload': payload })
|
||||
console.error('Error loading poll', { 'error': error.response }, { 'payload': payload })
|
||||
}
|
||||
throw error
|
||||
})
|
||||
},
|
||||
|
||||
deleteEventPromise({ commit }, payload) {
|
||||
let endPoint = 'apps/polls/event/delete/'
|
||||
deletePollPromise({ commit }, payload) {
|
||||
let endPoint = 'apps/polls/poll/delete/'
|
||||
|
||||
return axios.post(OC.generateUrl(endPoint), { event: payload.id })
|
||||
return axios.post(OC.generateUrl(endPoint), { poll: payload.id })
|
||||
.then((response) => {
|
||||
return response
|
||||
}, (error) => {
|
||||
console.error('Error deleting event', { 'error': error.response }, { 'payload': payload })
|
||||
console.error('Error deleting poll', { 'error': error.response }, { 'payload': payload })
|
||||
throw error
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
writeEventPromise({ commit, rootState }) {
|
||||
let endPoint = 'apps/polls/event/write/'
|
||||
writePollPromise({ commit, rootState }) {
|
||||
let endPoint = 'apps/polls/poll/write/'
|
||||
|
||||
return axios.post(OC.generateUrl(endPoint), { event: state })
|
||||
return axios.post(OC.generateUrl(endPoint), { poll: state })
|
||||
.then((response) => {
|
||||
commit('setEvent', { 'event': response.data })
|
||||
return response.event
|
||||
commit('setPoll', { 'poll': response.data })
|
||||
return response.poll
|
||||
}, (error) => {
|
||||
console.error('Error writing event:', { 'error': error.response }, { 'state': state })
|
||||
console.error('Error writing poll:', { 'error': error.response }, { 'state': state })
|
||||
throw error
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export default { state, mutations, getters, actions, defaultEvent }
|
||||
export default { state, mutations, getters, actions, defaultPoll }
|
|
@ -56,7 +56,7 @@ const getters = {
|
|||
|
||||
const actions = {
|
||||
loadPolls({ commit }) {
|
||||
let endPoint = 'apps/polls/events/get/'
|
||||
let endPoint = 'apps/polls/polls/get/'
|
||||
|
||||
return axios.get(OC.generateUrl(endPoint))
|
||||
.then((response) => {
|
||||
|
@ -71,7 +71,7 @@ const actions = {
|
|||
|
||||
return axios.post(
|
||||
OC.generateUrl(endPoint),
|
||||
payload.event
|
||||
payload.poll
|
||||
)
|
||||
}
|
||||
}
|
|
@ -92,9 +92,7 @@ const actions = {
|
|||
|
||||
return axios.get(OC.generateUrl(endPoint))
|
||||
.then((response) => {
|
||||
commit('setShares', {
|
||||
'list': response.data
|
||||
})
|
||||
commit('setShares', { 'list': response.data })
|
||||
}, (error) => {
|
||||
console.error('Error loading shares', { 'error': error.response }, { 'payload': payload })
|
||||
throw error
|
||||
|
@ -129,8 +127,8 @@ const actions = {
|
|||
|
||||
writeSharePromise({ commit, rootState }, payload) {
|
||||
let endPoint = 'apps/polls/share/write/'
|
||||
payload.share.pollId = rootState.event.id
|
||||
return axios.post(OC.generateUrl(endPoint), { pollId: rootState.event.id, share: payload.share })
|
||||
payload.share.pollId = rootState.poll.id
|
||||
return axios.post(OC.generateUrl(endPoint), { pollId: rootState.poll.id, share: payload.share })
|
||||
.then((response) => {
|
||||
commit('addShare', response.data)
|
||||
}, (error) => {
|
||||
|
|
|
@ -56,7 +56,7 @@ const mutations = {
|
|||
const getters = {
|
||||
|
||||
answerSequence: (state, getters, rootState) => {
|
||||
if (rootState.event.allowMaybe) {
|
||||
if (rootState.poll.allowMaybe) {
|
||||
return ['no', 'maybe', 'yes', 'no']
|
||||
} else {
|
||||
return ['no', 'yes', 'no']
|
||||
|
@ -148,14 +148,14 @@ const actions = {
|
|||
}
|
||||
|
||||
return axios.post(OC.generateUrl(endPoint), {
|
||||
pollId: rootState.event.id,
|
||||
pollId: rootState.poll.id,
|
||||
token: rootState.acl.token,
|
||||
option: payload.option,
|
||||
userId: payload.userId,
|
||||
setTo: payload.setTo
|
||||
})
|
||||
.then((response) => {
|
||||
commit('setVote', { option: payload.option, pollId: rootState.event.id, vote: response.data })
|
||||
commit('setVote', { option: payload.option, pollId: rootState.poll.id, vote: response.data })
|
||||
return response.data
|
||||
}, (error) => {
|
||||
console.error('Error setting vote', { 'error': error.response }, { 'payload': payload })
|
||||
|
|
|
@ -94,11 +94,11 @@ export default {
|
|||
},
|
||||
|
||||
methods: {
|
||||
callPoll(index, event, name) {
|
||||
callPoll(index, poll, name) {
|
||||
this.$router.push({
|
||||
name: name,
|
||||
params: {
|
||||
id: event.id
|
||||
id: poll.id
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -113,14 +113,14 @@ export default {
|
|||
.catch(error => {
|
||||
this.loading = false
|
||||
console.error('refresh poll: ', error.response)
|
||||
OC.Notification.showTemporary(t('polls', 'Error loading polls', 1, event.title), { type: 'error' })
|
||||
OC.Notification.showTemporary(t('polls', 'Error loading polls', 1, this.poll.title), { type: 'error' })
|
||||
})
|
||||
}
|
||||
|
||||
// removePoll(index, event) {
|
||||
// removePoll(index, poll) {
|
||||
// const params = {
|
||||
// title: t('polls', 'Delete poll'),
|
||||
// text: t('polls', 'Do you want to delete "%n"?', 1, event.title),
|
||||
// text: t('polls', 'Do you want to delete "%n"?', 1, poll.title),
|
||||
// buttonHideText: t('polls', 'No, keep poll.'),
|
||||
// buttonConfirmText: t('polls', 'Yes, delete poll.'),
|
||||
// // Call store action here
|
||||
|
@ -129,17 +129,17 @@ export default {
|
|||
// this.$store
|
||||
// .dispatch({
|
||||
// type: 'deletePollPromise',
|
||||
// event: event
|
||||
// poll: poll
|
||||
// })
|
||||
// .then(response => {
|
||||
// this.loading = false
|
||||
// this.refreshPolls()
|
||||
// OC.Notification.showTemporary(t('polls', 'Poll "%n" deleted', 1, event.title), { type: 'success' })
|
||||
// OC.Notification.showTemporary(t('polls', 'Poll "%n" deleted', 1, poll.title), { type: 'success' })
|
||||
// })
|
||||
// .catch(error => {
|
||||
// this.loading = false
|
||||
// console.error('remove poll: ', error.response)
|
||||
// OC.Notification.showTemporary(t('polls', 'Error while deleting Poll "%n"', 1, event.title), { type: 'error' })
|
||||
// OC.Notification.showTemporary(t('polls', 'Error while deleting Poll "%n"', 1, poll.title), { type: 'error' })
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<template>
|
||||
<AppContent>
|
||||
<div v-if="event.id > 0" class="main-container">
|
||||
<div v-if="poll.id > 0" class="main-container">
|
||||
<a v-if="!sideBarOpen" href="#" class="icon icon-settings active"
|
||||
:title="t('polls', 'Open Sidebar')" @click="toggleSideBar()" />
|
||||
|
||||
|
@ -66,12 +66,12 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
||||
windowTitle: function() {
|
||||
return t('polls', 'Polls') + ' - ' + this.event.title
|
||||
return t('polls', 'Polls') + ' - ' + this.poll.title
|
||||
}
|
||||
|
||||
},
|
||||
|
@ -89,7 +89,7 @@ export default {
|
|||
methods: {
|
||||
loadPoll() {
|
||||
this.loading = false
|
||||
this.$store.dispatch('loadEvent', { token: this.$route.params.token })
|
||||
this.$store.dispatch('loadPollMain', { token: this.$route.params.token })
|
||||
.then((response) => {
|
||||
this.$store.dispatch('loadPoll', { token: this.$route.params.token })
|
||||
.then(() => {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<template>
|
||||
<AppContent>
|
||||
<div v-if="event.id > 0" class="main-container">
|
||||
<div v-if="poll.id > 0" class="main-container">
|
||||
<a v-if="!sideBarOpen" href="#" class="icon icon-settings active"
|
||||
:title="t('polls', 'Open Sidebar')" @click="toggleSideBar()" />
|
||||
<VoteHeader />
|
||||
|
@ -64,7 +64,7 @@ export default {
|
|||
|
||||
computed: {
|
||||
...mapState({
|
||||
event: state => state.event,
|
||||
poll: state => state.poll,
|
||||
shares: state => state.shares,
|
||||
acl: state => state.acl
|
||||
}),
|
||||
|
@ -74,13 +74,12 @@ export default {
|
|||
]),
|
||||
|
||||
windowTitle: function() {
|
||||
return t('polls', 'Polls') + ' - ' + this.event.title
|
||||
return t('polls', 'Polls') + ' - ' + this.poll.title
|
||||
},
|
||||
|
||||
votePossible() {
|
||||
return this.acl.allowVote && !this.expired
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
watch: {
|
||||
|
@ -88,9 +87,12 @@ export default {
|
|||
this.loadPoll()
|
||||
},
|
||||
|
||||
'event.id'(to, from) {
|
||||
'poll.id'(to, from) {
|
||||
this.$store.dispatch({ type: 'loadPoll', pollId: this.$route.params.id })
|
||||
.then(() => {
|
||||
if (this.acl.allowEdit && moment.unix(this.poll.created).diff() > -10000) {
|
||||
this.sideBarOpen = true
|
||||
}
|
||||
this.loading = false
|
||||
})
|
||||
}
|
||||
|
@ -102,8 +104,8 @@ export default {
|
|||
|
||||
methods: {
|
||||
loadPoll() {
|
||||
this.loading = true
|
||||
this.$store.dispatch({ type: 'loadEvent', pollId: this.$route.params.id })
|
||||
this.loading = false
|
||||
this.$store.dispatch({ type: 'loadPollMain', pollId: this.$route.params.id })
|
||||
.catch(() => {
|
||||
this.loading = false
|
||||
})
|
||||
|
@ -111,20 +113,6 @@ export default {
|
|||
|
||||
toggleSideBar() {
|
||||
this.sideBarOpen = !this.sideBarOpen
|
||||
},
|
||||
|
||||
openConfigurationTab() {
|
||||
this.initialTab = 'configuration'
|
||||
this.sideBarOpen = true
|
||||
},
|
||||
|
||||
openOptionsTab() {
|
||||
if (this.event.type === 'datePoll') {
|
||||
this.initialTab = 'date-options'
|
||||
} else if (this.event.type === 'textPoll') {
|
||||
this.initialTab = 'text-options'
|
||||
}
|
||||
this.sideBarOpen = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ class PageControllerTest extends UnitTestCase {
|
|||
$optionMapper = $this->getMockBuilder('OCA\Polls\Db\OptionMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper')
|
||||
$pollMapper = $this->getMockBuilder('OCA\Polls\Db\PollMapper')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$subscriptionMapper = $this->getMockBuilder('OCA\Polls\Db\SubscriptionMapper')
|
||||
|
@ -101,7 +101,7 @@ class PageControllerTest extends UnitTestCase {
|
|||
$this->userId,
|
||||
$commentMapper,
|
||||
$optionMapper,
|
||||
$eventMapper,
|
||||
$pollMapper,
|
||||
$subscriptionMapper,
|
||||
$voteMapper,
|
||||
$mailer
|
||||
|
|
|
@ -25,8 +25,8 @@ namespace OCA\Polls\Tests\Unit\Db;
|
|||
|
||||
use OCA\Polls\Db\Comment;
|
||||
use OCA\Polls\Db\CommentMapper;
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Tests\Unit\UnitTestCase;
|
||||
use OCP\IDBConnection;
|
||||
use League\FactoryMuffin\Faker\Facade as Faker;
|
||||
|
@ -37,8 +37,8 @@ class CommentMapperTest extends UnitTestCase {
|
|||
private $con;
|
||||
/** @var CommentMapper */
|
||||
private $commentMapper;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -47,7 +47,7 @@ class CommentMapperTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->commentMapper = new CommentMapper($this->con);
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
$this->pollMapper = new PollMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,13 +56,13 @@ class CommentMapperTest extends UnitTestCase {
|
|||
* @return Comment
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Polls\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
/** @var Poll $poll */
|
||||
$poll = $this->fm->instance('OCA\Polls\Db\Poll');
|
||||
$this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
|
||||
|
||||
/** @var Comment $comment */
|
||||
$comment = $this->fm->instance('OCA\Polls\Db\Comment');
|
||||
$comment->setPollId($event->getId());
|
||||
$comment->setPollId($poll->getId());
|
||||
$this->assertInstanceOf(Comment::class, $this->commentMapper->insert($comment));
|
||||
|
||||
return $comment;
|
||||
|
@ -90,8 +90,8 @@ class CommentMapperTest extends UnitTestCase {
|
|||
* @param Comment $comment
|
||||
*/
|
||||
public function testDelete(Comment $comment) {
|
||||
$event = $this->eventMapper->find($comment->getPollId());
|
||||
$poll = $this->pollMapper->find($comment->getPollId());
|
||||
$this->commentMapper->delete($comment);
|
||||
$this->eventMapper->delete($event);
|
||||
$this->pollMapper->delete($poll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
namespace OCA\Polls\Tests\Unit\Db;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Option;
|
||||
use OCA\Polls\Db\OptionMapper;
|
||||
use OCA\Polls\Tests\Unit\UnitTestCase;
|
||||
|
@ -37,8 +37,8 @@ class OptionMapperTest extends UnitTestCase {
|
|||
private $con;
|
||||
/** @var OptionMapper */
|
||||
private $optionMapper;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -47,7 +47,7 @@ class OptionMapperTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->optionMapper = new OptionMapper($this->con);
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
$this->pollMapper = new PollMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,13 +56,13 @@ class OptionMapperTest extends UnitTestCase {
|
|||
* @return Option
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Polls\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
/** @var Poll $poll */
|
||||
$poll = $this->fm->instance('OCA\Polls\Db\Poll');
|
||||
$this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
|
||||
|
||||
/** @var Option $option */
|
||||
$option = $this->fm->instance('OCA\Polls\Db\Option');
|
||||
$option->setPollId($event->getId());
|
||||
$option->setPollId($poll->getId());
|
||||
$this->assertInstanceOf(Option::class, $this->optionMapper->insert($option));
|
||||
|
||||
return $option;
|
||||
|
@ -90,8 +90,8 @@ class OptionMapperTest extends UnitTestCase {
|
|||
* @param Option $option
|
||||
*/
|
||||
public function testDelete(Option $option) {
|
||||
$event = $this->eventMapper->find($option->getPollId());
|
||||
$poll = $this->pollMapper->find($option->getPollId());
|
||||
$this->optionMapper->delete($option);
|
||||
$this->eventMapper->delete($event);
|
||||
$this->pollMapper->delete($poll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,18 +23,18 @@
|
|||
|
||||
namespace OCA\Polls\Tests\Unit\Db;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Tests\Unit\UnitTestCase;
|
||||
use OCP\IDBConnection;
|
||||
use League\FactoryMuffin\Faker\Facade as Faker;
|
||||
|
||||
class EventMapperTest extends UnitTestCase {
|
||||
class PollMapperTest extends UnitTestCase {
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $con;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -42,46 +42,46 @@ class EventMapperTest extends UnitTestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
$this->pollMapper = new PollMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create some fake data and persist them to the database.
|
||||
*
|
||||
* @return Event
|
||||
* @return Poll
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Polls\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
/** @var Poll $poll */
|
||||
$poll = $this->fm->instance('OCA\Polls\Db\Poll');
|
||||
$this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
|
||||
|
||||
return $event;
|
||||
return $poll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the previously created entry and persist the changes.
|
||||
*
|
||||
* @depends testCreate
|
||||
* @param Event $event
|
||||
* @return Event
|
||||
* @param Poll $poll
|
||||
* @return Poll
|
||||
*/
|
||||
public function testUpdate(Event $event) {
|
||||
public function testUpdate(Poll $poll) {
|
||||
$newTitle = Faker::sentence(10);
|
||||
$newDescription = Faker::paragraph();
|
||||
$event->setTitle($newTitle());
|
||||
$event->setDescription($newDescription());
|
||||
$this->eventMapper->update($event);
|
||||
$poll->setTitle($newTitle());
|
||||
$poll->setDescription($newDescription());
|
||||
$this->pollMapper->update($poll);
|
||||
|
||||
return $event;
|
||||
return $poll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the previously created entry from the database.
|
||||
*
|
||||
* @depends testUpdate
|
||||
* @param Event $event
|
||||
* @param Poll $poll
|
||||
*/
|
||||
public function testDelete(Event $event) {
|
||||
$this->eventMapper->delete($event);
|
||||
public function testDelete(Poll $poll) {
|
||||
$this->pollMapper->delete($poll);
|
||||
}
|
||||
}
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
namespace OCA\Polls\Tests\Unit\Db;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Subscription;
|
||||
use OCA\Polls\Db\SubscriptionMapper;
|
||||
use OCA\Polls\Tests\Unit\UnitTestCase;
|
||||
|
@ -37,8 +37,8 @@ class SubscriptionMapperTest extends UnitTestCase {
|
|||
private $con;
|
||||
/** @var SubscriptionMapper */
|
||||
private $subscriptionMapper;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -47,7 +47,7 @@ class SubscriptionMapperTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->subscriptionMapper = new SubscriptionMapper($this->con);
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
$this->pollMapper = new PollMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,13 +56,13 @@ class SubscriptionMapperTest extends UnitTestCase {
|
|||
* @return Subscription
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Polls\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
/** @var Poll $poll */
|
||||
$poll = $this->fm->instance('OCA\Polls\Db\Poll');
|
||||
$this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
|
||||
|
||||
/** @var Subscription $subscription */
|
||||
$subscription = $this->fm->instance('OCA\Polls\Db\Subscription');
|
||||
$subscription->setPollId($event->getId());
|
||||
$subscription->setPollId($poll->getId());
|
||||
$this->assertInstanceOf(Subscription::class, $this->subscriptionMapper->insert($subscription));
|
||||
|
||||
return $subscription;
|
||||
|
@ -90,8 +90,8 @@ class SubscriptionMapperTest extends UnitTestCase {
|
|||
* @param Subscription $subscription
|
||||
*/
|
||||
public function testDelete(Subscription $subscription) {
|
||||
$event = $this->eventMapper->find($subscription->getPollId());
|
||||
$poll = $this->pollMapper->find($subscription->getPollId());
|
||||
$this->subscriptionMapper->delete($subscription);
|
||||
$this->eventMapper->delete($event);
|
||||
$this->pollMapper->delete($poll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
namespace OCA\Polls\Tests\Unit\Db;
|
||||
|
||||
use OCA\Polls\Db\Event;
|
||||
use OCA\Polls\Db\EventMapper;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Vote;
|
||||
use OCA\Polls\Db\VoteMapper;
|
||||
use OCA\Polls\Tests\Unit\UnitTestCase;
|
||||
|
@ -37,8 +37,8 @@ class VoteMapperTest extends UnitTestCase {
|
|||
private $con;
|
||||
/** @var VoteMapper */
|
||||
private $voteMapper;
|
||||
/** @var EventMapper */
|
||||
private $eventMapper;
|
||||
/** @var PollMapper */
|
||||
private $pollMapper;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -47,7 +47,7 @@ class VoteMapperTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
$this->con = \OC::$server->getDatabaseConnection();
|
||||
$this->voteMapper = new VoteMapper($this->con);
|
||||
$this->eventMapper = new EventMapper($this->con);
|
||||
$this->pollMapper = new PollMapper($this->con);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,14 +56,14 @@ class VoteMapperTest extends UnitTestCase {
|
|||
* @return Vote
|
||||
*/
|
||||
public function testCreate() {
|
||||
/** @var Event $event */
|
||||
$event = $this->fm->instance('OCA\Polls\Db\Event');
|
||||
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
|
||||
/** @var Poll $poll */
|
||||
$poll = $this->fm->instance('OCA\Polls\Db\Poll');
|
||||
$this->assertInstanceOf(Poll::class, $this->pollMapper->insert($poll));
|
||||
|
||||
|
||||
/** @var Vote $vote */
|
||||
$vote = $this->fm->instance('OCA\Polls\Db\Vote');
|
||||
$vote->setPollId($event->getId());
|
||||
$vote->setPollId($poll->getId());
|
||||
$vote->setVoteOptionId(1);
|
||||
$this->assertInstanceOf(Vote::class, $this->voteMapper->insert($vote));
|
||||
|
||||
|
@ -92,8 +92,8 @@ class VoteMapperTest extends UnitTestCase {
|
|||
* @param Vote $vote
|
||||
*/
|
||||
public function testDelete(Vote $vote) {
|
||||
$event = $this->eventMapper->find($vote->getPollId());
|
||||
$poll = $this->pollMapper->find($vote->getPollId());
|
||||
$this->voteMapper->delete($vote);
|
||||
$this->eventMapper->delete($event);
|
||||
$this->pollMapper->delete($poll);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,5 +32,9 @@ $fm->define('OCA\Polls\Db\Comment')->setDefinitions([
|
|||
$date = new DateTime('today');
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
},
|
||||
'timestamp' => function() {
|
||||
$date = new DateTime('today');
|
||||
return $date->getTimestamp();
|
||||
},
|
||||
'comment' => Faker::text(255)
|
||||
]);
|
||||
|
|
|
@ -27,5 +27,6 @@ use League\FactoryMuffin\Faker\Facade as Faker;
|
|||
* General factory for the text model.
|
||||
*/
|
||||
$fm->define('OCA\Polls\Db\Option')->setDefinitions([
|
||||
'pollOptionText' => Faker::text(255)
|
||||
'pollOptionText' => Faker::text(255),
|
||||
'timestamp' => 0
|
||||
]);
|
||||
|
|
|
@ -24,27 +24,32 @@
|
|||
use League\FactoryMuffin\Faker\Facade as Faker;
|
||||
|
||||
/**
|
||||
* General factory for the event model.
|
||||
* General factory for the poll model.
|
||||
*/
|
||||
$fm->define('OCA\Polls\Db\Event')->setDefinitions([
|
||||
'type' => 0,
|
||||
$fm->define('OCA\Polls\Db\Poll')->setDefinitions([
|
||||
'type' => 'textPoll',
|
||||
'title' => Faker::sentence(10),
|
||||
'description' => Faker::text(255),
|
||||
'owner' => Faker::firstNameMale(),
|
||||
'created' => function() {
|
||||
$date = new DateTime('today');
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
return $date->getTimestamp();
|
||||
},
|
||||
'access' => 'registered',
|
||||
'expire' => function() {
|
||||
$date = new DateTime('tomorrow');
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
return $date->getTimestamp();
|
||||
},
|
||||
'isAnonymous' => 0,
|
||||
'fullAnonymous' => 0,
|
||||
'showResults' => 'always',
|
||||
'delete_date' => function() {
|
||||
'deleted' => function() {
|
||||
$date = new DateTime('+1 month');
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
return $date->getTimestamp();
|
||||
},
|
||||
'access' => 'public',
|
||||
'anonymous' => 0,
|
||||
'fullAnonymous' => 0,
|
||||
'allowMaybe' => 1,
|
||||
'options' => '["yes","no","maybe"]',
|
||||
'settings' => '{"someJSON":0}',
|
||||
'voteLimit' => 0,
|
||||
'showResults' => 'always',
|
||||
'adminAccess' => 0
|
||||
]);
|
Загрузка…
Ссылка в новой задаче