Merge pull request #23612 from civicrm/5.50
[civicrm-core.git] / CRM / Contact / DAO / Relationship.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/Contact/Relationship.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
0b67ced4 9 * (GenCodeChecksum:3c7051137838e12caf53b96b8c369f2b)
e501603b 10 */
c3fc2621 11
f41f0342 12/**
c3fc2621 13 * Database access object for the Relationship entity.
f41f0342 14 */
e501603b 15class CRM_Contact_DAO_Relationship 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_relationship';
c3fc2621 25
449c4e6b
CW
26 /**
27 * Icon associated with this entity.
28 *
29 * @var string
30 */
31 public static $_icon = 'fa-handshake-o';
32
e501603b 33 /**
f41f0342 34 * Should CiviCRM log any modifications to this table in the civicrm_log table.
e501603b 35 *
c3fc2621 36 * @var bool
e501603b 37 */
fa45b5b9 38 public static $_log = TRUE;
c3fc2621 39
c5076889
CW
40 /**
41 * Paths for accessing this entity in the UI.
42 *
43 * @var string[]
44 */
45 protected static $_paths = [
46 'view' => 'civicrm/contact/view/rel?action=view&reset=1&cid=[contact_id_a]&id=[id]',
47 'delete' => 'civicrm/contact/view/rel?action=delete&reset=1&cid=[contact_id_a]&id=[id]',
48 ];
49
e501603b
TO
50 /**
51 * Relationship ID
52 *
28979d65
CW
53 * @var int|string|null
54 * (SQL type: int unsigned)
55 * Note that values will be retrieved from the database as a string.
e501603b
TO
56 */
57 public $id;
c3fc2621 58
e501603b
TO
59 /**
60 * id of the first contact
61 *
28979d65
CW
62 * @var int|string
63 * (SQL type: int unsigned)
64 * Note that values will be retrieved from the database as a string.
e501603b
TO
65 */
66 public $contact_id_a;
c3fc2621 67
e501603b
TO
68 /**
69 * id of the second contact
70 *
28979d65
CW
71 * @var int|string
72 * (SQL type: int unsigned)
73 * Note that values will be retrieved from the database as a string.
e501603b
TO
74 */
75 public $contact_id_b;
c3fc2621 76
e501603b 77 /**
1ac9bb56 78 * Type of relationship
e501603b 79 *
28979d65
CW
80 * @var int|string
81 * (SQL type: int unsigned)
82 * Note that values will be retrieved from the database as a string.
e501603b
TO
83 */
84 public $relationship_type_id;
c3fc2621 85
e501603b
TO
86 /**
87 * date when the relationship started
88 *
28979d65
CW
89 * @var string|null
90 * (SQL type: date)
91 * Note that values will be retrieved from the database as a string.
e501603b
TO
92 */
93 public $start_date;
c3fc2621 94
e501603b
TO
95 /**
96 * date when the relationship ended
97 *
28979d65
CW
98 * @var string|null
99 * (SQL type: date)
100 * Note that values will be retrieved from the database as a string.
e501603b
TO
101 */
102 public $end_date;
c3fc2621 103
e501603b
TO
104 /**
105 * is the relationship active ?
106 *
c1e814c7 107 * @var bool|string
28979d65
CW
108 * (SQL type: tinyint)
109 * Note that values will be retrieved from the database as a string.
e501603b
TO
110 */
111 public $is_active;
c3fc2621 112
e501603b
TO
113 /**
114 * Optional verbose description for the relationship.
115 *
28979d65
CW
116 * @var string|null
117 * (SQL type: varchar(255))
118 * Note that values will be retrieved from the database as a string.
e501603b
TO
119 */
120 public $description;
c3fc2621 121
e501603b 122 /**
f871c3a9 123 * Permission that Contact A has to view/update Contact B
e501603b 124 *
28979d65
CW
125 * @var int|string
126 * (SQL type: int unsigned)
127 * Note that values will be retrieved from the database as a string.
e501603b
TO
128 */
129 public $is_permission_a_b;
c3fc2621 130
e501603b 131 /**
f871c3a9 132 * Permission that Contact B has to view/update Contact A
e501603b 133 *
28979d65
CW
134 * @var int|string
135 * (SQL type: int unsigned)
136 * Note that values will be retrieved from the database as a string.
e501603b
TO
137 */
138 public $is_permission_b_a;
c3fc2621 139
e501603b
TO
140 /**
141 * FK to civicrm_case
142 *
28979d65
CW
143 * @var int|string|null
144 * (SQL type: int unsigned)
145 * Note that values will be retrieved from the database as a string.
e501603b
TO
146 */
147 public $case_id;
c3fc2621 148
a0efcd4d
EM
149 /**
150 * Relationship created date.
151 *
28979d65
CW
152 * @var string
153 * (SQL type: timestamp)
154 * Note that values will be retrieved from the database as a string.
a0efcd4d
EM
155 */
156 public $created_date;
157
158 /**
159 * Relationship last modified.
160 *
28979d65
CW
161 * @var string
162 * (SQL type: timestamp)
163 * Note that values will be retrieved from the database as a string.
a0efcd4d
EM
164 */
165 public $modified_date;
166
e501603b 167 /**
f41f0342 168 * Class constructor.
e501603b 169 */
c3fc2621 170 public function __construct() {
e501603b
TO
171 $this->__table = 'civicrm_relationship';
172 parent::__construct();
173 }
c3fc2621 174
449c4e6b
CW
175 /**
176 * Returns localized title of this entity.
7b66c3b5
AH
177 *
178 * @param bool $plural
179 * Whether to return the plural version of the title.
449c4e6b 180 */
7b66c3b5
AH
181 public static function getEntityTitle($plural = FALSE) {
182 return $plural ? ts('Relationships') : ts('Relationship');
449c4e6b
CW
183 }
184
e501603b 185 /**
f41f0342 186 * Returns foreign keys and entity references.
e501603b
TO
187 *
188 * @return array
189 * [CRM_Core_Reference_Interface]
190 */
c3fc2621 191 public static function getReferenceColumns() {
346aaaba 192 if (!isset(Civi::$statics[__CLASS__]['links'])) {
fa45b5b9 193 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
c3fc2621
CW
194 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id_a', 'civicrm_contact', 'id');
195 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id_b', 'civicrm_contact', 'id');
196 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'relationship_type_id', 'civicrm_relationship_type', 'id');
197 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'case_id', 'civicrm_case', 'id');
346aaaba 198 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
e501603b 199 }
346aaaba 200 return Civi::$statics[__CLASS__]['links'];
e501603b 201 }
c3fc2621 202
e501603b
TO
203 /**
204 * Returns all the column names of this table
205 *
206 * @return array
207 */
c3fc2621 208 public static function &fields() {
346aaaba 209 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
c3fc2621
CW
210 Civi::$statics[__CLASS__]['fields'] = [
211 'id' => [
e501603b
TO
212 'name' => 'id',
213 'type' => CRM_Utils_Type::T_INT,
c3fc2621 214 'title' => ts('Relationship ID'),
215b423e 215 'description' => ts('Relationship ID'),
c3fc2621 216 'required' => TRUE,
a36434b9 217 'where' => 'civicrm_relationship.id',
522a26c9 218 'table_name' => 'civicrm_relationship',
219 'entity' => 'Relationship',
220 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 221 'localizable' => 0,
2cbbebe8
A
222 'html' => [
223 'type' => 'Number',
224 ],
1fe423d6 225 'readonly' => TRUE,
a9d0587b 226 'add' => '1.1',
c3fc2621
CW
227 ],
228 'contact_id_a' => [
e501603b
TO
229 'name' => 'contact_id_a',
230 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 231 'title' => ts('Contact A ID'),
215b423e 232 'description' => ts('id of the first contact'),
c3fc2621 233 'required' => TRUE,
a36434b9 234 'where' => 'civicrm_relationship.contact_id_a',
522a26c9 235 'table_name' => 'civicrm_relationship',
236 'entity' => 'Relationship',
237 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 238 'localizable' => 0,
e501603b 239 'FKClassName' => 'CRM_Contact_DAO_Contact',
2cbbebe8 240 'html' => [
0b67ced4 241 'type' => 'EntityRef',
2cbbebe8
A
242 'label' => ts("Contact A"),
243 ],
a9d0587b 244 'add' => '1.1',
c3fc2621
CW
245 ],
246 'contact_id_b' => [
e501603b
TO
247 'name' => 'contact_id_b',
248 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 249 'title' => ts('Contact B ID'),
215b423e 250 'description' => ts('id of the second contact'),
c3fc2621 251 'required' => TRUE,
a36434b9 252 'where' => 'civicrm_relationship.contact_id_b',
522a26c9 253 'table_name' => 'civicrm_relationship',
254 'entity' => 'Relationship',
255 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 256 'localizable' => 0,
e501603b 257 'FKClassName' => 'CRM_Contact_DAO_Contact',
c3fc2621 258 'html' => [
e501603b 259 'type' => 'EntityRef',
2cbbebe8 260 'label' => ts("Contact B"),
c3fc2621 261 ],
a9d0587b 262 'add' => '1.1',
c3fc2621
CW
263 ],
264 'relationship_type_id' => [
e501603b
TO
265 'name' => 'relationship_type_id',
266 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 267 'title' => ts('Relationship Type ID'),
1ac9bb56 268 'description' => ts('Type of relationship'),
c3fc2621 269 'required' => TRUE,
a36434b9 270 'where' => 'civicrm_relationship.relationship_type_id',
522a26c9 271 'table_name' => 'civicrm_relationship',
272 'entity' => 'Relationship',
273 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 274 'localizable' => 0,
e501603b 275 'FKClassName' => 'CRM_Contact_DAO_RelationshipType',
c3fc2621 276 'html' => [
e501603b 277 'type' => 'Select',
2cbbebe8 278 'label' => ts("Relationship Type"),
c3fc2621 279 ],
1ac9bb56
CW
280 'pseudoconstant' => [
281 'table' => 'civicrm_relationship_type',
282 'keyColumn' => 'id',
283 'labelColumn' => 'label_a_b',
284 'nameColumn' => 'name_a_b',
285 ],
a9d0587b 286 'add' => '1.1',
c3fc2621 287 ],
cc1b27ee 288 'relationship_start_date' => [
e501603b
TO
289 'name' => 'start_date',
290 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 291 'title' => ts('Relationship Start Date'),
215b423e 292 'description' => ts('date when the relationship started'),
a36434b9 293 'where' => 'civicrm_relationship.start_date',
522a26c9 294 'table_name' => 'civicrm_relationship',
295 'entity' => 'Relationship',
296 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 297 'localizable' => 0,
c3fc2621 298 'html' => [
e501603b 299 'type' => 'Select Date',
425d6064 300 'formatType' => 'activityDate',
c3fc2621 301 ],
a9d0587b 302 'add' => '1.1',
c3fc2621 303 ],
cc1b27ee 304 'relationship_end_date' => [
e501603b
TO
305 'name' => 'end_date',
306 'type' => CRM_Utils_Type::T_DATE,
c3fc2621 307 'title' => ts('Relationship End Date'),
215b423e 308 'description' => ts('date when the relationship ended'),
a36434b9 309 'where' => 'civicrm_relationship.end_date',
522a26c9 310 'table_name' => 'civicrm_relationship',
311 'entity' => 'Relationship',
312 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 313 'localizable' => 0,
c3fc2621 314 'html' => [
e501603b 315 'type' => 'Select Date',
425d6064 316 'formatType' => 'activityDate',
c3fc2621 317 ],
a9d0587b 318 'add' => '1.1',
c3fc2621
CW
319 ],
320 'is_active' => [
e501603b
TO
321 'name' => 'is_active',
322 'type' => CRM_Utils_Type::T_BOOLEAN,
c3fc2621 323 'title' => ts('Relationship Is Active'),
215b423e 324 'description' => ts('is the relationship active ?'),
c1e814c7 325 'required' => TRUE,
a36434b9 326 'where' => 'civicrm_relationship.is_active',
e501603b 327 'default' => '1',
522a26c9 328 'table_name' => 'civicrm_relationship',
329 'entity' => 'Relationship',
330 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 331 'localizable' => 0,
c3fc2621 332 'html' => [
e501603b 333 'type' => 'CheckBox',
c3fc2621 334 ],
a9d0587b 335 'add' => '1.1',
c3fc2621
CW
336 ],
337 'description' => [
e501603b
TO
338 'name' => 'description',
339 'type' => CRM_Utils_Type::T_STRING,
c3fc2621 340 'title' => ts('Relationship Description'),
215b423e 341 'description' => ts('Optional verbose description for the relationship.'),
e501603b
TO
342 'maxlength' => 255,
343 'size' => CRM_Utils_Type::HUGE,
a36434b9 344 'where' => 'civicrm_relationship.description',
522a26c9 345 'table_name' => 'civicrm_relationship',
346 'entity' => 'Relationship',
347 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 348 'localizable' => 0,
c3fc2621 349 'html' => [
e501603b 350 'type' => 'Text',
c3fc2621 351 ],
a9d0587b 352 'add' => '1.5',
c3fc2621
CW
353 ],
354 'is_permission_a_b' => [
e501603b 355 'name' => 'is_permission_a_b',
f871c3a9 356 'type' => CRM_Utils_Type::T_INT,
c3fc2621 357 'title' => ts('Contact A has Permission Over Contact B'),
215b423e 358 'description' => ts('Permission that Contact A has to view/update Contact B'),
f871c3a9 359 'required' => TRUE,
a36434b9 360 'where' => 'civicrm_relationship.is_permission_a_b',
45a83e42 361 'default' => '0',
522a26c9 362 'table_name' => 'civicrm_relationship',
363 'entity' => 'Relationship',
364 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 365 'localizable' => 0,
c3fc2621 366 'html' => [
f871c3a9 367 'type' => 'Radio',
c3fc2621 368 ],
f871c3a9
AS
369 'pseudoconstant' => [
370 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions',
e6ca0a57 371 ],
a9d0587b 372 'add' => '2.1',
c3fc2621
CW
373 ],
374 'is_permission_b_a' => [
e501603b 375 'name' => 'is_permission_b_a',
f871c3a9 376 'type' => CRM_Utils_Type::T_INT,
c3fc2621 377 'title' => ts('Contact B has Permission Over Contact A'),
215b423e 378 'description' => ts('Permission that Contact B has to view/update Contact A'),
f871c3a9 379 'required' => TRUE,
a36434b9 380 'where' => 'civicrm_relationship.is_permission_b_a',
45a83e42 381 'default' => '0',
522a26c9 382 'table_name' => 'civicrm_relationship',
383 'entity' => 'Relationship',
384 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 385 'localizable' => 0,
c3fc2621 386 'html' => [
f871c3a9 387 'type' => 'Radio',
c3fc2621 388 ],
f871c3a9
AS
389 'pseudoconstant' => [
390 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions',
e6ca0a57 391 ],
a9d0587b 392 'add' => '2.1',
c3fc2621
CW
393 ],
394 'case_id' => [
e501603b
TO
395 'name' => 'case_id',
396 'type' => CRM_Utils_Type::T_INT,
2cbbebe8 397 'title' => ts('Case ID'),
215b423e 398 'description' => ts('FK to civicrm_case'),
a36434b9 399 'where' => 'civicrm_relationship.case_id',
5fb0de1f 400 'default' => NULL,
522a26c9 401 'table_name' => 'civicrm_relationship',
402 'entity' => 'Relationship',
403 'bao' => 'CRM_Contact_BAO_Relationship',
6a7e5e5d 404 'localizable' => 0,
e501603b 405 'FKClassName' => 'CRM_Case_DAO_Case',
8269c13e 406 'component' => 'CiviCase',
2cbbebe8
A
407 'html' => [
408 'label' => ts("Case"),
409 ],
a9d0587b 410 'add' => '2.2',
c3fc2621 411 ],
a0efcd4d
EM
412 'created_date' => [
413 'name' => 'created_date',
414 'type' => CRM_Utils_Type::T_TIMESTAMP,
415 'title' => ts('Created Date'),
416 'description' => ts('Relationship created date.'),
417 'required' => TRUE,
418 'where' => 'civicrm_relationship.created_date',
419 'default' => 'CURRENT_TIMESTAMP',
420 'table_name' => 'civicrm_relationship',
421 'entity' => 'Relationship',
422 'bao' => 'CRM_Contact_BAO_Relationship',
423 'localizable' => 0,
424 'add' => '5.47',
425 ],
426 'modified_date' => [
427 'name' => 'modified_date',
428 'type' => CRM_Utils_Type::T_TIMESTAMP,
429 'title' => ts('Relationship Modified Date'),
430 'description' => ts('Relationship last modified.'),
431 'required' => TRUE,
432 'where' => 'civicrm_relationship.modified_date',
433 'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
434 'table_name' => 'civicrm_relationship',
435 'entity' => 'Relationship',
436 'bao' => 'CRM_Contact_BAO_Relationship',
437 'localizable' => 0,
438 'readonly' => TRUE,
439 'add' => '5.47',
440 ],
c3fc2621 441 ];
346aaaba 442 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
e501603b 443 }
346aaaba 444 return Civi::$statics[__CLASS__]['fields'];
e501603b 445 }
c3fc2621 446
e501603b 447 /**
bd8e0b14 448 * Return a mapping from field-name to the corresponding key (as used in fields()).
e501603b
TO
449 *
450 * @return array
bd8e0b14 451 * Array(string $name => string $uniqueName).
e501603b 452 */
c3fc2621 453 public static function &fieldKeys() {
bd8e0b14
TO
454 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
455 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
e501603b 456 }
bd8e0b14 457 return Civi::$statics[__CLASS__]['fieldKeys'];
e501603b 458 }
c3fc2621 459
e501603b
TO
460 /**
461 * Returns the names of this table
462 *
463 * @return string
464 */
c3fc2621 465 public static function getTableName() {
e501603b
TO
466 return self::$_tableName;
467 }
c3fc2621 468
e501603b
TO
469 /**
470 * Returns if this table needs to be logged
471 *
c3fc2621 472 * @return bool
e501603b 473 */
c3fc2621 474 public function getLog() {
e501603b
TO
475 return self::$_log;
476 }
c3fc2621 477
e501603b
TO
478 /**
479 * Returns the list of fields that can be imported
480 *
481 * @param bool $prefix
482 *
483 * @return array
484 */
c3fc2621
CW
485 public static function &import($prefix = FALSE) {
486 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'relationship', $prefix, []);
60808919 487 return $r;
e501603b 488 }
c3fc2621 489
e501603b
TO
490 /**
491 * Returns the list of fields that can be exported
492 *
493 * @param bool $prefix
494 *
495 * @return array
496 */
c3fc2621
CW
497 public static function &export($prefix = FALSE) {
498 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'relationship', $prefix, []);
60808919 499 return $r;
e501603b 500 }
c3fc2621 501
e7a6b91a
AS
502 /**
503 * Returns the list of indices
c3fc2621
CW
504 *
505 * @param bool $localize
506 *
507 * @return array
e7a6b91a
AS
508 */
509 public static function indices($localize = TRUE) {
c3fc2621 510 $indices = [];
e7a6b91a
AS
511 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
512 }
c3fc2621 513
e501603b 514}