3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class contain function for IM handling
39 class CRM_Core_BAO_IM
extends CRM_Core_DAO_IM
{
42 * takes an associative array and adds im
44 * @param array $params (reference ) an assoc array of name/value pairs
46 * @return object CRM_Core_BAO_IM object on success, null otherwise
50 static function add(&$params) {
51 $hook = empty($params['id']) ?
'create' : 'edit';
52 CRM_Utils_Hook
::pre($hook, 'IM', CRM_Utils_Array
::value('id', $params), $params);
54 $im = new CRM_Core_DAO_IM();
55 $im->copyValues($params);
58 CRM_Utils_Hook
::post($hook, 'IM', $im->id
, $im);
63 * Given the list of params in the params array, fetch the object
64 * and store the values in the values array
66 * @param array entityBlock input parameters to find object
72 static function &getValues($entityBlock) {
73 return CRM_Core_BAO_Block
::getValues('im', $entityBlock);
77 * Get all the ims for a specified contact_id, with the primary im being first
79 * @param int $id the contact id
81 * @return array the array of im details
85 static function allIMs($id, $updateBlankLocInfo = FALSE) {
91 SELECT civicrm_im.name as im, civicrm_location_type.name as locationType, civicrm_im.is_primary as is_primary,
92 civicrm_im.id as im_id, civicrm_im.location_type_id as locationTypeId,
93 civicrm_im.provider_id as providerId
95 LEFT JOIN civicrm_im ON ( civicrm_im.contact_id = civicrm_contact.id )
96 LEFT JOIN civicrm_location_type ON ( civicrm_im.location_type_id = civicrm_location_type.id )
98 civicrm_contact.id = %1
100 civicrm_im.is_primary DESC, im_id ASC ";
101 $params = array(1 => array($id, 'Integer'));
103 $ims = $values = array();
104 $dao = CRM_Core_DAO
::executeQuery($query, $params);
106 while ($dao->fetch()) {
108 'locationType' => $dao->locationType
,
109 'is_primary' => $dao->is_primary
,
112 'locationTypeId' => $dao->locationTypeId
,
113 'providerId' => $dao->providerId
,
116 if ($updateBlankLocInfo) {
117 $ims[$count++
] = $values;
120 $ims[$dao->im_id
] = $values;
127 * Get all the ims for a specified location_block id, with the primary im being first
129 * @param array $entityElements the array containing entity_id and
132 * @return array the array of im details
136 static function allEntityIMs(&$entityElements) {
137 if (empty($entityElements)) {
142 $entityId = $entityElements['entity_id'];
143 $entityTable = $entityElements['entity_table'];
146 $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
147 FROM civicrm_loc_block loc, civicrm_im cim, civicrm_location_type ltype, {$entityTable} ev
149 AND loc.id = ev.loc_block_id
150 AND cim.id IN (loc.im_id, loc.im_2_id)
151 AND ltype.id = cim.location_type_id
152 ORDER BY cim.is_primary DESC, im_id ASC ";
154 $params = array(1 => array($entityId, 'Integer'));
157 $dao = CRM_Core_DAO
::executeQuery($sql, $params);
158 while ($dao->fetch()) {
159 $ims[$dao->im_id
] = array(
160 'locationType' => $dao->locationType
,
161 'is_primary' => $dao->is_primary
,
164 'locationTypeId' => $dao->locationTypeId
,
171 * Call common delete function
173 static function del($id) {
174 return CRM_Contact_BAO_Contact
::deleteObjectWithPrimary('IM', $id);