This commit is contained in:
dartcafe 2018-12-28 22:33:31 +01:00
Родитель 4b4599c49c
Коммит c76b51d26b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
14 изменённых файлов: 1460 добавлений и 125 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -25,10 +25,10 @@ namespace OCA\Polls\AppInfo;
use OCA\Polls\Controller\PageController;
use OCA\Polls\Db\CommentMapper;
use OCA\Polls\Db\OptionsMapper;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\EventMapper;
use OCA\Polls\Db\NotificationMapper;
use OCA\Polls\Db\VotesMapper;
use OCA\Polls\Db\VoteMapper;
use OCP\AppFramework\App;
use OCP\IContainer;

Просмотреть файл

@ -37,10 +37,10 @@ use OCP\Security\ISecureRandom;
use OCA\Polls\Db\Event;
use OCA\Polls\Db\EventMapper;
use OCA\Polls\Db\Options;
use OCA\Polls\Db\OptionsMapper;
use OCA\Polls\Db\Votes;
use OCA\Polls\Db\VotesMapper;
use OCA\Polls\Db\Option;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\Vote;
use OCA\Polls\Db\VoteMapper;
use OCA\Polls\Db\Comment;
use OCA\Polls\Db\CommentMapper;
@ -49,8 +49,8 @@ use OCA\Polls\Db\CommentMapper;
class ApiController extends Controller {
private $eventMapper;
private $optionsMapper;
private $votesMapper;
private $optionMapper;
private $voteMapper;
private $commentMapper;
private $systemConfig;
@ -60,8 +60,8 @@ class ApiController extends Controller {
* @param IRequest $request
* @param string $userId
* @param EventMapper $eventMapper
* @param OptionsMapper $optionsMapper
* @param VotesMapper $VotesMapper
* @param OptionMapper $optionMapper
* @param VoteMapper $VoteMapper
* @param CommentMapper $CommentMapper
*/
public function __construct(
@ -72,8 +72,8 @@ class ApiController extends Controller {
IUserManager $userManager,
$userId,
EventMapper $eventMapper,
OptionsMapper $optionsMapper,
VotesMapper $VotesMapper,
OptionMapper $optionMapper,
VoteMapper $VoteMapper,
CommentMapper $CommentMapper
) {
parent::__construct($appName, $request);
@ -82,8 +82,8 @@ class ApiController extends Controller {
$this->systemConfig = $systemConfig;
$this->userManager = $userManager;
$this->eventMapper = $eventMapper;
$this->optionsMapper = $optionsMapper;
$this->votesMapper = $VotesMapper;
$this->optionMapper = $optionMapper;
$this->voteMapper = $VoteMapper;
$this->commentMapper = $CommentMapper;
}
@ -166,9 +166,9 @@ class ApiController extends Controller {
*/
public function getOptions($pollId) {
$optionList = array();
$options = $this->optionsMapper->findByPoll($pollId);
$options = $this->optionMapper->findByPoll($pollId);
foreach ($options as $optionElement) {
$optionList[$optionElement->getId()] = [
$optionList[] = [
'id' => $optionElement->getId(),
'text' => htmlspecialchars_decode($optionElement->getPollOptionText()),
'timestamp' => $optionElement->getTimestamp()
@ -187,9 +187,9 @@ class ApiController extends Controller {
*/
public function getVotes($pollId) {
$votesList = array();
$votes = $this->votesMapper->findByPoll($pollId);
$votes = $this->voteMapper->findByPoll($pollId);
foreach ($votes as $voteElement) {
$votesList[$voteElement->getId()] = [
$votesList[] = [
'id' => $voteElement->getId(),
'userId' => $voteElement->getUserId(),
'voteOptionId' => $voteElement->getVoteOptionId(),
@ -212,7 +212,7 @@ class ApiController extends Controller {
$commentsList = array();
$comments = $this->commentMapper->findByPoll($pollId);
foreach ($comments as $commentElement) {
$commentsList[$commentElement->getId()] = [
$commentsList[] = [
'id' => $commentElement->getId(),
'userId' => $commentElement->getUserId(),
'date' => $commentElement->getDt() . ' UTC',
@ -377,15 +377,15 @@ class ApiController extends Controller {
$data['poll'] = [
'result' => $result,
'grantedAs' => $this->grantAccessAs($pollId),
'grantedAs' => $this->grantAccessAs($event['id']),
'mode' => $mode,
'comments' => $this->getComments($pollId),
'votes' => $this->getVotes($pollId),
'shares' => $this->getShares($pollId),
'event' => $event,
'comments' => $this->getComments($event['id']),
'votes' => $this->getVotes($event['id']),
'shares' => $this->getShares($event['id']),
'options' => [
'pollDates' => [],
'pollTexts' => $this->getOptions($pollId)
'pollTexts' => $this->getOptions($event['id'])
]
];
}
@ -541,7 +541,7 @@ class ApiController extends Controller {
$newEvent->setHash($oldPoll->getHash());
$newEvent->setId($oldPoll->getId());
$this->eventMapper->update($newEvent);
$this->optionsMapper->deleteByPoll($newEvent->getId());
$this->optionMapper->deleteByPoll($newEvent->getId());
} elseif ($mode === 'create') {
// Create new poll
@ -560,22 +560,22 @@ class ApiController extends Controller {
// Update options
if ($event['type'] === 'datePoll') {
foreach ($options['pollDates'] as $optionElement) {
$newOption = new Options();
$newOption = new Option();
$newOption->setPollId($newEvent->getId());
$newOption->setPollOptionText(date('Y-m-d H:i:s', $optionElement['timestamp']));
$newOption->setTimestamp($optionElement['timestamp']);
$this->optionsMapper->insert($newOption);
$this->optionMapper->insert($newOption);
}
} elseif ($event['type'] === "textPoll") {
foreach ($options['pollTexts'] as $optionElement) {
$newOption = new Options();
$newOption = new Option();
$newOption->setPollId($newEvent->getId());
$newOption->setpollOptionText(trim(htmlspecialchars($optionElement['text'])));
$this->optionsMapper->insert($newOption);
$this->optionMapper->insert($newOption);
}
}

Просмотреть файл

@ -29,10 +29,10 @@ use OCA\Polls\Db\Event;
use OCA\Polls\Db\EventMapper;
use OCA\Polls\Db\Notification;
use OCA\Polls\Db\NotificationMapper;
use OCA\Polls\Db\Options;
use OCA\Polls\Db\OptionsMapper;
use OCA\Polls\Db\Votes;
use OCA\Polls\Db\VotesMapper;
use OCA\Polls\Db\Option;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Db\Vote;
use OCA\Polls\Db\VoteMapper;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\ContentSecurityPolicy;
@ -61,8 +61,8 @@ class PageController extends Controller {
private $commentMapper;
private $eventMapper;
private $notificationMapper;
private $optionsMapper;
private $votesMapper;
private $optionMapper;
private $voteMapper;
private $urlGenerator;
private $userMgr;
private $avatarManager;
@ -86,10 +86,10 @@ class PageController extends Controller {
* @param IURLGenerator $urlGenerator
* @param string $userId
* @param CommentMapper $commentMapper
* @param OptionsMapper $optionsMapper
* @param OptionMapper $optionMapper
* @param EventMapper $eventMapper
* @param NotificationMapper $notificationMapper
* @param VotesMapper $VotesMapper
* @param VoteMapper $VoteMapper
* @param IMailer $mailer
*/
public function __construct(
@ -105,10 +105,10 @@ class PageController extends Controller {
IURLGenerator $urlGenerator,
$userId,
CommentMapper $commentMapper,
OptionsMapper $optionsMapper,
OptionMapper $optionMapper,
EventMapper $eventMapper,
NotificationMapper $notificationMapper,
VotesMapper $VotesMapper,
VoteMapper $VoteMapper,
IMailer $mailer
) {
parent::__construct($appName, $request);
@ -123,10 +123,10 @@ class PageController extends Controller {
$this->urlGenerator = $urlGenerator;
$this->userId = $userId;
$this->commentMapper = $commentMapper;
$this->optionsMapper = $optionsMapper;
$this->optionMapper = $optionMapper;
$this->eventMapper = $eventMapper;
$this->notificationMapper = $notificationMapper;
$this->votesMapper = $VotesMapper;
$this->voteMapper = $VoteMapper;
$this->mailer = $mailer;
}
@ -137,7 +137,7 @@ class PageController extends Controller {
public function index() {
$polls = $this->eventMapper->findAllForUserWithInfo($this->userId);
$comments = $this->commentMapper->findDistinctByUser($this->userId);
$votes = $this->votesMapper->findDistinctByUser($this->userId);
$votes = $this->voteMapper->findDistinctByUser($this->userId);
$response = new TemplateResponse('polls', 'main.tmpl', [
'polls' => $polls,
'comments' => $comments,
@ -229,9 +229,9 @@ class PageController extends Controller {
} catch (DoesNotExistException $e) {
return new TemplateResponse('polls', 'no.acc.tmpl', []);
}
$options = $this->optionsMapper->findByPoll($poll->getId());
$votes = $this->votesMapper->findByPoll($poll->getId());
$participants = $this->votesMapper->findParticipantsByPoll($poll->getId());
$options = $this->optionMapper->findByPoll($poll->getId());
$votes = $this->voteMapper->findByPoll($poll->getId());
$participants = $this->voteMapper->findParticipantsByPoll($poll->getId());
$comments = $this->commentMapper->findByPoll($poll->getId());
try {
@ -272,8 +272,8 @@ class PageController extends Controller {
$poll = new Event();
$poll->setId($pollId);
$this->commentMapper->deleteByPoll($pollId);
$this->votesMapper->deleteByPoll($pollId);
$this->optionsMapper->deleteByPoll($pollId);
$this->voteMapper->deleteByPoll($pollId);
$this->optionMapper->deleteByPoll($pollId);
$this->eventMapper->delete($poll);
$url = $this->urlGenerator->linkToRoute('polls.page.index');
return new RedirectResponse($url);
@ -342,15 +342,15 @@ class PageController extends Controller {
$options = json_decode($options);
$answers = json_decode($answers);
$count_options = count($options);
$this->votesMapper->deleteByPollAndUser($pollId, $userId);
$this->voteMapper->deleteByPollAndUser($pollId, $userId);
for ($i = 0; $i < $count_options; $i++) {
$vote = new Votes();
$vote = new Vote();
$vote->setPollId($pollId);
$vote->setUserId($userId);
$vote->setVoteOptionText(htmlspecialchars($options[$i]));
$vote->setVoteAnswer($answers[$i]);
$this->votesMapper->insert($vote);
$this->voteMapper->insert($vote);
}
$this->sendNotifications($pollId, $userId);

Просмотреть файл

@ -31,20 +31,19 @@ use OCP\AppFramework\Db\Entity;
* @method void setPollId(integer $value)
* @method string getPollOptionText()
* @method void setPollOptionText(string $value)
* @method string getTimestamp()
* @method void setTimestamp(Integer $value)
* @method integer getTimestamp()
* @method void setTimestamp(integer $value)
*/
class Options extends Model {
class Option extends Model {
protected $pollId;
protected $pollOptionText;
protected $timestamp;
/**
* Options constructor.
* Option constructor.
*/
public function __construct() {
$this->addType('pollId', 'integer');
$this->addType('pollOptionText', 'string');
$this->addType('timestamp', 'integer');
}
}

Просмотреть файл

@ -26,21 +26,21 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
class OptionsMapper extends Mapper {
class OptionMapper extends Mapper {
/**
* TextMapper constructor.
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
parent::__construct($db, 'polls_options', '\OCA\Polls\Db\Options');
parent::__construct($db, 'polls_options', '\OCA\Polls\Db\Option');
}
/**
* @param Integer $pollId
* @param Integer $limit
* @param Integer $offset
* @return Options[]
* @return Option[]
*/
public function findByPoll($pollId, $limit = null, $offset = null) {
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';

Просмотреть файл

@ -33,12 +33,12 @@ use OCP\AppFramework\Db\Entity;
* @method void setUserId(string $value)
* @method integer getVoteOptionId()
* @method void setVoteOptionId(integer $value)
* @method integer getVoteOptionText()
* @method string getVoteOptionText()
* @method void setVoteOptionText(string $value)
* @method integer getVoteAnswer()
* @method string getVoteAnswer()
* @method void setVoteAnswer(string $value)
*/
class Votes extends Model {
class Vote extends Model {
protected $pollId;
protected $userId;
protected $voteOptionId;
@ -50,6 +50,6 @@ class Votes extends Model {
*/
public function __construct() {
$this->addType('pollId', 'integer');
$this->addType('vote_type', 'integer');
$this->addType('voteOptionId', 'integer');
}
}

Просмотреть файл

@ -26,21 +26,21 @@ namespace OCA\Polls\Db;
use OCP\AppFramework\Db\Mapper;
use OCP\IDBConnection;
class VotesMapper extends Mapper {
class VoteMapper extends Mapper {
/**
* VotesMapper constructor.
* VoteMapper constructor.
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
parent::__construct($db, 'polls_votes', '\OCA\Polls\Db\Votes');
parent::__construct($db, 'polls_votes', '\OCA\Polls\Db\Vote');
}
/**
* @param string $userId
* @param int $limit
* @param int $offset
* @return Votes[]
* @return Vote[]
*/
public function findDistinctByUser($userId, $limit = null, $offset = null) {
$sql = 'SELECT DISTINCT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
@ -51,7 +51,7 @@ class VotesMapper extends Mapper {
* @param int $pollId
* @param int $limit
* @param int $offset
* @return Votes[]
* @return Vote[]
*/
public function findByPoll($pollId, $limit = null, $offset = null) {
$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE poll_id = ?';
@ -62,7 +62,7 @@ class VotesMapper extends Mapper {
* @param int $pollId
* @param int $limit
* @param int $offset
* @return Votes[]
* @return Vote[]
*/
public function findParticipantsByPoll($pollId, $limit = null, $offset = null) {
$sql = 'SELECT DISTINCT user_id FROM ' . $this->getTableName() . ' WHERE poll_id = ?';

Просмотреть файл

@ -45,9 +45,9 @@
$avaMgr = $_['avatarManager'];
/** @var \OCA\Polls\Db\Event $poll */
$poll = $_['poll'];
/** @var OCA\Polls\Db\Options[] $options */
/** @var OCA\Polls\Db\Option[] $options */
$options = $_['options'];
/** @var OCA\Polls\Db\Votes[] $votes */
/** @var OCA\Polls\Db\Vote[] $votes */
$votes = $_['votes'];
/** @var \OCA\Polls\Db\Comment[] $comments */
$comments = $_['comments'];

Просмотреть файл

@ -74,7 +74,7 @@ class PageControllerTest extends UnitTestCase {
$commentMapper = $this->getMockBuilder('OCA\Polls\Db\CommentMapper')
->disableOriginalConstructor()
->getMock();
$optionsMapper = $this->getMockBuilder('OCA\Polls\Db\OptionsMapper')
$optionMapper = $this->getMockBuilder('OCA\Polls\Db\OptionMapper')
->disableOriginalConstructor()
->getMock();
$eventMapper = $this->getMockBuilder('OCA\Polls\Db\EventMapper')
@ -83,7 +83,7 @@ class PageControllerTest extends UnitTestCase {
$notificationMapper = $this->getMockBuilder('OCA\Polls\Db\NotificationMapper')
->disableOriginalConstructor()
->getMock();
$votesMapper = $this->getMockBuilder('OCA\Polls\Db\VotesMapper')
$voteMapper = $this->getMockBuilder('OCA\Polls\Db\VoteMapper')
->disableOriginalConstructor()
->getMock();
@ -100,10 +100,10 @@ class PageControllerTest extends UnitTestCase {
$urlGenerator,
$this->userId,
$commentMapper,
$optionsMapper,
$optionMapper,
$eventMapper,
$notificationMapper,
$votesMapper,
$voteMapper,
$mailer
);
}

Просмотреть файл

@ -25,18 +25,18 @@ namespace OCA\Polls\Tests\Unit\Db;
use OCA\Polls\Db\Event;
use OCA\Polls\Db\EventMapper;
use OCA\Polls\Db\Options;
use OCA\Polls\Db\OptionsMapper;
use OCA\Polls\Db\Option;
use OCA\Polls\Db\OptionMapper;
use OCA\Polls\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
class OptionsMapperTest extends UnitTestCase {
class OptionMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
/** @var OptionsMapper */
private $optionsMapper;
/** @var OptionMapper */
private $optionMapper;
/** @var EventMapper */
private $eventMapper;
@ -46,52 +46,52 @@ class OptionsMapperTest extends UnitTestCase {
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
$this->optionsMapper = new OptionsMapper($this->con);
$this->optionMapper = new OptionMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
* @return Options
* @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 Options $options */
$options = $this->fm->instance('OCA\Polls\Db\Options');
$options->setPollId($event->getId());
$this->assertInstanceOf(Options::class, $this->optionsMapper->insert($options));
/** @var Option $option */
$option = $this->fm->instance('OCA\Polls\Db\Option');
$option->setPollId($event->getId());
$this->assertInstanceOf(Option::class, $this->optionMapper->insert($option));
return $options;
return $option;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
* @param Options $options
* @return Options
* @param Option $option
* @return Option
*/
public function testUpdate(Options $options) {
public function testUpdate(Option $option) {
$newPollOptionText = Faker::paragraph();
$options->setPollOptionText($newPollOptionText());
$this->optionsMapper->update($options);
$option->setPollOptionText($newPollOptionText());
$this->optionMapper->update($option);
return $options;
return $option;
}
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
* @param Options $options
* @param Option $option
*/
public function testDelete(Options $options) {
$event = $this->eventMapper->find($options->getPollId());
$this->optionsMapper->delete($options);
public function testDelete(Option $option) {
$event = $this->eventMapper->find($option->getPollId());
$this->optionMapper->delete($option);
$this->eventMapper->delete($event);
}
}

Просмотреть файл

@ -25,18 +25,18 @@ namespace OCA\Polls\Tests\Unit\Db;
use OCA\Polls\Db\Event;
use OCA\Polls\Db\EventMapper;
use OCA\Polls\Db\Votes;
use OCA\Polls\Db\VotesMapper;
use OCA\Polls\Db\Vote;
use OCA\Polls\Db\VoteMapper;
use OCA\Polls\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
class VotesMapperTest extends UnitTestCase {
class VoteMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
/** @var VotesMapper */
private $votesMapper;
/** @var VoteMapper */
private $voteMapper;
/** @var EventMapper */
private $eventMapper;
@ -46,54 +46,54 @@ class VotesMapperTest extends UnitTestCase {
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
$this->votesMapper = new VotesMapper($this->con);
$this->voteMapper = new VoteMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
* @return Votes
* @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 Votes $votes */
$votes = $this->fm->instance('OCA\Polls\Db\Votes');
$votes->setPollId($event->getId());
$votes->setVoteOptionId(1);
$this->assertInstanceOf(Votes::class, $this->votesMapper->insert($votes));
return $votes;
/** @var Vote $vote */
$vote = $this->fm->instance('OCA\Polls\Db\Vote');
$vote->setPollId($event->getId());
$vote->setVoteOptionId(1);
$this->assertInstanceOf(Vote::class, $this->voteMapper->insert($vote));
return $vote;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
* @param Votes $votes
* @return Votes
* @param Vote $vote
* @return Vote
*/
public function testUpdate(Votes $votes) {
public function testUpdate(Vote $vote) {
$newVoteOptionText = Faker::date('Y-m-d H:i:s');
$votes->setVoteOptionText($newVoteOptionText());
$this->votesMapper->update($votes);
$vote->setVoteOptionText($newVoteOptionText());
$this->voteMapper->update($vote);
return $votes;
return $vote;
}
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
* @param Votes $votes
* @param Vote $vote
*/
public function testDelete(Votes $votes) {
$event = $this->eventMapper->find($votes->getPollId());
$this->votesMapper->delete($votes);
public function testDelete(Vote $vote) {
$event = $this->eventMapper->find($vote->getPollId());
$this->voteMapper->delete($vote);
$this->eventMapper->delete($event);
}
}

Просмотреть файл

@ -26,6 +26,6 @@ use League\FactoryMuffin\Faker\Facade as Faker;
/**
* General factory for the text model.
*/
$fm->define('OCA\Polls\Db\Options')->setDefinitions([
$fm->define('OCA\Polls\Db\Option')->setDefinitions([
'pollOptionText' => Faker::text(255)
]);

Просмотреть файл

@ -24,9 +24,9 @@
use League\FactoryMuffin\Faker\Facade as Faker;
/**
* General factory for the votes model.
* General factory for the vote model.
*/
$fm->define('OCA\Polls\Db\Votes')->setDefinitions([
$fm->define('OCA\Polls\Db\Vote')->setDefinitions([
'voteOptionText' => Faker::text(255),
'userId' => Faker::firstNameMale(),
'voteAnswer' => 'yes'