Add "labelField" metadata to entities
[civicrm-core.git] / CRM / Core / DAO / Phone.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Core/Phone.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:751f23f392f8fe789e580096ae7522b7)
10 */
11
12 /**
13 * Database access object for the Phone entity.
14 */
15 class CRM_Core_DAO_Phone 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_phone';
25
26 /**
27 * Icon associated with this entity.
28 *
29 * @var string
30 */
31 public static $_icon = 'fa-phone';
32
33 /**
34 * Field to show when displaying a record.
35 *
36 * @var string
37 */
38 public static $_labelField = 'phone';
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 * Unique Phone ID
49 *
50 * @var int
51 */
52 public $id;
53
54 /**
55 * FK to Contact ID
56 *
57 * @var int
58 */
59 public $contact_id;
60
61 /**
62 * Which Location does this phone belong to.
63 *
64 * @var int
65 */
66 public $location_type_id;
67
68 /**
69 * Is this the primary phone for this contact and location.
70 *
71 * @var bool
72 */
73 public $is_primary;
74
75 /**
76 * Is this the billing?
77 *
78 * @var bool
79 */
80 public $is_billing;
81
82 /**
83 * Which Mobile Provider does this phone belong to.
84 *
85 * @var int
86 */
87 public $mobile_provider_id;
88
89 /**
90 * Complete phone number.
91 *
92 * @var string
93 */
94 public $phone;
95
96 /**
97 * Optional extension for a phone number.
98 *
99 * @var string
100 */
101 public $phone_ext;
102
103 /**
104 * Phone number stripped of all whitespace, letters, and punctuation.
105 *
106 * @var string
107 */
108 public $phone_numeric;
109
110 /**
111 * Which type of phone does this number belongs.
112 *
113 * @var int
114 */
115 public $phone_type_id;
116
117 /**
118 * Class constructor.
119 */
120 public function __construct() {
121 $this->__table = 'civicrm_phone';
122 parent::__construct();
123 }
124
125 /**
126 * Returns localized title of this entity.
127 *
128 * @param bool $plural
129 * Whether to return the plural version of the title.
130 */
131 public static function getEntityTitle($plural = FALSE) {
132 return $plural ? ts('Phones') : ts('Phone');
133 }
134
135 /**
136 * Returns foreign keys and entity references.
137 *
138 * @return array
139 * [CRM_Core_Reference_Interface]
140 */
141 public static function getReferenceColumns() {
142 if (!isset(Civi::$statics[__CLASS__]['links'])) {
143 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
144 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
145 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
146 }
147 return Civi::$statics[__CLASS__]['links'];
148 }
149
150 /**
151 * Returns all the column names of this table
152 *
153 * @return array
154 */
155 public static function &fields() {
156 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
157 Civi::$statics[__CLASS__]['fields'] = [
158 'id' => [
159 'name' => 'id',
160 'type' => CRM_Utils_Type::T_INT,
161 'title' => ts('Phone ID'),
162 'description' => ts('Unique Phone ID'),
163 'required' => TRUE,
164 'where' => 'civicrm_phone.id',
165 'table_name' => 'civicrm_phone',
166 'entity' => 'Phone',
167 'bao' => 'CRM_Core_BAO_Phone',
168 'localizable' => 0,
169 'add' => '1.1',
170 ],
171 'contact_id' => [
172 'name' => 'contact_id',
173 'type' => CRM_Utils_Type::T_INT,
174 'title' => ts('Phone Contact'),
175 'description' => ts('FK to Contact ID'),
176 'where' => 'civicrm_phone.contact_id',
177 'table_name' => 'civicrm_phone',
178 'entity' => 'Phone',
179 'bao' => 'CRM_Core_BAO_Phone',
180 'localizable' => 0,
181 'FKClassName' => 'CRM_Contact_DAO_Contact',
182 'add' => '2.0',
183 ],
184 'location_type_id' => [
185 'name' => 'location_type_id',
186 'type' => CRM_Utils_Type::T_INT,
187 'title' => ts('Phone Location Type ID'),
188 'description' => ts('Which Location does this phone belong to.'),
189 'where' => 'civicrm_phone.location_type_id',
190 'table_name' => 'civicrm_phone',
191 'entity' => 'Phone',
192 'bao' => 'CRM_Core_BAO_Phone',
193 'localizable' => 0,
194 'html' => [
195 'type' => 'Select',
196 'label' => ts("Phone Location Type"),
197 ],
198 'pseudoconstant' => [
199 'table' => 'civicrm_location_type',
200 'keyColumn' => 'id',
201 'labelColumn' => 'display_name',
202 ],
203 'add' => '2.0',
204 ],
205 'is_primary' => [
206 'name' => 'is_primary',
207 'type' => CRM_Utils_Type::T_BOOLEAN,
208 'title' => ts('Primary phone'),
209 'description' => ts('Is this the primary phone for this contact and location.'),
210 'where' => 'civicrm_phone.is_primary',
211 'default' => '0',
212 'table_name' => 'civicrm_phone',
213 'entity' => 'Phone',
214 'bao' => 'CRM_Core_BAO_Phone',
215 'localizable' => 0,
216 'html' => [
217 'type' => 'Radio',
218 ],
219 'add' => '1.1',
220 ],
221 'is_billing' => [
222 'name' => 'is_billing',
223 'type' => CRM_Utils_Type::T_BOOLEAN,
224 'title' => ts('Is Billing Phone'),
225 'description' => ts('Is this the billing?'),
226 'where' => 'civicrm_phone.is_billing',
227 'default' => '0',
228 'table_name' => 'civicrm_phone',
229 'entity' => 'Phone',
230 'bao' => 'CRM_Core_BAO_Phone',
231 'localizable' => 0,
232 'add' => '2.0',
233 ],
234 'mobile_provider_id' => [
235 'name' => 'mobile_provider_id',
236 'type' => CRM_Utils_Type::T_INT,
237 'title' => ts('Mobile Provider'),
238 'description' => ts('Which Mobile Provider does this phone belong to.'),
239 'where' => 'civicrm_phone.mobile_provider_id',
240 'table_name' => 'civicrm_phone',
241 'entity' => 'Phone',
242 'bao' => 'CRM_Core_BAO_Phone',
243 'localizable' => 0,
244 'add' => '1.1',
245 ],
246 'phone' => [
247 'name' => 'phone',
248 'type' => CRM_Utils_Type::T_STRING,
249 'title' => ts('Phone'),
250 'description' => ts('Complete phone number.'),
251 'maxlength' => 32,
252 'size' => CRM_Utils_Type::MEDIUM,
253 'import' => TRUE,
254 'where' => 'civicrm_phone.phone',
255 'headerPattern' => '/phone/i',
256 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
257 'export' => TRUE,
258 'table_name' => 'civicrm_phone',
259 'entity' => 'Phone',
260 'bao' => 'CRM_Core_BAO_Phone',
261 'localizable' => 0,
262 'html' => [
263 'type' => 'Text',
264 ],
265 'add' => '1.1',
266 ],
267 'phone_ext' => [
268 'name' => 'phone_ext',
269 'type' => CRM_Utils_Type::T_STRING,
270 'title' => ts('Phone Extension'),
271 'description' => ts('Optional extension for a phone number.'),
272 'maxlength' => 16,
273 'size' => 4,
274 'import' => TRUE,
275 'where' => 'civicrm_phone.phone_ext',
276 'headerPattern' => '/extension/i',
277 'dataPattern' => '/^\d+$/',
278 'export' => TRUE,
279 'table_name' => 'civicrm_phone',
280 'entity' => 'Phone',
281 'bao' => 'CRM_Core_BAO_Phone',
282 'localizable' => 0,
283 'html' => [
284 'type' => 'Text',
285 ],
286 'add' => '3.3',
287 ],
288 'phone_numeric' => [
289 'name' => 'phone_numeric',
290 'type' => CRM_Utils_Type::T_STRING,
291 'title' => ts('Phone Numeric'),
292 'description' => ts('Phone number stripped of all whitespace, letters, and punctuation.'),
293 'maxlength' => 32,
294 'size' => CRM_Utils_Type::MEDIUM,
295 'where' => 'civicrm_phone.phone_numeric',
296 'table_name' => 'civicrm_phone',
297 'entity' => 'Phone',
298 'bao' => 'CRM_Core_BAO_Phone',
299 'localizable' => 0,
300 'add' => '4.3',
301 ],
302 'phone_type_id' => [
303 'name' => 'phone_type_id',
304 'type' => CRM_Utils_Type::T_INT,
305 'title' => ts('Phone Type ID'),
306 'description' => ts('Which type of phone does this number belongs.'),
307 'where' => 'civicrm_phone.phone_type_id',
308 'export' => TRUE,
309 'table_name' => 'civicrm_phone',
310 'entity' => 'Phone',
311 'bao' => 'CRM_Core_BAO_Phone',
312 'localizable' => 0,
313 'html' => [
314 'type' => 'Select',
315 'label' => ts("Phone Type"),
316 ],
317 'pseudoconstant' => [
318 'optionGroupName' => 'phone_type',
319 'optionEditPath' => 'civicrm/admin/options/phone_type',
320 ],
321 'add' => '2.2',
322 ],
323 ];
324 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
325 }
326 return Civi::$statics[__CLASS__]['fields'];
327 }
328
329 /**
330 * Return a mapping from field-name to the corresponding key (as used in fields()).
331 *
332 * @return array
333 * Array(string $name => string $uniqueName).
334 */
335 public static function &fieldKeys() {
336 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
337 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
338 }
339 return Civi::$statics[__CLASS__]['fieldKeys'];
340 }
341
342 /**
343 * Returns the names of this table
344 *
345 * @return string
346 */
347 public static function getTableName() {
348 return self::$_tableName;
349 }
350
351 /**
352 * Returns if this table needs to be logged
353 *
354 * @return bool
355 */
356 public function getLog() {
357 return self::$_log;
358 }
359
360 /**
361 * Returns the list of fields that can be imported
362 *
363 * @param bool $prefix
364 *
365 * @return array
366 */
367 public static function &import($prefix = FALSE) {
368 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'phone', $prefix, []);
369 return $r;
370 }
371
372 /**
373 * Returns the list of fields that can be exported
374 *
375 * @param bool $prefix
376 *
377 * @return array
378 */
379 public static function &export($prefix = FALSE) {
380 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'phone', $prefix, []);
381 return $r;
382 }
383
384 /**
385 * Returns the list of indices
386 *
387 * @param bool $localize
388 *
389 * @return array
390 */
391 public static function indices($localize = TRUE) {
392 $indices = [
393 'index_location_type' => [
394 'name' => 'index_location_type',
395 'field' => [
396 0 => 'location_type_id',
397 ],
398 'localizable' => FALSE,
399 'sig' => 'civicrm_phone::0::location_type_id',
400 ],
401 'index_is_primary' => [
402 'name' => 'index_is_primary',
403 'field' => [
404 0 => 'is_primary',
405 ],
406 'localizable' => FALSE,
407 'sig' => 'civicrm_phone::0::is_primary',
408 ],
409 'index_is_billing' => [
410 'name' => 'index_is_billing',
411 'field' => [
412 0 => 'is_billing',
413 ],
414 'localizable' => FALSE,
415 'sig' => 'civicrm_phone::0::is_billing',
416 ],
417 'UI_mobile_provider_id' => [
418 'name' => 'UI_mobile_provider_id',
419 'field' => [
420 0 => 'mobile_provider_id',
421 ],
422 'localizable' => FALSE,
423 'sig' => 'civicrm_phone::0::mobile_provider_id',
424 ],
425 'index_phone_numeric' => [
426 'name' => 'index_phone_numeric',
427 'field' => [
428 0 => 'phone_numeric',
429 ],
430 'localizable' => FALSE,
431 'sig' => 'civicrm_phone::0::phone_numeric',
432 ],
433 ];
434 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
435 }
436
437 }