Merge pull request #23042 from eileenmcnaughton/sane
[civicrm-core.git] / CRM / Core / DAO / OptionGroup.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Core/OptionGroup.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:c9bc7ac897d9d7ef0bc421f6e58bdf27)
10 */
11
12 /**
13 * Database access object for the OptionGroup entity.
14 */
15 class CRM_Core_DAO_OptionGroup extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.5';
18
19 /**
20 * Static instance to hold the table name.
21 *
22 * @var string
23 */
24 public static $_tableName = 'civicrm_option_group';
25
26 /**
27 * Should CiviCRM log any modifications to this table in the civicrm_log table.
28 *
29 * @var bool
30 */
31 public static $_log = TRUE;
32
33 /**
34 * Option Group ID
35 *
36 * @var int|string|null
37 * (SQL type: int unsigned)
38 * Note that values will be retrieved from the database as a string.
39 */
40 public $id;
41
42 /**
43 * Option group name. Used as selection key by class properties which lookup options in civicrm_option_value.
44 *
45 * @var string
46 * (SQL type: varchar(64))
47 * Note that values will be retrieved from the database as a string.
48 */
49 public $name;
50
51 /**
52 * Option Group title.
53 *
54 * @var string|null
55 * (SQL type: varchar(255))
56 * Note that values will be retrieved from the database as a string.
57 */
58 public $title;
59
60 /**
61 * Option group description.
62 *
63 * @var string|null
64 * (SQL type: varchar(255))
65 * Note that values will be retrieved from the database as a string.
66 */
67 public $description;
68
69 /**
70 * Type of data stored by this option group.
71 *
72 * @var string|null
73 * (SQL type: varchar(128))
74 * Note that values will be retrieved from the database as a string.
75 */
76 public $data_type;
77
78 /**
79 * Is this a predefined system option group (i.e. it can not be deleted)?
80 *
81 * @var bool|string
82 * (SQL type: tinyint)
83 * Note that values will be retrieved from the database as a string.
84 */
85 public $is_reserved;
86
87 /**
88 * Is this option group active?
89 *
90 * @var bool|string
91 * (SQL type: tinyint)
92 * Note that values will be retrieved from the database as a string.
93 */
94 public $is_active;
95
96 /**
97 * A lock to remove the ability to add new options via the UI.
98 *
99 * @var bool|string
100 * (SQL type: tinyint)
101 * Note that values will be retrieved from the database as a string.
102 */
103 public $is_locked;
104
105 /**
106 * Which optional columns from the option_value table are in use by this group.
107 *
108 * @var string|null
109 * (SQL type: varchar(128))
110 * Note that values will be retrieved from the database as a string.
111 */
112 public $option_value_fields;
113
114 /**
115 * Class constructor.
116 */
117 public function __construct() {
118 $this->__table = 'civicrm_option_group';
119 parent::__construct();
120 }
121
122 /**
123 * Returns localized title of this entity.
124 *
125 * @param bool $plural
126 * Whether to return the plural version of the title.
127 */
128 public static function getEntityTitle($plural = FALSE) {
129 return $plural ? ts('Option Groups') : ts('Option Group');
130 }
131
132 /**
133 * Returns all the column names of this table
134 *
135 * @return array
136 */
137 public static function &fields() {
138 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
139 Civi::$statics[__CLASS__]['fields'] = [
140 'id' => [
141 'name' => 'id',
142 'type' => CRM_Utils_Type::T_INT,
143 'title' => ts('Option Group ID'),
144 'description' => ts('Option Group ID'),
145 'required' => TRUE,
146 'where' => 'civicrm_option_group.id',
147 'table_name' => 'civicrm_option_group',
148 'entity' => 'OptionGroup',
149 'bao' => 'CRM_Core_BAO_OptionGroup',
150 'localizable' => 0,
151 'html' => [
152 'type' => 'Number',
153 ],
154 'readonly' => TRUE,
155 'add' => '1.5',
156 ],
157 'name' => [
158 'name' => 'name',
159 'type' => CRM_Utils_Type::T_STRING,
160 'title' => ts('Option Group Name'),
161 'description' => ts('Option group name. Used as selection key by class properties which lookup options in civicrm_option_value.'),
162 'required' => TRUE,
163 'maxlength' => 64,
164 'size' => CRM_Utils_Type::BIG,
165 'where' => 'civicrm_option_group.name',
166 'table_name' => 'civicrm_option_group',
167 'entity' => 'OptionGroup',
168 'bao' => 'CRM_Core_BAO_OptionGroup',
169 'localizable' => 0,
170 'add' => '1.5',
171 ],
172 'title' => [
173 'name' => 'title',
174 'type' => CRM_Utils_Type::T_STRING,
175 'title' => ts('Option Group title'),
176 'description' => ts('Option Group title.'),
177 'maxlength' => 255,
178 'size' => CRM_Utils_Type::HUGE,
179 'where' => 'civicrm_option_group.title',
180 'table_name' => 'civicrm_option_group',
181 'entity' => 'OptionGroup',
182 'bao' => 'CRM_Core_BAO_OptionGroup',
183 'localizable' => 1,
184 'add' => '1.5',
185 ],
186 'description' => [
187 'name' => 'description',
188 'type' => CRM_Utils_Type::T_STRING,
189 'title' => ts('Option Group Description'),
190 'description' => ts('Option group description.'),
191 'maxlength' => 255,
192 'size' => CRM_Utils_Type::HUGE,
193 'where' => 'civicrm_option_group.description',
194 'table_name' => 'civicrm_option_group',
195 'entity' => 'OptionGroup',
196 'bao' => 'CRM_Core_BAO_OptionGroup',
197 'localizable' => 1,
198 'add' => '1.5',
199 ],
200 'data_type' => [
201 'name' => 'data_type',
202 'type' => CRM_Utils_Type::T_STRING,
203 'title' => ts('Data Type'),
204 'description' => ts('Type of data stored by this option group.'),
205 'maxlength' => 128,
206 'size' => CRM_Utils_Type::HUGE,
207 'where' => 'civicrm_option_group.data_type',
208 'table_name' => 'civicrm_option_group',
209 'entity' => 'OptionGroup',
210 'bao' => 'CRM_Core_BAO_OptionGroup',
211 'localizable' => 0,
212 'pseudoconstant' => [
213 'callback' => 'CRM_Utils_Type::dataTypes',
214 ],
215 'add' => '4.7',
216 ],
217 'is_reserved' => [
218 'name' => 'is_reserved',
219 'type' => CRM_Utils_Type::T_BOOLEAN,
220 'title' => ts('Option Group Is Reserved?'),
221 'description' => ts('Is this a predefined system option group (i.e. it can not be deleted)?'),
222 'required' => TRUE,
223 'where' => 'civicrm_option_group.is_reserved',
224 'default' => '1',
225 'table_name' => 'civicrm_option_group',
226 'entity' => 'OptionGroup',
227 'bao' => 'CRM_Core_BAO_OptionGroup',
228 'localizable' => 0,
229 'add' => '1.5',
230 ],
231 'is_active' => [
232 'name' => 'is_active',
233 'type' => CRM_Utils_Type::T_BOOLEAN,
234 'title' => ts('Option Group Is Active?'),
235 'description' => ts('Is this option group active?'),
236 'required' => TRUE,
237 'where' => 'civicrm_option_group.is_active',
238 'default' => '1',
239 'table_name' => 'civicrm_option_group',
240 'entity' => 'OptionGroup',
241 'bao' => 'CRM_Core_BAO_OptionGroup',
242 'localizable' => 0,
243 'add' => '1.5',
244 ],
245 'is_locked' => [
246 'name' => 'is_locked',
247 'type' => CRM_Utils_Type::T_BOOLEAN,
248 'title' => ts('Option Group Is Locked'),
249 'description' => ts('A lock to remove the ability to add new options via the UI.'),
250 'required' => TRUE,
251 'where' => 'civicrm_option_group.is_locked',
252 'default' => '0',
253 'table_name' => 'civicrm_option_group',
254 'entity' => 'OptionGroup',
255 'bao' => 'CRM_Core_BAO_OptionGroup',
256 'localizable' => 0,
257 'add' => '4.5',
258 ],
259 'option_value_fields' => [
260 'name' => 'option_value_fields',
261 'type' => CRM_Utils_Type::T_STRING,
262 'title' => ts('Option Value Fields'),
263 'description' => ts('Which optional columns from the option_value table are in use by this group.'),
264 'maxlength' => 128,
265 'size' => CRM_Utils_Type::HUGE,
266 'where' => 'civicrm_option_group.option_value_fields',
267 'default' => 'name,label,description',
268 'table_name' => 'civicrm_option_group',
269 'entity' => 'OptionGroup',
270 'bao' => 'CRM_Core_BAO_OptionGroup',
271 'localizable' => 0,
272 'serialize' => self::SERIALIZE_COMMA,
273 'pseudoconstant' => [
274 'callback' => 'CRM_Core_SelectValues::optionValueFields',
275 ],
276 'add' => '5.49',
277 ],
278 ];
279 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
280 }
281 return Civi::$statics[__CLASS__]['fields'];
282 }
283
284 /**
285 * Return a mapping from field-name to the corresponding key (as used in fields()).
286 *
287 * @return array
288 * Array(string $name => string $uniqueName).
289 */
290 public static function &fieldKeys() {
291 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
292 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
293 }
294 return Civi::$statics[__CLASS__]['fieldKeys'];
295 }
296
297 /**
298 * Returns the names of this table
299 *
300 * @return string
301 */
302 public static function getTableName() {
303 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
304 }
305
306 /**
307 * Returns if this table needs to be logged
308 *
309 * @return bool
310 */
311 public function getLog() {
312 return self::$_log;
313 }
314
315 /**
316 * Returns the list of fields that can be imported
317 *
318 * @param bool $prefix
319 *
320 * @return array
321 */
322 public static function &import($prefix = FALSE) {
323 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'option_group', $prefix, []);
324 return $r;
325 }
326
327 /**
328 * Returns the list of fields that can be exported
329 *
330 * @param bool $prefix
331 *
332 * @return array
333 */
334 public static function &export($prefix = FALSE) {
335 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'option_group', $prefix, []);
336 return $r;
337 }
338
339 /**
340 * Returns the list of indices
341 *
342 * @param bool $localize
343 *
344 * @return array
345 */
346 public static function indices($localize = TRUE) {
347 $indices = [
348 'UI_name' => [
349 'name' => 'UI_name',
350 'field' => [
351 0 => 'name',
352 ],
353 'localizable' => FALSE,
354 'unique' => TRUE,
355 'sig' => 'civicrm_option_group::1::name',
356 ],
357 ];
358 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
359 }
360
361 }