function preProcess() { $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); $this->assign('contactId', $this->_contactId); $contact = new CRM_Contact_BAO_Contact(); $contact->get('id', $this->_contactId); $this->_apiKey = $contact->api_key; $this->assign('apiKey', $this->_apiKey); // check logged in url permission CRM_Contact_Page_View::checkUserPermission($this); // set page title CRM_Contact_Page_View::setTitle($this->_contactId); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); $this->assign('action', $this->_action); $isAdmin = CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_Permission::check('edit all contacts'); $session = CRM_Core_Session::singleton(); $isMyself = $this->_contactId && $this->_contactId == $session->get('userID'); $this->assign('isAdmin', $isAdmin); $this->assign('isMyself', $isMyself); $urlParam = 'reset=1&action=add&cid=' . $this->_contactId; if ($this->_apiKey) { $urlParam = 'reset=1&action=edit&cid=' . $this->_contactId; } $this->assign('addApiKeyUrl', CRM_Utils_System::url('civicrm/contact/apikey', $urlParam)); }
function addContactTokens($contact_id, $variable_name) { if (empty($contact_id)) { return; } // use the API to load a extensive contact information bulk $contact = civicrm_api('Contact', 'getsingle', array('id' => $contact_id, 'version' => 3)); // ... add some missing fields $bao = new CRM_Contact_BAO_Contact(); $bao->get('id', $contact_id); $contact['postal_greeting_display'] = $bao->postal_greeting_display; $contact['email_greeting_display'] = $bao->email_greeting_display; $contact['addressee_display'] = $bao->addressee_display; if (empty($contact['is_error'])) { $this->assign($variable_name, $contact); } }
/** * read out the contributor */ public function getContributor($contact_id) { if ($this->cached_contributors[$contact_id]) { return $this->cached_contributors[$contact_id]; } // not cached? build it. $contributor = array(); // load the contact $contact = new CRM_Contact_BAO_Contact(); $contact->get('id', $contact_id); // copy the base values foreach (CRM_Donrec_Logic_ReceiptTokens::$STORED_TOKENS['contributor'] as $key => $value) { if (isset($contact->{$key})) { $contributor[$key] = $contact->{$key}; } } // add the addresses $types = $this->getProfile()->getLocationTypes()['legal']; $contributor_address = $this->lookupAddressTokens($contact_id, $types['address'], $types['fallback']); if ($contributor_address != NULL) { $contributor = array_merge($contributor, $contributor_address); } // cache the result $this->cached_contributors[$contact_id] = $contributor; return $contributor; }
/** * Get address tokens for a given contact with fallback type */ public static function lookupAddressTokens($contact_id, $location_type, $fallback_location_type) { if (empty($contact_id)) { return array(); } // find the address $address = self::_lookupAddress($contact_id, $location_type); if ($address == NULL) { $address = self::_lookupAddress($contact_id, $fallback_location_type); } if ($address == NULL) { // no address found return array(); } //add contact information $contact_bao = new CRM_Contact_BAO_Contact(); $contact_bao->get('id', $contact_id); $address['display_name'] = $contact_bao->display_name; $address['addressee'] = $contact_bao->addressee_display; return $address; }