forms/lib/Db/Form.php

99 lines
2.8 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 affan98 <affan98@gmail.com>
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
*
2019-05-14 01:15:45 +02:00
* @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.
2019-05-14 01:15:45 +02:00
*
* 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.
2019-05-14 01:15:45 +02:00
*
* 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/>.
2019-05-14 01:15:45 +02:00
*
*/
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 integer getCreated()
* @method void setCreated(integer $value)
* @method integer getExpires()
* @method void setExpires(integer $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 $expires;
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('created', 'integer');
$this->addType('expires', 'integer');
$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));
}
// Read full form
public function read() {
2019-05-14 01:15:45 +02:00
return [
'id' => $this->getId(),
'hash' => $this->getHash(),
'title' => $this->getTitle(),
'description' => $this->getDescription(),
'ownerId' => $this->getOwnerId(),
2019-05-14 01:15:45 +02:00
'created' => $this->getCreated(),
'access' => $this->getAccess(),
'expires' => $this->getExpires(),
2019-05-14 01:15:45 +02:00
'isAnonymous' => $this->getIsAnonymous(),
'submitOnce' => $this->getSubmitOnce()
2019-05-14 01:15:45 +02:00
];
}
}