3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class contain function for IM handling
23 class CRM_Core_BAO_IM
extends CRM_Core_DAO_IM
{
26 * Takes an associative array and adds im.
28 * @param array $params
29 * (reference ) an assoc array of name/value pairs.
32 * CRM_Core_BAO_IM object on success, null otherwise
34 public static function add(&$params) {
35 $hook = empty($params['id']) ?
'create' : 'edit';
36 CRM_Utils_Hook
::pre($hook, 'IM', CRM_Utils_Array
::value('id', $params), $params);
38 $im = new CRM_Core_DAO_IM();
39 $im->copyValues($params);
42 CRM_Utils_Hook
::post($hook, 'IM', $im->id
, $im);
47 * Given the list of params in the params array, fetch the object
48 * and store the values in the values array
50 * @param array $entityBlock input parameters to find object
54 public static function &getValues($entityBlock) {
55 return CRM_Core_BAO_Block
::getValues('im', $entityBlock);
59 * Get all the ims for a specified contact_id, with the primary im being first
64 * @param bool $updateBlankLocInfo
67 * the array of im details
69 public static function allIMs($id, $updateBlankLocInfo = FALSE) {
75 SELECT civicrm_im.name as im, civicrm_location_type.name as locationType, civicrm_im.is_primary as is_primary,
76 civicrm_im.id as im_id, civicrm_im.location_type_id as locationTypeId,
77 civicrm_im.provider_id as providerId
79 LEFT JOIN civicrm_im ON ( civicrm_im.contact_id = civicrm_contact.id )
80 LEFT JOIN civicrm_location_type ON ( civicrm_im.location_type_id = civicrm_location_type.id )
82 civicrm_contact.id = %1
84 civicrm_im.is_primary DESC, im_id ASC ";
85 $params = [1 => [$id, 'Integer']];
88 $dao = CRM_Core_DAO
::executeQuery($query, $params);
90 while ($dao->fetch()) {
92 'locationType' => $dao->locationType
,
93 'is_primary' => $dao->is_primary
,
96 'locationTypeId' => $dao->locationTypeId
,
97 'providerId' => $dao->providerId
,
100 if ($updateBlankLocInfo) {
101 $ims[$count++
] = $values;
104 $ims[$dao->im_id
] = $values;
111 * Get all the ims for a specified location_block id, with the primary im being first
113 * @param array $entityElements
114 * The array containing entity_id and.
118 * the array of im details
120 public static function allEntityIMs(&$entityElements) {
121 if (empty($entityElements)) {
124 $entityId = $entityElements['entity_id'];
125 $entityTable = $entityElements['entity_table'];
126 $sql = "SELECT cim.name as im, ltype.name as locationType, cim.is_primary as is_primary, cim.id as im_id, cim.location_type_id as locationTypeId
127 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev
129 AND loc.id = ev.loc_block_id
130 AND cim.id IN (loc.im_id, loc.im_2_id)
131 AND ltype.id = cim.location_type_id
132 ORDER BY cim.is_primary DESC, im_id ASC ";
134 $params = [1 => [$entityId, 'Integer']];
137 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
138 while ($dao->fetch()) {
139 $ims[$dao->im_id
] = [
140 'locationType' => $dao->locationType
,
141 'is_primary' => $dao->is_primary
,
144 'locationTypeId' => $dao->locationTypeId
,
151 * Call common delete function.
157 public static function del($id) {
158 return CRM_Contact_BAO_Contact
::deleteObjectWithPrimary('IM', $id);