[$id, 'Integer']]; $ims = $values = []; $dao = CRM_Core_DAO::executeQuery($query, $params); $count = 1; while ($dao->fetch()) { $values = [ 'locationType' => $dao->locationType, 'is_primary' => $dao->is_primary, 'id' => $dao->im_id, 'name' => $dao->im, 'locationTypeId' => $dao->locationTypeId, 'providerId' => $dao->providerId, ]; if ($updateBlankLocInfo) { $ims[$count++] = $values; } else { $ims[$dao->im_id] = $values; } } return $ims; } /** * Get all the ims for a specified location_block id, with the primary im being first * * @param array $entityElements * The array containing entity_id and. * entity_table name * * @return array * the array of im details */ public static function allEntityIMs(&$entityElements) { if (empty($entityElements)) { return NULL; } $entityId = $entityElements['entity_id']; $entityTable = $entityElements['entity_table']; $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 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev WHERE ev.id = %1 AND loc.id = ev.loc_block_id AND cim.id IN (loc.im_id, loc.im_2_id) AND ltype.id = cim.location_type_id ORDER BY cim.is_primary DESC, im_id ASC "; $params = [1 => [$entityId, 'Integer']]; $ims = []; $dao = CRM_Core_DAO::executeQuery($sql, $params); while ($dao->fetch()) { $ims[$dao->im_id] = [ 'locationType' => $dao->locationType, 'is_primary' => $dao->is_primary, 'id' => $dao->im_id, 'name' => $dao->im, 'locationTypeId' => $dao->locationTypeId, ]; } return $ims; } /** * Call common delete function. * * @param int $id * * @return bool */ public static function del($id) { return CRM_Contact_BAO_Contact::deleteObjectWithPrimary('IM', $id); } }