Merge branch 'MDL-81457-main' of https://github.com/andrewnicols/moodle
[moodle.git] / customfield / classes / field.php
blob7ba3ffced349c7bad1f30a877394d9a72e15bdc0
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Field persistent class
20 * @package core_customfield
21 * @copyright 2018 Toni Barbera <toni@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_customfield;
27 use core\persistent;
29 defined('MOODLE_INTERNAL') || die;
31 /**
32 * Class field
34 * @package core_customfield
35 * @copyright 2018 Toni Barbera <toni@moodle.com>
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 class field extends persistent {
40 /**
41 * Database table.
43 const TABLE = 'customfield_field';
45 /**
46 * Return the definition of the properties of this model.
48 * @return array
50 protected static function define_properties(): array {
51 return array(
52 'name' => [
53 'type' => PARAM_TEXT,
55 'shortname' => [
56 'type' => PARAM_TEXT,
58 'type' => [
59 'type' => PARAM_PLUGIN,
61 'description' => [
62 'type' => PARAM_RAW,
63 'optional' => true,
64 'default' => null,
65 'null' => NULL_ALLOWED
67 'descriptionformat' => [
68 'type' => PARAM_INT,
69 'default' => FORMAT_MOODLE,
70 'optional' => true
72 'sortorder' => [
73 'type' => PARAM_INT,
74 'optional' => true,
75 'default' => -1,
77 'categoryid' => [
78 'type' => PARAM_INT
80 'configdata' => [
81 'type' => PARAM_RAW,
82 'optional' => true,
83 'default' => null,
84 'null' => NULL_ALLOWED
89 /**
90 * Get decoded configdata.
92 * @return array
94 protected function get_configdata(): array {
95 return json_decode($this->raw_get('configdata') ?? '', true) ?? array();