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