2bcf574a9d6ccd66dc77cde159c87ab17e6d38a2
[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:69c5bce12cbed1144a0c38eec1052206)
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 'html' => [
170 'type' => 'Number',
171 ],
172 'add' => '1.1',
173 ],
174 'contact_id' => [
175 'name' => 'contact_id',
176 'type' => CRM_Utils_Type::T_INT,
177 'title' => ts('Contact ID'),
178 'description' => ts('FK to Contact ID'),
179 'where' => 'civicrm_phone.contact_id',
180 'table_name' => 'civicrm_phone',
181 'entity' => 'Phone',
182 'bao' => 'CRM_Core_BAO_Phone',
183 'localizable' => 0,
184 'FKClassName' => 'CRM_Contact_DAO_Contact',
185 'html' => [
186 'label' => ts("Contact"),
187 ],
188 'add' => '2.0',
189 ],
190 'location_type_id' => [
191 'name' => 'location_type_id',
192 'type' => CRM_Utils_Type::T_INT,
193 'title' => ts('Location Type ID'),
194 'description' => ts('Which Location does this phone belong to.'),
195 'where' => 'civicrm_phone.location_type_id',
196 'table_name' => 'civicrm_phone',
197 'entity' => 'Phone',
198 'bao' => 'CRM_Core_BAO_Phone',
199 'localizable' => 0,
200 'html' => [
201 'type' => 'Select',
202 'label' => ts("Location Type"),
203 ],
204 'pseudoconstant' => [
205 'table' => 'civicrm_location_type',
206 'keyColumn' => 'id',
207 'labelColumn' => 'display_name',
208 ],
209 'add' => '2.0',
210 ],
211 'is_primary' => [
212 'name' => 'is_primary',
213 'type' => CRM_Utils_Type::T_BOOLEAN,
214 'title' => ts('Primary phone'),
215 'description' => ts('Is this the primary phone for this contact and location.'),
216 'where' => 'civicrm_phone.is_primary',
217 'default' => '0',
218 'table_name' => 'civicrm_phone',
219 'entity' => 'Phone',
220 'bao' => 'CRM_Core_BAO_Phone',
221 'localizable' => 0,
222 'html' => [
223 'type' => 'Radio',
224 ],
225 'add' => '1.1',
226 ],
227 'is_billing' => [
228 'name' => 'is_billing',
229 'type' => CRM_Utils_Type::T_BOOLEAN,
230 'title' => ts('Is Billing Phone'),
231 'description' => ts('Is this the billing?'),
232 'where' => 'civicrm_phone.is_billing',
233 'default' => '0',
234 'table_name' => 'civicrm_phone',
235 'entity' => 'Phone',
236 'bao' => 'CRM_Core_BAO_Phone',
237 'localizable' => 0,
238 'add' => '2.0',
239 ],
240 'mobile_provider_id' => [
241 'name' => 'mobile_provider_id',
242 'type' => CRM_Utils_Type::T_INT,
243 'title' => ts('Mobile Provider'),
244 'description' => ts('Which Mobile Provider does this phone belong to.'),
245 'where' => 'civicrm_phone.mobile_provider_id',
246 'table_name' => 'civicrm_phone',
247 'entity' => 'Phone',
248 'bao' => 'CRM_Core_BAO_Phone',
249 'localizable' => 0,
250 'add' => '1.1',
251 ],
252 'phone' => [
253 'name' => 'phone',
254 'type' => CRM_Utils_Type::T_STRING,
255 'title' => ts('Phone'),
256 'description' => ts('Complete phone number.'),
257 'maxlength' => 32,
258 'size' => CRM_Utils_Type::MEDIUM,
259 'import' => TRUE,
260 'where' => 'civicrm_phone.phone',
261 'headerPattern' => '/phone/i',
262 'dataPattern' => '/^[\d\(\)\-\.\s]+$/',
263 'export' => TRUE,
264 'table_name' => 'civicrm_phone',
265 'entity' => 'Phone',
266 'bao' => 'CRM_Core_BAO_Phone',
267 'localizable' => 0,
268 'html' => [
269 'type' => 'Text',
270 'label' => ts("Phone"),
271 ],
272 'add' => '1.1',
273 ],
274 'phone_ext' => [
275 'name' => 'phone_ext',
276 'type' => CRM_Utils_Type::T_STRING,
277 'title' => ts('Phone Extension'),
278 'description' => ts('Optional extension for a phone number.'),
279 'maxlength' => 16,
280 'size' => 4,
281 'import' => TRUE,
282 'where' => 'civicrm_phone.phone_ext',
283 'headerPattern' => '/extension/i',
284 'dataPattern' => '/^\d+$/',
285 'export' => TRUE,
286 'table_name' => 'civicrm_phone',
287 'entity' => 'Phone',
288 'bao' => 'CRM_Core_BAO_Phone',
289 'localizable' => 0,
290 'html' => [
291 'type' => 'Text',
292 ],
293 'add' => '3.3',
294 ],
295 'phone_numeric' => [
296 'name' => 'phone_numeric',
297 'type' => CRM_Utils_Type::T_STRING,
298 'title' => ts('Phone Numeric'),
299 'description' => ts('Phone number stripped of all whitespace, letters, and punctuation.'),
300 'maxlength' => 32,
301 'size' => CRM_Utils_Type::MEDIUM,
302 'where' => 'civicrm_phone.phone_numeric',
303 'table_name' => 'civicrm_phone',
304 'entity' => 'Phone',
305 'bao' => 'CRM_Core_BAO_Phone',
306 'localizable' => 0,
307 'html' => [
308 'label' => ts("Numeric"),
309 ],
310 'add' => '4.3',
311 ],
312 'phone_type_id' => [
313 'name' => 'phone_type_id',
314 'type' => CRM_Utils_Type::T_INT,
315 'title' => ts('Phone Type ID'),
316 'description' => ts('Which type of phone does this number belongs.'),
317 'where' => 'civicrm_phone.phone_type_id',
318 'export' => TRUE,
319 'table_name' => 'civicrm_phone',
320 'entity' => 'Phone',
321 'bao' => 'CRM_Core_BAO_Phone',
322 'localizable' => 0,
323 'html' => [
324 'type' => 'Select',
325 'label' => ts("Phone Type"),
326 ],
327 'pseudoconstant' => [
328 'optionGroupName' => 'phone_type',
329 'optionEditPath' => 'civicrm/admin/options/phone_type',
330 ],
331 'add' => '2.2',
332 ],
333 ];
334 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
335 }
336 return Civi::$statics[__CLASS__]['fields'];
337 }
338
339 /**
340 * Return a mapping from field-name to the corresponding key (as used in fields()).
341 *
342 * @return array
343 * Array(string $name => string $uniqueName).
344 */
345 public static function &fieldKeys() {
346 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
347 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
348 }
349 return Civi::$statics[__CLASS__]['fieldKeys'];
350 }
351
352 /**
353 * Returns the names of this table
354 *
355 * @return string
356 */
357 public static function getTableName() {
358 return self::$_tableName;
359 }
360
361 /**
362 * Returns if this table needs to be logged
363 *
364 * @return bool
365 */
366 public function getLog() {
367 return self::$_log;
368 }
369
370 /**
371 * Returns the list of fields that can be imported
372 *
373 * @param bool $prefix
374 *
375 * @return array
376 */
377 public static function &import($prefix = FALSE) {
378 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'phone', $prefix, []);
379 return $r;
380 }
381
382 /**
383 * Returns the list of fields that can be exported
384 *
385 * @param bool $prefix
386 *
387 * @return array
388 */
389 public static function &export($prefix = FALSE) {
390 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'phone', $prefix, []);
391 return $r;
392 }
393
394 /**
395 * Returns the list of indices
396 *
397 * @param bool $localize
398 *
399 * @return array
400 */
401 public static function indices($localize = TRUE) {
402 $indices = [
403 'index_location_type' => [
404 'name' => 'index_location_type',
405 'field' => [
406 0 => 'location_type_id',
407 ],
408 'localizable' => FALSE,
409 'sig' => 'civicrm_phone::0::location_type_id',
410 ],
411 'index_is_primary' => [
412 'name' => 'index_is_primary',
413 'field' => [
414 0 => 'is_primary',
415 ],
416 'localizable' => FALSE,
417 'sig' => 'civicrm_phone::0::is_primary',
418 ],
419 'index_is_billing' => [
420 'name' => 'index_is_billing',
421 'field' => [
422 0 => 'is_billing',
423 ],
424 'localizable' => FALSE,
425 'sig' => 'civicrm_phone::0::is_billing',
426 ],
427 'UI_mobile_provider_id' => [
428 'name' => 'UI_mobile_provider_id',
429 'field' => [
430 0 => 'mobile_provider_id',
431 ],
432 'localizable' => FALSE,
433 'sig' => 'civicrm_phone::0::mobile_provider_id',
434 ],
435 'index_phone_numeric' => [
436 'name' => 'index_phone_numeric',
437 'field' => [
438 0 => 'phone_numeric',
439 ],
440 'localizable' => FALSE,
441 'sig' => 'civicrm_phone::0::phone_numeric',
442 ],
443 ];
444 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
445 }
446
447 }