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
{
24 * Create or update IM record.
26 * @param array $params
28 * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
29 * @throws \CRM_Core_Exception
30 * @throws \API_Exception
32 public static function create($params) {
33 CRM_Core_BAO_Block
::handlePrimary($params, __CLASS__
);
34 return self
::writeRecord($params);
38 * Create or update IM record.
42 * @param array $params
44 * @return \CRM_Core_DAO|\CRM_Core_DAO_IM
45 * @throws \CRM_Core_Exception
46 * @throws \API_Exception
48 public static function add($params) {
49 CRM_Core_Error
::deprecatedFunctionWarning('use the v4 api');
50 return self
::create($params);
54 * Given the list of params in the params array, fetch the object
55 * and store the values in the values array
57 * @param array $entityBlock input parameters to find object
61 public static function &getValues($entityBlock) {
62 return CRM_Core_BAO_Block
::getValues('im', $entityBlock);
66 * Get all the ims for a specified contact_id, with the primary im being first
71 * @param bool $updateBlankLocInfo
74 * the array of im details
76 public static function allIMs($id, $updateBlankLocInfo = FALSE) {
82 SELECT civicrm_im.name as im, civicrm_location_type.name as locationType, civicrm_im.is_primary as is_primary,
83 civicrm_im.id as im_id, civicrm_im.location_type_id as locationTypeId,
84 civicrm_im.provider_id as providerId
86 LEFT JOIN civicrm_im ON ( civicrm_im.contact_id = civicrm_contact.id )
87 LEFT JOIN civicrm_location_type ON ( civicrm_im.location_type_id = civicrm_location_type.id )
89 civicrm_contact.id = %1
91 civicrm_im.is_primary DESC, im_id ASC ";
92 $params = [1 => [$id, 'Integer']];
95 $dao = CRM_Core_DAO
::executeQuery($query, $params);
97 while ($dao->fetch()) {
99 'locationType' => $dao->locationType
,
100 'is_primary' => $dao->is_primary
,
103 'locationTypeId' => $dao->locationTypeId
,
104 'providerId' => $dao->providerId
,
107 if ($updateBlankLocInfo) {
108 $ims[$count++
] = $values;
111 $ims[$dao->im_id
] = $values;
118 * Get all the ims for a specified location_block id, with the primary im being first
120 * @param array $entityElements
121 * The array containing entity_id and.
125 * the array of im details
127 public static function allEntityIMs(&$entityElements) {
128 if (empty($entityElements)) {
131 $entityId = $entityElements['entity_id'];
132 $entityTable = $entityElements['entity_table'];
133 $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
134 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev
136 AND loc.id = ev.loc_block_id
137 AND cim.id IN (loc.im_id, loc.im_2_id)
138 AND ltype.id = cim.location_type_id
139 ORDER BY cim.is_primary DESC, im_id ASC ";
141 $params = [1 => [$entityId, 'Integer']];
144 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
145 while ($dao->fetch()) {
146 $ims[$dao->im_id
] = [
147 'locationType' => $dao->locationType
,
148 'is_primary' => $dao->is_primary
,
151 'locationTypeId' => $dao->locationTypeId
,
158 * Call common delete function.
164 public static function del($id) {
165 return CRM_Contact_BAO_Contact
::deleteObjectWithPrimary('IM', $id);