Merge pull request #22074 from eileenmcnaughton/tags
[civicrm-core.git] / CRM / Core / DAO / EntityTag.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Core/EntityTag.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:c5bfb60ebd84dbe86b8dd8b522fd11e6)
10 */
11
12 /**
13 * Database access object for the EntityTag entity.
14 */
15 class CRM_Core_DAO_EntityTag 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_entity_tag';
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 * primary key
35 *
36 * @var int
37 */
38 public $id;
39
40 /**
41 * physical tablename for entity being joined to file, e.g. civicrm_contact
42 *
43 * @var string
44 */
45 public $entity_table;
46
47 /**
48 * FK to entity table specified in entity_table column.
49 *
50 * @var int
51 */
52 public $entity_id;
53
54 /**
55 * FK to civicrm_tag
56 *
57 * @var int
58 */
59 public $tag_id;
60
61 /**
62 * Class constructor.
63 */
64 public function __construct() {
65 $this->__table = 'civicrm_entity_tag';
66 parent::__construct();
67 }
68
69 /**
70 * Returns localized title of this entity.
71 *
72 * @param bool $plural
73 * Whether to return the plural version of the title.
74 */
75 public static function getEntityTitle($plural = FALSE) {
76 return $plural ? ts('Entity Tags') : ts('Entity Tag');
77 }
78
79 /**
80 * Returns foreign keys and entity references.
81 *
82 * @return array
83 * [CRM_Core_Reference_Interface]
84 */
85 public static function getReferenceColumns() {
86 if (!isset(Civi::$statics[__CLASS__]['links'])) {
87 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
88 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'tag_id', 'civicrm_tag', 'id');
89 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), 'entity_id', NULL, 'id', 'entity_table');
90 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
91 }
92 return Civi::$statics[__CLASS__]['links'];
93 }
94
95 /**
96 * Returns all the column names of this table
97 *
98 * @return array
99 */
100 public static function &fields() {
101 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
102 Civi::$statics[__CLASS__]['fields'] = [
103 'id' => [
104 'name' => 'id',
105 'type' => CRM_Utils_Type::T_INT,
106 'title' => ts('Entity Tag ID'),
107 'description' => ts('primary key'),
108 'required' => TRUE,
109 'where' => 'civicrm_entity_tag.id',
110 'table_name' => 'civicrm_entity_tag',
111 'entity' => 'EntityTag',
112 'bao' => 'CRM_Core_BAO_EntityTag',
113 'localizable' => 0,
114 'html' => [
115 'type' => 'Number',
116 ],
117 'readonly' => TRUE,
118 'add' => '1.1',
119 ],
120 'entity_table' => [
121 'name' => 'entity_table',
122 'type' => CRM_Utils_Type::T_STRING,
123 'title' => ts('Entity Table'),
124 'description' => ts('physical tablename for entity being joined to file, e.g. civicrm_contact'),
125 'maxlength' => 64,
126 'size' => CRM_Utils_Type::BIG,
127 'where' => 'civicrm_entity_tag.entity_table',
128 'table_name' => 'civicrm_entity_tag',
129 'entity' => 'EntityTag',
130 'bao' => 'CRM_Core_BAO_EntityTag',
131 'localizable' => 0,
132 'pseudoconstant' => [
133 'optionGroupName' => 'tag_used_for',
134 'optionEditPath' => 'civicrm/admin/options/tag_used_for',
135 ],
136 'add' => '3.2',
137 ],
138 'entity_id' => [
139 'name' => 'entity_id',
140 'type' => CRM_Utils_Type::T_INT,
141 'title' => ts('Entity ID'),
142 'description' => ts('FK to entity table specified in entity_table column.'),
143 'required' => TRUE,
144 'where' => 'civicrm_entity_tag.entity_id',
145 'table_name' => 'civicrm_entity_tag',
146 'entity' => 'EntityTag',
147 'bao' => 'CRM_Core_BAO_EntityTag',
148 'localizable' => 0,
149 'add' => '3.2',
150 ],
151 'tag_id' => [
152 'name' => 'tag_id',
153 'type' => CRM_Utils_Type::T_INT,
154 'title' => ts('Tag ID'),
155 'description' => ts('FK to civicrm_tag'),
156 'required' => TRUE,
157 'where' => 'civicrm_entity_tag.tag_id',
158 'table_name' => 'civicrm_entity_tag',
159 'entity' => 'EntityTag',
160 'bao' => 'CRM_Core_BAO_EntityTag',
161 'localizable' => 0,
162 'FKClassName' => 'CRM_Core_DAO_Tag',
163 'html' => [
164 'type' => 'Select',
165 'label' => ts("Tag"),
166 ],
167 'pseudoconstant' => [
168 'table' => 'civicrm_tag',
169 'keyColumn' => 'id',
170 'labelColumn' => 'name',
171 'condition' => 'is_tagset != 1',
172 ],
173 'add' => '1.1',
174 ],
175 ];
176 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
177 }
178 return Civi::$statics[__CLASS__]['fields'];
179 }
180
181 /**
182 * Return a mapping from field-name to the corresponding key (as used in fields()).
183 *
184 * @return array
185 * Array(string $name => string $uniqueName).
186 */
187 public static function &fieldKeys() {
188 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
189 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
190 }
191 return Civi::$statics[__CLASS__]['fieldKeys'];
192 }
193
194 /**
195 * Returns the names of this table
196 *
197 * @return string
198 */
199 public static function getTableName() {
200 return self::$_tableName;
201 }
202
203 /**
204 * Returns if this table needs to be logged
205 *
206 * @return bool
207 */
208 public function getLog() {
209 return self::$_log;
210 }
211
212 /**
213 * Returns the list of fields that can be imported
214 *
215 * @param bool $prefix
216 *
217 * @return array
218 */
219 public static function &import($prefix = FALSE) {
220 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'entity_tag', $prefix, []);
221 return $r;
222 }
223
224 /**
225 * Returns the list of fields that can be exported
226 *
227 * @param bool $prefix
228 *
229 * @return array
230 */
231 public static function &export($prefix = FALSE) {
232 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'entity_tag', $prefix, []);
233 return $r;
234 }
235
236 /**
237 * Returns the list of indices
238 *
239 * @param bool $localize
240 *
241 * @return array
242 */
243 public static function indices($localize = TRUE) {
244 $indices = [
245 'UI_entity_id_entity_table_tag_id' => [
246 'name' => 'UI_entity_id_entity_table_tag_id',
247 'field' => [
248 0 => 'entity_id',
249 1 => 'entity_table',
250 2 => 'tag_id',
251 ],
252 'localizable' => FALSE,
253 'unique' => TRUE,
254 'sig' => 'civicrm_entity_tag::1::entity_id::entity_table::tag_id',
255 ],
256 ];
257 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
258 }
259
260 }