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
19 * This class contain function for IM handling
21 class CRM_Core_BAO_IM
extends CRM_Core_DAO_IM
{
22 use CRM_Contact_AccessTrait
;
25 * Create or update IM record.
27 * @param array $params
29 * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
30 * @throws \CRM_Core_Exception
31 * @throws \API_Exception
33 public static function create($params) {
34 CRM_Core_BAO_Block
::handlePrimary($params, __CLASS__
);
35 return self
::writeRecord($params);
39 * Create or update IM record.
43 * @param array $params
45 * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
46 * @throws \CRM_Core_Exception
47 * @throws \API_Exception
49 public static function add($params) {
50 CRM_Core_Error
::deprecatedFunctionWarning('use the v4 api');
51 return self
::create($params);
55 * Given the list of params in the params array, fetch the object
56 * and store the values in the values array
58 * @param array $entityBlock input parameters to find object
62 public static function &getValues($entityBlock) {
63 return CRM_Core_BAO_Block
::getValues('im', $entityBlock);
67 * Get all the ims for a specified contact_id, with the primary im being first
72 * @param bool $updateBlankLocInfo
75 * the array of im details
77 public static function allIMs($id, $updateBlankLocInfo = FALSE) {
83 SELECT civicrm_im.name as im, civicrm_location_type.name as locationType, civicrm_im.is_primary as is_primary,
84 civicrm_im.id as im_id, civicrm_im.location_type_id as locationTypeId,
85 civicrm_im.provider_id as providerId
87 LEFT JOIN civicrm_im ON ( civicrm_im.contact_id = civicrm_contact.id )
88 LEFT JOIN civicrm_location_type ON ( civicrm_im.location_type_id = civicrm_location_type.id )
90 civicrm_contact.id = %1
92 civicrm_im.is_primary DESC, im_id ASC ";
93 $params = [1 => [$id, 'Integer']];
96 $dao = CRM_Core_DAO
::executeQuery($query, $params);
98 while ($dao->fetch()) {
100 'locationType' => $dao->locationType
,
101 'is_primary' => $dao->is_primary
,
104 'locationTypeId' => $dao->locationTypeId
,
105 'providerId' => $dao->providerId
,
108 if ($updateBlankLocInfo) {
109 $ims[$count++
] = $values;
112 $ims[$dao->im_id
] = $values;
119 * Get all the ims for a specified location_block id, with the primary im being first
121 * @param array $entityElements
122 * The array containing entity_id and.
126 * the array of im details
128 public static function allEntityIMs(&$entityElements) {
129 if (empty($entityElements)) {
132 $entityId = $entityElements['entity_id'];
133 $entityTable = $entityElements['entity_table'];
134 $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
135 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev
137 AND loc.id = ev.loc_block_id
138 AND cim.id IN (loc.im_id, loc.im_2_id)
139 AND ltype.id = cim.location_type_id
140 ORDER BY cim.is_primary DESC, im_id ASC ";
142 $params = [1 => [$entityId, 'Integer']];
145 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
146 while ($dao->fetch()) {
147 $ims[$dao->im_id
] = [
148 'locationType' => $dao->locationType
,
149 'is_primary' => $dao->is_primary
,
152 'locationTypeId' => $dao->locationTypeId
,
159 * Call common delete function.
165 public static function del($id) {
166 return CRM_Contact_BAO_Contact
::deleteObjectWithPrimary('IM', $id);