c8a2a3eb473c879ca862159b0483d1fbf91d2e4b
[civicrm-core.git] / CRM / Contact / DAO / Group.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Contact/Group.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:8ac9c70cfe18b05911b2c6d85e8c522d)
10 */
11
12 /**
13 * Database access object for the Group entity.
14 */
15 class CRM_Contact_DAO_Group extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '1.1';
18
19 /**
20 * Static instance to hold the table name.
21 *
22 * @var string
23 */
24 public static $_tableName = 'civicrm_group';
25
26 /**
27 * Icon associated with this entity.
28 *
29 * @var string
30 */
31 public static $_icon = 'fa-users';
32
33 /**
34 * Field to show when displaying a record.
35 *
36 * @var string
37 */
38 public static $_labelField = 'title';
39
40 /**
41 * Should CiviCRM log any modifications to this table in the civicrm_log table.
42 *
43 * @var bool
44 */
45 public static $_log = TRUE;
46
47 /**
48 * Paths for accessing this entity in the UI.
49 *
50 * @var string[]
51 */
52 protected static $_paths = [
53 'add' => 'civicrm/group/add?reset=1',
54 ];
55
56 /**
57 * Group ID
58 *
59 * @var int
60 */
61 public $id;
62
63 /**
64 * Internal name of Group.
65 *
66 * @var string
67 */
68 public $name;
69
70 /**
71 * Name of Group.
72 *
73 * @var string
74 */
75 public $title;
76
77 /**
78 * Optional verbose description of the group.
79 *
80 * @var text
81 */
82 public $description;
83
84 /**
85 * Module or process which created this group.
86 *
87 * @var string
88 */
89 public $source;
90
91 /**
92 * FK to saved search table.
93 *
94 * @var int
95 */
96 public $saved_search_id;
97
98 /**
99 * Is this entry active?
100 *
101 * @var bool
102 */
103 public $is_active;
104
105 /**
106 * In what context(s) is this field visible.
107 *
108 * @var string
109 */
110 public $visibility;
111
112 /**
113 * the sql where clause if a saved search acl
114 *
115 * @var text
116 */
117 public $where_clause;
118
119 /**
120 * the tables to be included in a select data
121 *
122 * @var text
123 */
124 public $select_tables;
125
126 /**
127 * the tables to be included in the count statement
128 *
129 * @var text
130 */
131 public $where_tables;
132
133 /**
134 * FK to group type
135 *
136 * @var string
137 */
138 public $group_type;
139
140 /**
141 * Date when we created the cache for a smart group
142 *
143 * @var timestamp
144 */
145 public $cache_date;
146
147 /**
148 * Date and time when we need to refresh the cache next.
149 *
150 * @var timestamp
151 */
152 public $refresh_date;
153
154 /**
155 * IDs of the parent(s)
156 *
157 * @var text
158 */
159 public $parents;
160
161 /**
162 * IDs of the child(ren)
163 *
164 * @var text
165 */
166 public $children;
167
168 /**
169 * Is this group hidden?
170 *
171 * @var bool
172 */
173 public $is_hidden;
174
175 /**
176 * @var bool
177 */
178 public $is_reserved;
179
180 /**
181 * FK to contact table.
182 *
183 * @var int
184 */
185 public $created_id;
186
187 /**
188 * FK to contact table.
189 *
190 * @var int
191 */
192 public $modified_id;
193
194 /**
195 * Alternative public title for this Group.
196 *
197 * @var string
198 */
199 public $frontend_title;
200
201 /**
202 * Alternative public description of the group.
203 *
204 * @var text
205 */
206 public $frontend_description;
207
208 /**
209 * Class constructor.
210 */
211 public function __construct() {
212 $this->__table = 'civicrm_group';
213 parent::__construct();
214 }
215
216 /**
217 * Returns localized title of this entity.
218 *
219 * @param bool $plural
220 * Whether to return the plural version of the title.
221 */
222 public static function getEntityTitle($plural = FALSE) {
223 return $plural ? ts('Groups') : ts('Group');
224 }
225
226 /**
227 * Returns foreign keys and entity references.
228 *
229 * @return array
230 * [CRM_Core_Reference_Interface]
231 */
232 public static function getReferenceColumns() {
233 if (!isset(Civi::$statics[__CLASS__]['links'])) {
234 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
235 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'saved_search_id', 'civicrm_saved_search', 'id');
236 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'created_id', 'civicrm_contact', 'id');
237 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'modified_id', 'civicrm_contact', 'id');
238 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
239 }
240 return Civi::$statics[__CLASS__]['links'];
241 }
242
243 /**
244 * Returns all the column names of this table
245 *
246 * @return array
247 */
248 public static function &fields() {
249 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
250 Civi::$statics[__CLASS__]['fields'] = [
251 'id' => [
252 'name' => 'id',
253 'type' => CRM_Utils_Type::T_INT,
254 'title' => ts('Group ID'),
255 'description' => ts('Group ID'),
256 'required' => TRUE,
257 'where' => 'civicrm_group.id',
258 'table_name' => 'civicrm_group',
259 'entity' => 'Group',
260 'bao' => 'CRM_Contact_BAO_Group',
261 'localizable' => 0,
262 'html' => [
263 'type' => 'Number',
264 ],
265 'add' => '1.1',
266 ],
267 'name' => [
268 'name' => 'name',
269 'type' => CRM_Utils_Type::T_STRING,
270 'title' => ts('Group Name'),
271 'description' => ts('Internal name of Group.'),
272 'maxlength' => 64,
273 'size' => CRM_Utils_Type::BIG,
274 'where' => 'civicrm_group.name',
275 'table_name' => 'civicrm_group',
276 'entity' => 'Group',
277 'bao' => 'CRM_Contact_BAO_Group',
278 'localizable' => 0,
279 'add' => '1.1',
280 ],
281 'title' => [
282 'name' => 'title',
283 'type' => CRM_Utils_Type::T_STRING,
284 'title' => ts('Group Title'),
285 'description' => ts('Name of Group.'),
286 'maxlength' => 255,
287 'size' => CRM_Utils_Type::HUGE,
288 'where' => 'civicrm_group.title',
289 'table_name' => 'civicrm_group',
290 'entity' => 'Group',
291 'bao' => 'CRM_Contact_BAO_Group',
292 'localizable' => 1,
293 'html' => [
294 'type' => 'Text',
295 ],
296 'add' => '1.1',
297 ],
298 'description' => [
299 'name' => 'description',
300 'type' => CRM_Utils_Type::T_TEXT,
301 'title' => ts('Group Description'),
302 'description' => ts('Optional verbose description of the group.'),
303 'rows' => 2,
304 'cols' => 60,
305 'where' => 'civicrm_group.description',
306 'table_name' => 'civicrm_group',
307 'entity' => 'Group',
308 'bao' => 'CRM_Contact_BAO_Group',
309 'localizable' => 0,
310 'html' => [
311 'type' => 'TextArea',
312 ],
313 'add' => '1.1',
314 ],
315 'source' => [
316 'name' => 'source',
317 'type' => CRM_Utils_Type::T_STRING,
318 'title' => ts('Group Source'),
319 'description' => ts('Module or process which created this group.'),
320 'maxlength' => 64,
321 'size' => CRM_Utils_Type::BIG,
322 'where' => 'civicrm_group.source',
323 'table_name' => 'civicrm_group',
324 'entity' => 'Group',
325 'bao' => 'CRM_Contact_BAO_Group',
326 'localizable' => 0,
327 'add' => '1.1',
328 ],
329 'saved_search_id' => [
330 'name' => 'saved_search_id',
331 'type' => CRM_Utils_Type::T_INT,
332 'title' => ts('Saved Search ID'),
333 'description' => ts('FK to saved search table.'),
334 'where' => 'civicrm_group.saved_search_id',
335 'table_name' => 'civicrm_group',
336 'entity' => 'Group',
337 'bao' => 'CRM_Contact_BAO_Group',
338 'localizable' => 0,
339 'FKClassName' => 'CRM_Contact_DAO_SavedSearch',
340 'html' => [
341 'label' => ts("Saved Search"),
342 ],
343 'add' => '1.1',
344 ],
345 'is_active' => [
346 'name' => 'is_active',
347 'type' => CRM_Utils_Type::T_BOOLEAN,
348 'title' => ts('Group Enabled'),
349 'description' => ts('Is this entry active?'),
350 'where' => 'civicrm_group.is_active',
351 'table_name' => 'civicrm_group',
352 'entity' => 'Group',
353 'bao' => 'CRM_Contact_BAO_Group',
354 'localizable' => 0,
355 'add' => '1.1',
356 ],
357 'visibility' => [
358 'name' => 'visibility',
359 'type' => CRM_Utils_Type::T_STRING,
360 'title' => ts('Group Visibility Setting'),
361 'description' => ts('In what context(s) is this field visible.'),
362 'maxlength' => 24,
363 'size' => CRM_Utils_Type::MEDIUM,
364 'where' => 'civicrm_group.visibility',
365 'default' => 'User and User Admin Only',
366 'table_name' => 'civicrm_group',
367 'entity' => 'Group',
368 'bao' => 'CRM_Contact_BAO_Group',
369 'localizable' => 0,
370 'html' => [
371 'type' => 'Select',
372 ],
373 'pseudoconstant' => [
374 'callback' => 'CRM_Core_SelectValues::groupVisibility',
375 ],
376 'add' => '1.2',
377 ],
378 'where_clause' => [
379 'name' => 'where_clause',
380 'type' => CRM_Utils_Type::T_TEXT,
381 'title' => ts('Group Where Clause'),
382 'description' => ts('the sql where clause if a saved search acl'),
383 'where' => 'civicrm_group.where_clause',
384 'table_name' => 'civicrm_group',
385 'entity' => 'Group',
386 'bao' => 'CRM_Contact_BAO_Group',
387 'localizable' => 0,
388 'add' => '1.6',
389 ],
390 'select_tables' => [
391 'name' => 'select_tables',
392 'type' => CRM_Utils_Type::T_TEXT,
393 'title' => ts('Tables For Select Clause'),
394 'description' => ts('the tables to be included in a select data'),
395 'where' => 'civicrm_group.select_tables',
396 'table_name' => 'civicrm_group',
397 'entity' => 'Group',
398 'bao' => 'CRM_Contact_BAO_Group',
399 'localizable' => 0,
400 'serialize' => self::SERIALIZE_PHP,
401 'add' => '1.6',
402 ],
403 'where_tables' => [
404 'name' => 'where_tables',
405 'type' => CRM_Utils_Type::T_TEXT,
406 'title' => ts('Tables For Where Clause'),
407 'description' => ts('the tables to be included in the count statement'),
408 'where' => 'civicrm_group.where_tables',
409 'table_name' => 'civicrm_group',
410 'entity' => 'Group',
411 'bao' => 'CRM_Contact_BAO_Group',
412 'localizable' => 0,
413 'serialize' => self::SERIALIZE_PHP,
414 'add' => '1.6',
415 ],
416 'group_type' => [
417 'name' => 'group_type',
418 'type' => CRM_Utils_Type::T_STRING,
419 'title' => ts('Group Type'),
420 'description' => ts('FK to group type'),
421 'maxlength' => 128,
422 'size' => CRM_Utils_Type::HUGE,
423 'where' => 'civicrm_group.group_type',
424 'table_name' => 'civicrm_group',
425 'entity' => 'Group',
426 'bao' => 'CRM_Contact_BAO_Group',
427 'localizable' => 0,
428 'serialize' => self::SERIALIZE_SEPARATOR_BOOKEND,
429 'pseudoconstant' => [
430 'optionGroupName' => 'group_type',
431 'optionEditPath' => 'civicrm/admin/options/group_type',
432 ],
433 'add' => '1.9',
434 ],
435 'cache_date' => [
436 'name' => 'cache_date',
437 'type' => CRM_Utils_Type::T_TIMESTAMP,
438 'title' => ts('Group Cache Date'),
439 'description' => ts('Date when we created the cache for a smart group'),
440 'required' => FALSE,
441 'where' => 'civicrm_group.cache_date',
442 'table_name' => 'civicrm_group',
443 'entity' => 'Group',
444 'bao' => 'CRM_Contact_BAO_Group',
445 'localizable' => 0,
446 'add' => '2.1',
447 ],
448 'refresh_date' => [
449 'name' => 'refresh_date',
450 'type' => CRM_Utils_Type::T_TIMESTAMP,
451 'title' => ts('Next Group Refresh Time'),
452 'description' => ts('Date and time when we need to refresh the cache next.'),
453 'required' => FALSE,
454 'where' => 'civicrm_group.refresh_date',
455 'table_name' => 'civicrm_group',
456 'entity' => 'Group',
457 'bao' => 'CRM_Contact_BAO_Group',
458 'localizable' => 0,
459 'add' => '4.3',
460 ],
461 'parents' => [
462 'name' => 'parents',
463 'type' => CRM_Utils_Type::T_TEXT,
464 'title' => ts('Group Parents'),
465 'description' => ts('IDs of the parent(s)'),
466 'where' => 'civicrm_group.parents',
467 'table_name' => 'civicrm_group',
468 'entity' => 'Group',
469 'bao' => 'CRM_Contact_BAO_Group',
470 'localizable' => 0,
471 'serialize' => self::SERIALIZE_COMMA,
472 'pseudoconstant' => [
473 'callback' => 'CRM_Core_PseudoConstant::allGroup',
474 ],
475 'add' => '2.1',
476 ],
477 'children' => [
478 'name' => 'children',
479 'type' => CRM_Utils_Type::T_TEXT,
480 'title' => ts('Group Children'),
481 'description' => ts('IDs of the child(ren)'),
482 'where' => 'civicrm_group.children',
483 'table_name' => 'civicrm_group',
484 'entity' => 'Group',
485 'bao' => 'CRM_Contact_BAO_Group',
486 'localizable' => 0,
487 'add' => '2.1',
488 ],
489 'is_hidden' => [
490 'name' => 'is_hidden',
491 'type' => CRM_Utils_Type::T_BOOLEAN,
492 'title' => ts('Group is Hidden'),
493 'description' => ts('Is this group hidden?'),
494 'where' => 'civicrm_group.is_hidden',
495 'default' => '0',
496 'table_name' => 'civicrm_group',
497 'entity' => 'Group',
498 'bao' => 'CRM_Contact_BAO_Group',
499 'localizable' => 0,
500 'add' => '2.2',
501 ],
502 'is_reserved' => [
503 'name' => 'is_reserved',
504 'type' => CRM_Utils_Type::T_BOOLEAN,
505 'title' => ts('Group is Reserved'),
506 'where' => 'civicrm_group.is_reserved',
507 'default' => '0',
508 'table_name' => 'civicrm_group',
509 'entity' => 'Group',
510 'bao' => 'CRM_Contact_BAO_Group',
511 'localizable' => 0,
512 'add' => '4.2',
513 ],
514 'created_id' => [
515 'name' => 'created_id',
516 'type' => CRM_Utils_Type::T_INT,
517 'title' => ts('Created By Contact ID'),
518 'description' => ts('FK to contact table.'),
519 'where' => 'civicrm_group.created_id',
520 'table_name' => 'civicrm_group',
521 'entity' => 'Group',
522 'bao' => 'CRM_Contact_BAO_Group',
523 'localizable' => 0,
524 'FKClassName' => 'CRM_Contact_DAO_Contact',
525 'html' => [
526 'label' => ts("Created By"),
527 ],
528 'add' => '4.3',
529 ],
530 'modified_id' => [
531 'name' => 'modified_id',
532 'type' => CRM_Utils_Type::T_INT,
533 'title' => ts('Modified By Contact ID'),
534 'description' => ts('FK to contact table.'),
535 'where' => 'civicrm_group.modified_id',
536 'table_name' => 'civicrm_group',
537 'entity' => 'Group',
538 'bao' => 'CRM_Contact_BAO_Group',
539 'localizable' => 0,
540 'FKClassName' => 'CRM_Contact_DAO_Contact',
541 'html' => [
542 'label' => ts("Modified By"),
543 ],
544 'add' => '4.5',
545 ],
546 'frontend_title' => [
547 'name' => 'frontend_title',
548 'type' => CRM_Utils_Type::T_STRING,
549 'title' => ts('Public Group Title'),
550 'description' => ts('Alternative public title for this Group.'),
551 'maxlength' => 255,
552 'size' => CRM_Utils_Type::HUGE,
553 'where' => 'civicrm_group.frontend_title',
554 'default' => 'NULL',
555 'table_name' => 'civicrm_group',
556 'entity' => 'Group',
557 'bao' => 'CRM_Contact_BAO_Group',
558 'localizable' => 1,
559 'html' => [
560 'type' => 'Text',
561 ],
562 'add' => '5.31',
563 ],
564 'frontend_description' => [
565 'name' => 'frontend_description',
566 'type' => CRM_Utils_Type::T_TEXT,
567 'title' => ts('Public Group Description'),
568 'description' => ts('Alternative public description of the group.'),
569 'rows' => 2,
570 'cols' => 60,
571 'where' => 'civicrm_group.frontend_description',
572 'default' => 'NULL',
573 'table_name' => 'civicrm_group',
574 'entity' => 'Group',
575 'bao' => 'CRM_Contact_BAO_Group',
576 'localizable' => 1,
577 'html' => [
578 'type' => 'TextArea',
579 ],
580 'add' => '5.31',
581 ],
582 ];
583 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
584 }
585 return Civi::$statics[__CLASS__]['fields'];
586 }
587
588 /**
589 * Return a mapping from field-name to the corresponding key (as used in fields()).
590 *
591 * @return array
592 * Array(string $name => string $uniqueName).
593 */
594 public static function &fieldKeys() {
595 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
596 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
597 }
598 return Civi::$statics[__CLASS__]['fieldKeys'];
599 }
600
601 /**
602 * Returns the names of this table
603 *
604 * @return string
605 */
606 public static function getTableName() {
607 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
608 }
609
610 /**
611 * Returns if this table needs to be logged
612 *
613 * @return bool
614 */
615 public function getLog() {
616 return self::$_log;
617 }
618
619 /**
620 * Returns the list of fields that can be imported
621 *
622 * @param bool $prefix
623 *
624 * @return array
625 */
626 public static function &import($prefix = FALSE) {
627 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'group', $prefix, []);
628 return $r;
629 }
630
631 /**
632 * Returns the list of fields that can be exported
633 *
634 * @param bool $prefix
635 *
636 * @return array
637 */
638 public static function &export($prefix = FALSE) {
639 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'group', $prefix, []);
640 return $r;
641 }
642
643 /**
644 * Returns the list of indices
645 *
646 * @param bool $localize
647 *
648 * @return array
649 */
650 public static function indices($localize = TRUE) {
651 $indices = [
652 'UI_cache_date' => [
653 'name' => 'UI_cache_date',
654 'field' => [
655 0 => 'cache_date',
656 ],
657 'localizable' => FALSE,
658 'sig' => 'civicrm_group::0::cache_date',
659 ],
660 'index_group_type' => [
661 'name' => 'index_group_type',
662 'field' => [
663 0 => 'group_type',
664 ],
665 'localizable' => FALSE,
666 'sig' => 'civicrm_group::0::group_type',
667 ],
668 'UI_title' => [
669 'name' => 'UI_title',
670 'field' => [
671 0 => 'title',
672 ],
673 'localizable' => TRUE,
674 'unique' => TRUE,
675 'sig' => 'civicrm_group::1::title',
676 ],
677 'UI_name' => [
678 'name' => 'UI_name',
679 'field' => [
680 0 => 'name',
681 ],
682 'localizable' => FALSE,
683 'unique' => TRUE,
684 'sig' => 'civicrm_group::1::name',
685 ],
686 ];
687 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
688 }
689
690 }