Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordartcafe <github@dartcafe.de>2020-05-12 09:40:17 +0300
committerdartcafe <github@dartcafe.de>2020-05-12 09:40:17 +0300
commit36aeee5fcf18325df29b051df1a97294b409d9b3 (patch)
tree22641f7bf7b1b015a338aae78e40b167d99a742e /lib
parent67f3a94ae2ac518e4e39c8f9561b8de2e757dd0c (diff)
confirm options after expiry
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/OptionController.php16
-rw-r--r--lib/Db/Option.php14
-rw-r--r--lib/Migration/Version0105Date20200508211943.php78
3 files changed, 107 insertions, 1 deletions
diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php
index 1686c555..1b3309b0 100644
--- a/lib/Controller/OptionController.php
+++ b/lib/Controller/OptionController.php
@@ -27,6 +27,7 @@ use Exception;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IRequest;
+use OCP\ILogger;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
@@ -48,6 +49,7 @@ class OptionController extends Controller {
private $groupManager;
private $pollMapper;
+ private $logger;
private $logService;
private $acl;
@@ -56,6 +58,7 @@ class OptionController extends Controller {
* @param string $appName
* @param $UserId
* @param IRequest $request
+ * @param ILogger $logger
* @param OptionMapper $optionMapper
* @param IGroupManager $groupManager
* @param PollMapper $pollMapper
@@ -70,6 +73,7 @@ class OptionController extends Controller {
OptionMapper $optionMapper,
IGroupManager $groupManager,
PollMapper $pollMapper,
+ ILogger $logger,
LogService $logService,
Acl $acl
) {
@@ -78,6 +82,7 @@ class OptionController extends Controller {
$this->optionMapper = $optionMapper;
$this->groupManager = $groupManager;
$this->pollMapper = $pollMapper;
+ $this->logger = $logger;
$this->logService = $logService;
$this->acl = $acl;
}
@@ -170,6 +175,7 @@ class OptionController extends Controller {
public function update($option) {
try {
+ $this->logger->alert(json_encode($option));
$updateOption = $this->optionMapper->find($option['id']);
if (!$this->acl->setPollId($option['pollId'])->getAllowEdit()) {
@@ -185,6 +191,16 @@ class OptionController extends Controller {
$updateOption->setOrder($option['timestamp']);
}
+ if ($option['confirmed']) {
+ // do not update confirmation date, if option is already confirmed
+ if (!$updateOption->setConfirmed()){
+ $updateOption->setConfirmed(time());
+ }
+
+ } else {
+ $updateOption->setConfirmed(0);
+ }
+
$this->optionMapper->update($updateOption);
$this->logService->setLog($option['pollId'], 'updateOption');
diff --git a/lib/Db/Option.php b/lib/Db/Option.php
index f8c442ac..70c63d4e 100644
--- a/lib/Db/Option.php
+++ b/lib/Db/Option.php
@@ -40,6 +40,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setTimestamp(integer $value)
* @method integer getOrder()
* @method void setOrder(integer $value)
+ * @method integer getConfirmed()
+ * @method void setConfirmed(integer $value)
*/
class Option extends Entity implements JsonSerializable {
@@ -55,6 +57,9 @@ class Option extends Entity implements JsonSerializable {
/** @var int $order */
protected $order;
+ /** @var int $confirmed */
+ protected $confirmed;
+
public function jsonSerialize() {
if (intval($this->timestamp) > 0) {
$timestamp = $this->timestamp;
@@ -69,7 +74,14 @@ class Option extends Entity implements JsonSerializable {
'pollId' => intval($this->pollId),
'pollOptionText' => htmlspecialchars_decode($this->pollOptionText),
'timestamp' => intval($timestamp),
- 'order' => $this->setOrder(intval($this->timestamp), intval($this->order))
+ 'order' => $this->setOrder(intval($this->timestamp), intval($this->order)),
+ 'confirmed' => intval($this->confirmed),
+ 'no' => 0,
+ 'yes' => 0,
+ 'maybe' => 0,
+ 'realno' => 0,
+ 'rank' => 0,
+ 'votes' => 0,
];
}
diff --git a/lib/Migration/Version0105Date20200508211943.php b/lib/Migration/Version0105Date20200508211943.php
new file mode 100644
index 00000000..cafee187
--- /dev/null
+++ b/lib/Migration/Version0105Date20200508211943.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 René Gieling <github@dartcafe.de>
+ *
+ * @author René Gieling <github@dartcafe.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Polls\Migration;
+
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\ISchemaWrapper;
+use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IConfig;
+use OCP\IDBConnection;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+/**
+ * Installation class for the polls app.
+ * Initial db creation
+ */
+class Version0105Date20200508211943 extends SimpleMigrationStep {
+
+ /** @var IDBConnection */
+ protected $connection;
+
+ /** @var IConfig */
+ protected $config;
+
+ /**
+ * @param IDBConnection $connection
+ * @param IConfig $config
+ */
+ public function __construct(IDBConnection $connection, IConfig $config) {
+ $this->connection = $connection;
+ $this->config = $config;
+ }
+
+ /**
+ * @param IOutput $output
+ * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ * @since 13.0.0
+ */
+ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+ if ($schema->hasTable('polls_options')) {
+ $table = $schema->getTable('polls_options');
+ if (!$table->hasColumn('confirmed')) {
+ $table->addColumn('confirmed', Type::INTEGER, [
+ 'length' => 11,
+ 'notnull' => true,
+ 'default' => 0
+ ]);
+ }
+ }
+
+ return $schema;
+ }
+}