/** * AllIMs() method - get all IMs for our contact, with primary IM first */ public function testAllIMs() { $op = new PHPUnit_Extensions_Database_Operation_Insert(); $op->execute($this->_dbconn, $this->createFlatXMLDataSet(dirname(__FILE__) . '/dataset/im_test.xml')); $contactId = 69; $IMs = CRM_Core_BAO_IM::allIMs($contactId); $this->assertEquals(count($IMs), 3, 'Checking number of returned IMs.'); $firstIMValue = array_slice($IMs, 0, 1); $this->assertEquals('alan1.smith1', $firstIMValue[0]['name'], 'Confirm primary IM value.'); $this->assertEquals(1, $firstIMValue[0]['is_primary'], 'Confirm first IM is primary.'); $this->contactDelete($contactId); }
/** * Run the page. * * This method is called after the page is created. * * @return void * @access public * */ function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')); $IMProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $entityBlock = array('contact_id' => $contactId); $ims = CRM_Core_BAO_IM::getValues($entityBlock); if (!empty($ims)) { foreach ($ims as $key => &$value) { $value['location_type'] = $locationTypes[$value['location_type_id']]; $value['provider'] = $IMProviders[$value['provider_id']]; } } $this->assign('contactId', $contactId); $this->assign('im', $ims); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * takes an associative array and creates a contact object * * the function extract all the params it needs to initialize the create a * contact object. the params array could contain additional unused name/value * pairs * * @param array $params (reference ) an assoc array of name/value pairs * @param array $ids the array that holds all the db ids * @param int $locationId * @param int $imId * @param bool $isPrimary Has any previous entry been marked as isPrimary? * * @return object CRM_Core_BAO_IM object on success, null otherwise * @access public * @static */ function add(&$params, &$ids, $locationId, $imId, &$isPrimary) { if (!CRM_Core_BAO_IM::dataExists($params, $locationId, $imId, $ids)) { return null; } $im =& new CRM_Core_DAO_IM(); $im->name = $params['location'][$locationId]['im'][$imId]['name']; $im->id = CRM_Utils_Array::value($imId, $ids['location'][$locationId]['im']); if (empty($im->name)) { $im->delete(); return null; } $im->location_id = $params['location'][$locationId]['id']; $im->provider_id = $params['location'][$locationId]['im'][$imId]['provider_id']; if (!$im->provider_id) { $im->provider_id = 'null'; } // set this object to be the value of isPrimary and make sure no one else can be isPrimary $im->is_primary = $isPrimary; $isPrimary = false; return $im->save(); }
/** * simple helper function to dispatch getCall to lower comm blocks */ function getBlocks(&$params, &$values, &$ids, $blockCount = 0, &$parent) { $parent->address =& CRM_Core_BAO_Address::getValues($params, $values, $ids, $blockCount); $parent->phone =& CRM_Core_BAO_Phone::getValues($params, $values, $ids, $blockCount); $parent->email =& CRM_Core_BAO_Email::getValues($params, $values, $ids, $blockCount); $parent->im =& CRM_Core_BAO_IM::getValues($params, $values, $ids, $blockCount); }