f9e0c8ecc7fbd08c9684d9fe1aed89686e8ad079
[civicrm-core.git] / CRM / Contact / DAO / RelationshipCache.php
1 <?php
2
3 /**
4 * @package CRM
5 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 *
7 * Generated from xml/schema/CRM/Contact/RelationshipCache.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:f70f357cd7e45be254350f45ef41aee2)
10 */
11
12 /**
13 * Database access object for the RelationshipCache entity.
14 */
15 class CRM_Contact_DAO_RelationshipCache extends CRM_Core_DAO {
16 const EXT = 'civicrm';
17 const TABLE_ADDED = '5.29';
18
19 /**
20 * Static instance to hold the table name.
21 *
22 * @var string
23 */
24 public static $_tableName = 'civicrm_relationship_cache';
25
26 /**
27 * Icon associated with this entity.
28 *
29 * @var string
30 */
31 public static $_icon = 'fa-handshake-o';
32
33 /**
34 * Should CiviCRM log any modifications to this table in the civicrm_log table.
35 *
36 * @var bool
37 */
38 public static $_log = FALSE;
39
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=[near_contact_id]&id=[relationship_id]',
47 'update' => 'civicrm/contact/view/rel?action=update&reset=1&cid=[near_contact_id]&id=[relationship_id]&rtype=[orientation]',
48 'delete' => 'civicrm/contact/view/rel?action=delete&reset=1&cid=[near_contact_id]&id=[relationship_id]',
49 ];
50
51 /**
52 * Relationship Cache ID
53 *
54 * @var int
55 */
56 public $id;
57
58 /**
59 * id of the relationship (FK to civicrm_relationship.id)
60 *
61 * @var int
62 */
63 public $relationship_id;
64
65 /**
66 * id of the relationship type
67 *
68 * @var int
69 */
70 public $relationship_type_id;
71
72 /**
73 * The cache record is a permutation of the original relationship record. The orientation indicates whether it is forward (a_b) or reverse (b_a) relationship.
74 *
75 * @var string
76 */
77 public $orientation;
78
79 /**
80 * id of the first contact
81 *
82 * @var int
83 */
84 public $near_contact_id;
85
86 /**
87 * name for relationship of near_contact to far_contact.
88 *
89 * @var string
90 */
91 public $near_relation;
92
93 /**
94 * id of the second contact
95 *
96 * @var int
97 */
98 public $far_contact_id;
99
100 /**
101 * name for relationship of far_contact to near_contact.
102 *
103 * @var string
104 */
105 public $far_relation;
106
107 /**
108 * is the relationship active ?
109 *
110 * @var bool
111 */
112 public $is_active;
113
114 /**
115 * date when the relationship started
116 *
117 * @var date
118 */
119 public $start_date;
120
121 /**
122 * date when the relationship ended
123 *
124 * @var date
125 */
126 public $end_date;
127
128 /**
129 * FK to civicrm_case
130 *
131 * @var int
132 */
133 public $case_id;
134
135 /**
136 * Class constructor.
137 */
138 public function __construct() {
139 $this->__table = 'civicrm_relationship_cache';
140 parent::__construct();
141 }
142
143 /**
144 * Returns localized title of this entity.
145 *
146 * @param bool $plural
147 * Whether to return the plural version of the title.
148 */
149 public static function getEntityTitle($plural = FALSE) {
150 return $plural ? ts('Related Contacts') : ts('Related Contact');
151 }
152
153 /**
154 * Returns foreign keys and entity references.
155 *
156 * @return array
157 * [CRM_Core_Reference_Interface]
158 */
159 public static function getReferenceColumns() {
160 if (!isset(Civi::$statics[__CLASS__]['links'])) {
161 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
162 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'relationship_id', 'civicrm_relationship', 'id');
163 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'relationship_type_id', 'civicrm_relationship_type', 'id');
164 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'near_contact_id', 'civicrm_contact', 'id');
165 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'far_contact_id', 'civicrm_contact', 'id');
166 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'case_id', 'civicrm_case', 'id');
167 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
168 }
169 return Civi::$statics[__CLASS__]['links'];
170 }
171
172 /**
173 * Returns all the column names of this table
174 *
175 * @return array
176 */
177 public static function &fields() {
178 if (!isset(Civi::$statics[__CLASS__]['fields'])) {
179 Civi::$statics[__CLASS__]['fields'] = [
180 'id' => [
181 'name' => 'id',
182 'type' => CRM_Utils_Type::T_INT,
183 'title' => ts('Relationship Cache ID'),
184 'description' => ts('Relationship Cache ID'),
185 'required' => TRUE,
186 'where' => 'civicrm_relationship_cache.id',
187 'table_name' => 'civicrm_relationship_cache',
188 'entity' => 'RelationshipCache',
189 'bao' => 'CRM_Contact_BAO_RelationshipCache',
190 'localizable' => 0,
191 'html' => [
192 'type' => 'Number',
193 ],
194 'readonly' => TRUE,
195 'add' => '5.29',
196 ],
197 'relationship_id' => [
198 'name' => 'relationship_id',
199 'type' => CRM_Utils_Type::T_INT,
200 'title' => ts('Relationship ID'),
201 'description' => ts('id of the relationship (FK to civicrm_relationship.id)'),
202 'required' => TRUE,
203 'where' => 'civicrm_relationship_cache.relationship_id',
204 'table_name' => 'civicrm_relationship_cache',
205 'entity' => 'RelationshipCache',
206 'bao' => 'CRM_Contact_BAO_RelationshipCache',
207 'localizable' => 0,
208 'FKClassName' => 'CRM_Contact_DAO_Relationship',
209 'html' => [
210 'label' => ts("Relationship"),
211 ],
212 'readonly' => TRUE,
213 'add' => '5.29',
214 ],
215 'relationship_type_id' => [
216 'name' => 'relationship_type_id',
217 'type' => CRM_Utils_Type::T_INT,
218 'title' => ts('Relationship Type ID'),
219 'description' => ts('id of the relationship type'),
220 'required' => TRUE,
221 'where' => 'civicrm_relationship_cache.relationship_type_id',
222 'table_name' => 'civicrm_relationship_cache',
223 'entity' => 'RelationshipCache',
224 'bao' => 'CRM_Contact_BAO_RelationshipCache',
225 'localizable' => 0,
226 'FKClassName' => 'CRM_Contact_DAO_RelationshipType',
227 'html' => [
228 'label' => ts("Relationship Type"),
229 ],
230 'readonly' => TRUE,
231 'add' => '5.29',
232 ],
233 'orientation' => [
234 'name' => 'orientation',
235 'type' => CRM_Utils_Type::T_STRING,
236 'title' => ts('Orientation (a_b or b_a)'),
237 'description' => ts('The cache record is a permutation of the original relationship record. The orientation indicates whether it is forward (a_b) or reverse (b_a) relationship.'),
238 'required' => TRUE,
239 'maxlength' => 3,
240 'size' => CRM_Utils_Type::FOUR,
241 'where' => 'civicrm_relationship_cache.orientation',
242 'table_name' => 'civicrm_relationship_cache',
243 'entity' => 'RelationshipCache',
244 'bao' => 'CRM_Contact_BAO_RelationshipCache',
245 'localizable' => 0,
246 'pseudoconstant' => [
247 'callback' => 'CRM_Core_SelectValues::relationshipOrientation',
248 ],
249 'readonly' => TRUE,
250 'add' => '5.29',
251 ],
252 'near_contact_id' => [
253 'name' => 'near_contact_id',
254 'type' => CRM_Utils_Type::T_INT,
255 'title' => ts('Contact ID (Near side)'),
256 'description' => ts('id of the first contact'),
257 'required' => TRUE,
258 'where' => 'civicrm_relationship_cache.near_contact_id',
259 'table_name' => 'civicrm_relationship_cache',
260 'entity' => 'RelationshipCache',
261 'bao' => 'CRM_Contact_BAO_RelationshipCache',
262 'localizable' => 0,
263 'FKClassName' => 'CRM_Contact_DAO_Contact',
264 'html' => [
265 'type' => 'EntityRef',
266 'label' => ts("Contact (Near side)"),
267 ],
268 'readonly' => TRUE,
269 'add' => '5.29',
270 ],
271 'near_relation' => [
272 'name' => 'near_relation',
273 'type' => CRM_Utils_Type::T_STRING,
274 'title' => ts('Relationship Name (to related contact)'),
275 'description' => ts('name for relationship of near_contact to far_contact.'),
276 'maxlength' => 64,
277 'size' => CRM_Utils_Type::BIG,
278 'where' => 'civicrm_relationship_cache.near_relation',
279 'table_name' => 'civicrm_relationship_cache',
280 'entity' => 'RelationshipCache',
281 'bao' => 'CRM_Contact_BAO_RelationshipCache',
282 'localizable' => 0,
283 'html' => [
284 'label' => ts("Relationship to contact"),
285 ],
286 'pseudoconstant' => [
287 'callback' => 'CRM_Core_PseudoConstant::relationshipTypeOptions',
288 ],
289 'readonly' => TRUE,
290 'add' => '5.29',
291 ],
292 'far_contact_id' => [
293 'name' => 'far_contact_id',
294 'type' => CRM_Utils_Type::T_INT,
295 'title' => ts('Contact ID (Far side)'),
296 'description' => ts('id of the second contact'),
297 'required' => TRUE,
298 'where' => 'civicrm_relationship_cache.far_contact_id',
299 'table_name' => 'civicrm_relationship_cache',
300 'entity' => 'RelationshipCache',
301 'bao' => 'CRM_Contact_BAO_RelationshipCache',
302 'localizable' => 0,
303 'FKClassName' => 'CRM_Contact_DAO_Contact',
304 'html' => [
305 'type' => 'EntityRef',
306 'label' => ts("Contact (Far side)"),
307 ],
308 'readonly' => TRUE,
309 'add' => '5.29',
310 ],
311 'far_relation' => [
312 'name' => 'far_relation',
313 'type' => CRM_Utils_Type::T_STRING,
314 'title' => ts('Relationship Name (from related contact)'),
315 'description' => ts('name for relationship of far_contact to near_contact.'),
316 'maxlength' => 64,
317 'size' => CRM_Utils_Type::BIG,
318 'where' => 'civicrm_relationship_cache.far_relation',
319 'table_name' => 'civicrm_relationship_cache',
320 'entity' => 'RelationshipCache',
321 'bao' => 'CRM_Contact_BAO_RelationshipCache',
322 'localizable' => 0,
323 'html' => [
324 'label' => ts("Relationship from contact"),
325 ],
326 'pseudoconstant' => [
327 'callback' => 'CRM_Core_PseudoConstant::relationshipTypeOptions',
328 ],
329 'readonly' => TRUE,
330 'add' => '5.29',
331 ],
332 'is_active' => [
333 'name' => 'is_active',
334 'type' => CRM_Utils_Type::T_BOOLEAN,
335 'title' => ts('Relationship Is Active'),
336 'description' => ts('is the relationship active ?'),
337 'where' => 'civicrm_relationship_cache.is_active',
338 'default' => '1',
339 'table_name' => 'civicrm_relationship_cache',
340 'entity' => 'RelationshipCache',
341 'bao' => 'CRM_Contact_BAO_RelationshipCache',
342 'localizable' => 0,
343 'html' => [
344 'type' => 'CheckBox',
345 ],
346 'readonly' => TRUE,
347 'add' => '5.29',
348 ],
349 'relationship_start_date' => [
350 'name' => 'start_date',
351 'type' => CRM_Utils_Type::T_DATE,
352 'title' => ts('Relationship Start Date'),
353 'description' => ts('date when the relationship started'),
354 'where' => 'civicrm_relationship_cache.start_date',
355 'table_name' => 'civicrm_relationship_cache',
356 'entity' => 'RelationshipCache',
357 'bao' => 'CRM_Contact_BAO_RelationshipCache',
358 'localizable' => 0,
359 'html' => [
360 'type' => 'Select Date',
361 'formatType' => 'activityDate',
362 ],
363 'readonly' => TRUE,
364 'add' => '5.29',
365 ],
366 'relationship_end_date' => [
367 'name' => 'end_date',
368 'type' => CRM_Utils_Type::T_DATE,
369 'title' => ts('Relationship End Date'),
370 'description' => ts('date when the relationship ended'),
371 'where' => 'civicrm_relationship_cache.end_date',
372 'table_name' => 'civicrm_relationship_cache',
373 'entity' => 'RelationshipCache',
374 'bao' => 'CRM_Contact_BAO_RelationshipCache',
375 'localizable' => 0,
376 'html' => [
377 'type' => 'Select Date',
378 'formatType' => 'activityDate',
379 ],
380 'readonly' => TRUE,
381 'add' => '5.29',
382 ],
383 'case_id' => [
384 'name' => 'case_id',
385 'type' => CRM_Utils_Type::T_INT,
386 'title' => ts('Case ID'),
387 'description' => ts('FK to civicrm_case'),
388 'where' => 'civicrm_relationship_cache.case_id',
389 'default' => 'NULL',
390 'table_name' => 'civicrm_relationship_cache',
391 'entity' => 'RelationshipCache',
392 'bao' => 'CRM_Contact_BAO_RelationshipCache',
393 'localizable' => 0,
394 'FKClassName' => 'CRM_Case_DAO_Case',
395 'component' => 'CiviCase',
396 'html' => [
397 'label' => ts("Case"),
398 ],
399 'readonly' => TRUE,
400 'add' => '5.44',
401 ],
402 ];
403 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
404 }
405 return Civi::$statics[__CLASS__]['fields'];
406 }
407
408 /**
409 * Return a mapping from field-name to the corresponding key (as used in fields()).
410 *
411 * @return array
412 * Array(string $name => string $uniqueName).
413 */
414 public static function &fieldKeys() {
415 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
416 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
417 }
418 return Civi::$statics[__CLASS__]['fieldKeys'];
419 }
420
421 /**
422 * Returns the names of this table
423 *
424 * @return string
425 */
426 public static function getTableName() {
427 return self::$_tableName;
428 }
429
430 /**
431 * Returns if this table needs to be logged
432 *
433 * @return bool
434 */
435 public function getLog() {
436 return self::$_log;
437 }
438
439 /**
440 * Returns the list of fields that can be imported
441 *
442 * @param bool $prefix
443 *
444 * @return array
445 */
446 public static function &import($prefix = FALSE) {
447 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'relationship_cache', $prefix, []);
448 return $r;
449 }
450
451 /**
452 * Returns the list of fields that can be exported
453 *
454 * @param bool $prefix
455 *
456 * @return array
457 */
458 public static function &export($prefix = FALSE) {
459 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'relationship_cache', $prefix, []);
460 return $r;
461 }
462
463 /**
464 * Returns the list of indices
465 *
466 * @param bool $localize
467 *
468 * @return array
469 */
470 public static function indices($localize = TRUE) {
471 $indices = [
472 'UI_relationship' => [
473 'name' => 'UI_relationship',
474 'field' => [
475 0 => 'relationship_id',
476 1 => 'orientation',
477 ],
478 'localizable' => FALSE,
479 'unique' => TRUE,
480 'sig' => 'civicrm_relationship_cache::1::relationship_id::orientation',
481 ],
482 'index_nearid_nearrelation' => [
483 'name' => 'index_nearid_nearrelation',
484 'field' => [
485 0 => 'near_contact_id',
486 1 => 'near_relation',
487 ],
488 'localizable' => FALSE,
489 'sig' => 'civicrm_relationship_cache::0::near_contact_id::near_relation',
490 ],
491 'index_nearid_farrelation' => [
492 'name' => 'index_nearid_farrelation',
493 'field' => [
494 0 => 'near_contact_id',
495 1 => 'far_relation',
496 ],
497 'localizable' => FALSE,
498 'sig' => 'civicrm_relationship_cache::0::near_contact_id::far_relation',
499 ],
500 'index_near_relation' => [
501 'name' => 'index_near_relation',
502 'field' => [
503 0 => 'near_relation',
504 ],
505 'localizable' => FALSE,
506 'sig' => 'civicrm_relationship_cache::0::near_relation',
507 ],
508 ];
509 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
510 }
511
512 }