forms/lib/Db/Form.php

112 lines
3.1 KiB
PHP
Raw Normal View History

2019-05-14 01:15:45 +02:00
<?php
declare(strict_types=1);
2019-05-14 01:15:45 +02:00
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @author Kai Schröer <git@schroeer.co>
* @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\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method string getHash()
* @method void setHash(string $value)
2019-05-14 01:15:45 +02:00
* @method string getTitle()
* @method void setTitle(string $value)
* @method string getDescription()
* @method void setDescription(string $value)
* @method string getOwnerId()
* @method void setOwnerId(string $value)
* @method array getAccess()
* @method void setAccess(array $value)
* @method string getCreated()
* @method void setCreated(string $value)
* @method string getExpirationDate()
* @method void setExpirationDate(string $value)
2019-05-14 01:15:45 +02:00
* @method integer getIsAnonymous()
* @method void setIsAnonymous(bool $value)
* @method integer getSubmitOnce()
* @method void setSubmitOnce(bool $value)
2019-05-14 01:15:45 +02:00
*/
class Form extends Entity {
protected $hash;
2019-05-14 01:15:45 +02:00
protected $title;
protected $description;
protected $ownerId;
protected $accessJson;
protected $created;
protected $expirationDate;
2019-05-14 01:15:45 +02:00
protected $isAnonymous;
protected $submitOnce;
2019-05-14 01:15:45 +02:00
/**
* Form constructor.
2019-05-14 01:15:45 +02:00
*/
public function __construct() {
$this->addType('isAnonymous', 'bool');
$this->addType('submitOnce', 'bool');
2019-05-14 01:15:45 +02:00
}
/**
* JSON-Decoding of access-column.
*/
public function getAccess(): array {
return json_decode($this->getAccessJson(), true); // assoc=true, => Convert to associative Array
}
/**
* JSON-Encoding of access-column.
*/
public function setAccess(array $access) {
$this->setAccessJson(json_encode($access));
}
2019-05-14 01:15:45 +02:00
public function read() {
if ($this->getExpirationDate() === null) {
2019-05-14 01:15:45 +02:00
$expired = false;
$expires = false;
2019-05-14 01:15:45 +02:00
} else {
$expired = time() > strtotime($this->getExpirationDate());
$expires = true;
2019-05-14 01:15:45 +02:00
}
return [
'id' => $this->getId(),
'hash' => $this->getHash(),
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'ownerId' => $this->getOwnerId(),
'ownerDisplayName' => \OC_User::getDisplayName($this->getOwnerId()),
2019-05-14 01:15:45 +02:00
'created' => $this->getCreated(),
'access' => $this->getAccess(),
'expires' => $expires,
2019-05-14 01:15:45 +02:00
'expired' => $expired,
'expirationDate' => $this->getExpirationDate(),
2019-05-14 01:15:45 +02:00
'isAnonymous' => $this->getIsAnonymous(),
'submitOnce' => $this->getSubmitOnce()
2019-05-14 01:15:45 +02:00
];
}
}