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 * Create or update IM record.
28 * @param array $params
29 * @return CRM_Core_DAO_IM
31 public static function add($params) {
32 return self
::writeRecord($params);
36 * Given the list of params in the params array, fetch the object
37 * and store the values in the values array
39 * @param array $entityBlock input parameters to find object
43 public static function &getValues($entityBlock) {
44 return CRM_Core_BAO_Block
::getValues('im', $entityBlock);
48 * Get all the ims for a specified contact_id, with the primary im being first
53 * @param bool $updateBlankLocInfo
56 * the array of im details
58 public static function allIMs($id, $updateBlankLocInfo = FALSE) {
64 SELECT civicrm_im.name as im, civicrm_location_type.name as locationType, civicrm_im.is_primary as is_primary,
65 civicrm_im.id as im_id, civicrm_im.location_type_id as locationTypeId,
66 civicrm_im.provider_id as providerId
68 LEFT JOIN civicrm_im ON ( civicrm_im.contact_id = civicrm_contact.id )
69 LEFT JOIN civicrm_location_type ON ( civicrm_im.location_type_id = civicrm_location_type.id )
71 civicrm_contact.id = %1
73 civicrm_im.is_primary DESC, im_id ASC ";
74 $params = [1 => [$id, 'Integer']];
77 $dao = CRM_Core_DAO
::executeQuery($query, $params);
79 while ($dao->fetch()) {
81 'locationType' => $dao->locationType
,
82 'is_primary' => $dao->is_primary
,
85 'locationTypeId' => $dao->locationTypeId
,
86 'providerId' => $dao->providerId
,
89 if ($updateBlankLocInfo) {
90 $ims[$count++
] = $values;
93 $ims[$dao->im_id
] = $values;
100 * Get all the ims for a specified location_block id, with the primary im being first
102 * @param array $entityElements
103 * The array containing entity_id and.
107 * the array of im details
109 public static function allEntityIMs(&$entityElements) {
110 if (empty($entityElements)) {
113 $entityId = $entityElements['entity_id'];
114 $entityTable = $entityElements['entity_table'];
115 $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
116 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev
118 AND loc.id = ev.loc_block_id
119 AND cim.id IN (loc.im_id, loc.im_2_id)
120 AND ltype.id = cim.location_type_id
121 ORDER BY cim.is_primary DESC, im_id ASC ";
123 $params = [1 => [$entityId, 'Integer']];
126 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
127 while ($dao->fetch()) {
128 $ims[$dao->im_id
] = [
129 'locationType' => $dao->locationType
,
130 'is_primary' => $dao->is_primary
,
133 'locationTypeId' => $dao->locationTypeId
,
140 * Call common delete function.
146 public static function del($id) {
147 return CRM_Contact_BAO_Contact
::deleteObjectWithPrimary('IM', $id);