2019-05-14 02:15:45 +03:00
|
|
|
<?php
|
2020-04-29 12:42:39 +03:00
|
|
|
|
2019-08-30 14:58:25 +03:00
|
|
|
declare(strict_types=1);
|
2020-04-29 12:42:39 +03:00
|
|
|
|
2019-05-14 02:15:45 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2019 Inigo Jiron <ijiron@terpmail.umd.edu>
|
|
|
|
*
|
2020-04-29 12:42:39 +03:00
|
|
|
* @author affan98 <affan98@gmail.com>
|
2021-01-20 11:50:49 +03:00
|
|
|
* @author Jan-Christoph Borchardt <hey@jancborchardt.net>
|
2020-04-29 12:42:39 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
|
|
* @author Jonas Rittershofer <jotoeri@users.noreply.github.com>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2021-01-20 11:50:49 +03:00
|
|
|
* @author Simon Vieille <simon@deblan.fr>
|
2019-05-14 02:15:45 +03:00
|
|
|
*
|
2021-11-30 23:08:26 +03:00
|
|
|
* @license AGPL-3.0-or-later
|
2019-05-14 02:15:45 +03:00
|
|
|
*
|
2020-04-29 12:42:39 +03:00
|
|
|
* 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 02:15:45 +03:00
|
|
|
*
|
2020-04-29 12:42:39 +03: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 02:15:45 +03:00
|
|
|
*
|
2020-04-29 12:42:39 +03: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 02:15:45 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Forms\Db;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Db\Entity;
|
|
|
|
|
|
|
|
/**
|
2024-08-09 00:10:01 +03:00
|
|
|
* @method int getFormId()
|
2019-05-14 02:15:45 +03:00
|
|
|
* @method void setFormId(integer $value)
|
2024-08-09 00:10:01 +03:00
|
|
|
* @method int getOrder()
|
2020-04-09 13:40:04 +03:00
|
|
|
* @method void setOrder(integer $value)
|
2020-03-30 14:48:14 +03:00
|
|
|
* @method string getType()
|
|
|
|
* @method void setType(string $value)
|
2023-03-21 18:46:35 +03:00
|
|
|
* @method bool getIsRequired()
|
|
|
|
* @method void setIsRequired(bool $value)
|
2020-03-30 14:48:14 +03:00
|
|
|
* @method string getText()
|
|
|
|
* @method void setText(string $value)
|
2022-04-15 00:38:10 +03:00
|
|
|
* @method string getDescription()
|
|
|
|
* @method void setDescription(string $value)
|
2023-03-13 22:55:00 +03:00
|
|
|
* @method string getName()
|
|
|
|
* @method void setName(string $value)
|
2019-05-14 02:15:45 +03:00
|
|
|
*/
|
2019-08-30 14:58:25 +03:00
|
|
|
class Question extends Entity {
|
2019-05-14 02:15:45 +03:00
|
|
|
protected $formId;
|
2020-04-09 13:40:04 +03:00
|
|
|
protected $order;
|
2020-03-30 14:48:14 +03:00
|
|
|
protected $type;
|
2021-04-07 00:32:00 +03:00
|
|
|
protected $isRequired;
|
2020-03-30 14:48:14 +03:00
|
|
|
protected $text;
|
2023-03-13 22:55:00 +03:00
|
|
|
protected $name;
|
2022-04-15 00:38:10 +03:00
|
|
|
protected $description;
|
2022-08-31 21:47:25 +03:00
|
|
|
protected $extraSettingsJson;
|
2019-05-14 02:15:45 +03:00
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
$this->addType('formId', 'integer');
|
2020-04-09 13:40:04 +03:00
|
|
|
$this->addType('order', 'integer');
|
2020-03-30 14:48:14 +03:00
|
|
|
$this->addType('type', 'string');
|
2024-10-22 22:13:27 +03:00
|
|
|
$this->addType('isRequired', 'boolean');
|
2020-03-30 14:48:14 +03:00
|
|
|
$this->addType('text', 'string');
|
2022-04-15 00:38:10 +03:00
|
|
|
$this->addType('description', 'string');
|
2023-03-13 22:55:00 +03:00
|
|
|
$this->addType('name', 'string');
|
2019-05-14 02:15:45 +03:00
|
|
|
}
|
|
|
|
|
2023-09-01 02:40:12 +03:00
|
|
|
public function getExtraSettings(): array {
|
|
|
|
return json_decode($this->getExtraSettingsJson() ?: '{}', true); // assoc=true, => Convert to associative Array
|
2022-08-31 21:47:25 +03:00
|
|
|
}
|
|
|
|
|
2023-10-28 16:48:44 +03:00
|
|
|
public function setExtraSettings(array $extraSettings) {
|
2023-09-01 02:40:12 +03:00
|
|
|
// Remove extraSettings that are not set
|
|
|
|
foreach ($extraSettings as $key => $value) {
|
|
|
|
if ($value === false) {
|
|
|
|
unset($extraSettings[$key]);
|
|
|
|
}
|
|
|
|
}
|
2024-03-29 02:37:21 +03:00
|
|
|
|
2022-08-31 21:47:25 +03:00
|
|
|
$this->setExtraSettingsJson(json_encode($extraSettings, JSON_FORCE_OBJECT));
|
|
|
|
}
|
|
|
|
|
2019-08-30 14:58:25 +03:00
|
|
|
public function read(): array {
|
2019-05-14 02:15:45 +03:00
|
|
|
return [
|
|
|
|
'id' => $this->getId(),
|
|
|
|
'formId' => $this->getFormId(),
|
2023-01-10 20:26:26 +03:00
|
|
|
'order' => (int)$this->getOrder(),
|
|
|
|
'type' => $this->getType(),
|
|
|
|
'isRequired' => (bool)$this->getIsRequired(),
|
|
|
|
'text' => (string)$this->getText(),
|
2023-03-13 22:55:00 +03:00
|
|
|
'name' => (string)$this->getName(),
|
2023-01-10 20:26:26 +03:00
|
|
|
'description' => (string)$this->getDescription(),
|
2022-08-31 21:47:25 +03:00
|
|
|
'extraSettings' => $this->getExtraSettings(),
|
2019-05-14 02:15:45 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|