5 * @copyright CiviCRM LLC https://civicrm.org/licensing
7 * Generated from xml/schema/CRM/Contact/Relationship.xml
8 * DO NOT EDIT. Generated by CRM_Core_CodeGen
9 * (GenCodeChecksum:3c7051137838e12caf53b96b8c369f2b)
13 * Database access object for the Relationship entity.
15 class CRM_Contact_DAO_Relationship
extends CRM_Core_DAO
{
16 const EXT
= 'civicrm';
17 const TABLE_ADDED
= '1.1';
20 * Static instance to hold the table name.
24 public static $_tableName = 'civicrm_relationship';
27 * Icon associated with this entity.
31 public static $_icon = 'fa-handshake-o';
34 * Should CiviCRM log any modifications to this table in the civicrm_log table.
38 public static $_log = TRUE;
41 * Paths for accessing this entity in the UI.
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]',
53 * @var int|string|null
54 * (SQL type: int unsigned)
55 * Note that values will be retrieved from the database as a string.
60 * id of the first contact
63 * (SQL type: int unsigned)
64 * Note that values will be retrieved from the database as a string.
69 * id of the second contact
72 * (SQL type: int unsigned)
73 * Note that values will be retrieved from the database as a string.
78 * Type of relationship
81 * (SQL type: int unsigned)
82 * Note that values will be retrieved from the database as a string.
84 public $relationship_type_id;
87 * date when the relationship started
91 * Note that values will be retrieved from the database as a string.
96 * date when the relationship ended
100 * Note that values will be retrieved from the database as a string.
105 * is the relationship active ?
108 * (SQL type: tinyint)
109 * Note that values will be retrieved from the database as a string.
114 * Optional verbose description for the relationship.
117 * (SQL type: varchar(255))
118 * Note that values will be retrieved from the database as a string.
123 * Permission that Contact A has to view/update Contact B
126 * (SQL type: int unsigned)
127 * Note that values will be retrieved from the database as a string.
129 public $is_permission_a_b;
132 * Permission that Contact B has to view/update Contact A
135 * (SQL type: int unsigned)
136 * Note that values will be retrieved from the database as a string.
138 public $is_permission_b_a;
143 * @var int|string|null
144 * (SQL type: int unsigned)
145 * Note that values will be retrieved from the database as a string.
150 * Relationship created date.
153 * (SQL type: timestamp)
154 * Note that values will be retrieved from the database as a string.
156 public $created_date;
159 * Relationship last modified.
162 * (SQL type: timestamp)
163 * Note that values will be retrieved from the database as a string.
165 public $modified_date;
170 public function __construct() {
171 $this->__table
= 'civicrm_relationship';
172 parent
::__construct();
176 * Returns localized title of this entity.
178 * @param bool $plural
179 * Whether to return the plural version of the title.
181 public static function getEntityTitle($plural = FALSE) {
182 return $plural ?
ts('Relationships') : ts('Relationship');
186 * Returns foreign keys and entity references.
189 * [CRM_Core_Reference_Interface]
191 public static function getReferenceColumns() {
192 if (!isset(Civi
::$statics[__CLASS__
]['links'])) {
193 Civi
::$statics[__CLASS__
]['links'] = static::createReferenceColumns(__CLASS__
);
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');
198 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'links_callback', Civi
::$statics[__CLASS__
]['links']);
200 return Civi
::$statics[__CLASS__
]['links'];
204 * Returns all the column names of this table
208 public static function &fields() {
209 if (!isset(Civi
::$statics[__CLASS__
]['fields'])) {
210 Civi
::$statics[__CLASS__
]['fields'] = [
213 'type' => CRM_Utils_Type
::T_INT
,
214 'title' => ts('Relationship ID'),
215 'description' => ts('Relationship ID'),
217 'where' => 'civicrm_relationship.id',
218 'table_name' => 'civicrm_relationship',
219 'entity' => 'Relationship',
220 'bao' => 'CRM_Contact_BAO_Relationship',
229 'name' => 'contact_id_a',
230 'type' => CRM_Utils_Type
::T_INT
,
231 'title' => ts('Contact A ID'),
232 'description' => ts('id of the first contact'),
234 'where' => 'civicrm_relationship.contact_id_a',
235 'table_name' => 'civicrm_relationship',
236 'entity' => 'Relationship',
237 'bao' => 'CRM_Contact_BAO_Relationship',
239 'FKClassName' => 'CRM_Contact_DAO_Contact',
241 'type' => 'EntityRef',
242 'label' => ts("Contact A"),
247 'name' => 'contact_id_b',
248 'type' => CRM_Utils_Type
::T_INT
,
249 'title' => ts('Contact B ID'),
250 'description' => ts('id of the second contact'),
252 'where' => 'civicrm_relationship.contact_id_b',
253 'table_name' => 'civicrm_relationship',
254 'entity' => 'Relationship',
255 'bao' => 'CRM_Contact_BAO_Relationship',
257 'FKClassName' => 'CRM_Contact_DAO_Contact',
259 'type' => 'EntityRef',
260 'label' => ts("Contact B"),
264 'relationship_type_id' => [
265 'name' => 'relationship_type_id',
266 'type' => CRM_Utils_Type
::T_INT
,
267 'title' => ts('Relationship Type ID'),
268 'description' => ts('Type of relationship'),
270 'where' => 'civicrm_relationship.relationship_type_id',
271 'table_name' => 'civicrm_relationship',
272 'entity' => 'Relationship',
273 'bao' => 'CRM_Contact_BAO_Relationship',
275 'FKClassName' => 'CRM_Contact_DAO_RelationshipType',
278 'label' => ts("Relationship Type"),
280 'pseudoconstant' => [
281 'table' => 'civicrm_relationship_type',
283 'labelColumn' => 'label_a_b',
284 'nameColumn' => 'name_a_b',
288 'relationship_start_date' => [
289 'name' => 'start_date',
290 'type' => CRM_Utils_Type
::T_DATE
,
291 'title' => ts('Relationship Start Date'),
292 'description' => ts('date when the relationship started'),
293 'where' => 'civicrm_relationship.start_date',
294 'table_name' => 'civicrm_relationship',
295 'entity' => 'Relationship',
296 'bao' => 'CRM_Contact_BAO_Relationship',
299 'type' => 'Select Date',
300 'formatType' => 'activityDate',
304 'relationship_end_date' => [
305 'name' => 'end_date',
306 'type' => CRM_Utils_Type
::T_DATE
,
307 'title' => ts('Relationship End Date'),
308 'description' => ts('date when the relationship ended'),
309 'where' => 'civicrm_relationship.end_date',
310 'table_name' => 'civicrm_relationship',
311 'entity' => 'Relationship',
312 'bao' => 'CRM_Contact_BAO_Relationship',
315 'type' => 'Select Date',
316 'formatType' => 'activityDate',
321 'name' => 'is_active',
322 'type' => CRM_Utils_Type
::T_BOOLEAN
,
323 'title' => ts('Relationship Is Active'),
324 'description' => ts('is the relationship active ?'),
326 'where' => 'civicrm_relationship.is_active',
328 'table_name' => 'civicrm_relationship',
329 'entity' => 'Relationship',
330 'bao' => 'CRM_Contact_BAO_Relationship',
333 'type' => 'CheckBox',
338 'name' => 'description',
339 'type' => CRM_Utils_Type
::T_STRING
,
340 'title' => ts('Relationship Description'),
341 'description' => ts('Optional verbose description for the relationship.'),
343 'size' => CRM_Utils_Type
::HUGE
,
344 'where' => 'civicrm_relationship.description',
345 'table_name' => 'civicrm_relationship',
346 'entity' => 'Relationship',
347 'bao' => 'CRM_Contact_BAO_Relationship',
354 'is_permission_a_b' => [
355 'name' => 'is_permission_a_b',
356 'type' => CRM_Utils_Type
::T_INT
,
357 'title' => ts('Contact A has Permission Over Contact B'),
358 'description' => ts('Permission that Contact A has to view/update Contact B'),
360 'where' => 'civicrm_relationship.is_permission_a_b',
362 'table_name' => 'civicrm_relationship',
363 'entity' => 'Relationship',
364 'bao' => 'CRM_Contact_BAO_Relationship',
369 'pseudoconstant' => [
370 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions',
374 'is_permission_b_a' => [
375 'name' => 'is_permission_b_a',
376 'type' => CRM_Utils_Type
::T_INT
,
377 'title' => ts('Contact B has Permission Over Contact A'),
378 'description' => ts('Permission that Contact B has to view/update Contact A'),
380 'where' => 'civicrm_relationship.is_permission_b_a',
382 'table_name' => 'civicrm_relationship',
383 'entity' => 'Relationship',
384 'bao' => 'CRM_Contact_BAO_Relationship',
389 'pseudoconstant' => [
390 'callback' => 'CRM_Core_SelectValues::getPermissionedRelationshipOptions',
396 'type' => CRM_Utils_Type
::T_INT
,
397 'title' => ts('Case ID'),
398 'description' => ts('FK to civicrm_case'),
399 'where' => 'civicrm_relationship.case_id',
401 'table_name' => 'civicrm_relationship',
402 'entity' => 'Relationship',
403 'bao' => 'CRM_Contact_BAO_Relationship',
405 'FKClassName' => 'CRM_Case_DAO_Case',
406 'component' => 'CiviCase',
408 'label' => ts("Case"),
413 'name' => 'created_date',
414 'type' => CRM_Utils_Type
::T_TIMESTAMP
,
415 'title' => ts('Created Date'),
416 'description' => ts('Relationship created date.'),
418 'where' => 'civicrm_relationship.created_date',
419 'default' => 'CURRENT_TIMESTAMP',
420 'table_name' => 'civicrm_relationship',
421 'entity' => 'Relationship',
422 'bao' => 'CRM_Contact_BAO_Relationship',
427 'name' => 'modified_date',
428 'type' => CRM_Utils_Type
::T_TIMESTAMP
,
429 'title' => ts('Relationship Modified Date'),
430 'description' => ts('Relationship last modified.'),
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',
442 CRM_Core_DAO_AllCoreTables
::invoke(__CLASS__
, 'fields_callback', Civi
::$statics[__CLASS__
]['fields']);
444 return Civi
::$statics[__CLASS__
]['fields'];
448 * Return a mapping from field-name to the corresponding key (as used in fields()).
451 * Array(string $name => string $uniqueName).
453 public static function &fieldKeys() {
454 if (!isset(Civi
::$statics[__CLASS__
]['fieldKeys'])) {
455 Civi
::$statics[__CLASS__
]['fieldKeys'] = array_flip(CRM_Utils_Array
::collect('name', self
::fields()));
457 return Civi
::$statics[__CLASS__
]['fieldKeys'];
461 * Returns the names of this table
465 public static function getTableName() {
466 return self
::$_tableName;
470 * Returns if this table needs to be logged
474 public function getLog() {
479 * Returns the list of fields that can be imported
481 * @param bool $prefix
485 public static function &import($prefix = FALSE) {
486 $r = CRM_Core_DAO_AllCoreTables
::getImports(__CLASS__
, 'relationship', $prefix, []);
491 * Returns the list of fields that can be exported
493 * @param bool $prefix
497 public static function &export($prefix = FALSE) {
498 $r = CRM_Core_DAO_AllCoreTables
::getExports(__CLASS__
, 'relationship', $prefix, []);
503 * Returns the list of indices
505 * @param bool $localize
509 public static function indices($localize = TRUE) {
511 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables
::multilingualize(__CLASS__
, $indices) : $indices;