本文整理汇总了PHP中CRM_Contact_BAO_Relationship::getPermissionedContacts方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Contact_BAO_Relationship::getPermissionedContacts方法的具体用法?PHP CRM_Contact_BAO_Relationship::getPermissionedContacts怎么用?PHP CRM_Contact_BAO_Relationship::getPermissionedContacts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Contact_BAO_Relationship
的用法示例。
在下文中一共展示了CRM_Contact_BAO_Relationship::getPermissionedContacts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildComponentForm
/**
* Add onbehalf/honoree profile fields and native module fields.
*
* @param int $id
* @param CRM_Core_Form $form
*/
public function buildComponentForm($id, $form)
{
if (empty($id)) {
return;
}
$contactID = $this->getContactID();
foreach (array('soft_credit', 'on_behalf') as $module) {
if ($module == 'soft_credit') {
if (empty($form->_values['honoree_profile_id'])) {
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.'));
}
$profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']);
$requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email'));
$validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]);
if (!$validProfile) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
}
foreach (array('honor_block_title', 'honor_block_text') as $name) {
$form->assign($name, $form->_values[$name]);
}
$softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
// radio button for Honor Type
foreach ($form->_values['soft_credit_types'] as $value) {
$honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
}
$form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
$honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE);
$form->assign('honoreeProfileFields', $honoreeProfileFields);
// add the form elements
foreach ($honoreeProfileFields as $name => $field) {
// If soft credit type is not chosen then make omit requiredness from honoree profile fields
if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) {
$field['is_required'] = FALSE;
}
CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor');
}
} else {
if (empty($form->_values['onbehalf_profile_id'])) {
continue;
}
if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) {
CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.'));
}
$member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id);
if (empty($member['is_active'])) {
$msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
$onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']);
foreach (array('Individual', 'Organization', 'Household') as $contactType) {
if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) {
CRM_Core_Error::fatal($msg);
}
}
}
if ($contactID) {
// retrieve all permissioned organizations of contact $contactID
$organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization');
if (count($organizations)) {
// Related org url - pass checksum if needed
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => '');
if (!empty($_GET['cs'])) {
$args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => '');
}
$locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
$form->assign('locDataURL', $locDataURL);
}
if (count($organizations) > 0) {
$form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations));
$orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
$form->addRadio('org_option', ts('options'), $orgOptions);
$form->setDefaults(array('org_option' => 0));
}
}
$form->assign('fieldSetTitle', ts('Organization Details'));
if (CRM_Utils_Array::value('is_for_organization', $form->_values)) {
if ($form->_values['is_for_organization'] == 2) {
$form->assign('onBehalfRequired', TRUE);
} else {
$form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL);
}
}
$profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
$form->assign('onBehalfOfFields', $profileFields);
if (!empty($form->_submitValues['onbehalf'])) {
if (!empty($form->_submitValues['onbehalfof_id'])) {
$form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']);
}
$form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf']));
}
$fieldTypes = array('Contact', 'Organization');
$contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
$fieldTypes = array_merge($fieldTypes, $contactSubType);
//.........这里部分代码省略.........
示例2: preProcess
/**
* Function to set variables up before form is built
*
* @return void
* @access public
*/
public function preProcess()
{
$config = CRM_Core_Config::singleton();
$session = CRM_Core_Session::singleton();
// current contribution page id
$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
if (!$this->_id) {
// seems like the session is corrupted and/or we lost the id trail
// lets just bump this to a regular session error and redirect user to main page
$this->controller->invalidKeyRedirect();
}
// this was used prior to the cleverer this_>getContactID - unsure now
$this->_userID = $session->get('userID');
$this->_contactID = $this->_membershipContactID = $this->getContactID();
$this->_mid = NULL;
if ($this->_contactID) {
$this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
if ($this->_mid) {
$membership = new CRM_Member_DAO_Membership();
$membership->id = $this->_mid;
if ($membership->find(TRUE)) {
$this->_defaultMemTypeId = $membership->membership_type_id;
if ($membership->contact_id != $this->_contactID) {
$validMembership = FALSE;
$employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID);
if (!empty($employers) && array_key_exists($membership->contact_id, $employers)) {
$this->_membershipContactID = $membership->contact_id;
$this->assign('membershipContactID', $this->_membershipContactID);
$this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']);
$validMembership = TRUE;
} else {
$membershipType = new CRM_Member_BAO_MembershipType();
$membershipType->id = $membership->membership_type_id;
if ($membershipType->find(TRUE)) {
// CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
// Convert to commma separated list.
$inheritedRelTypes = implode(CRM_Utils_Array::explodePadded($membershipType->relationship_type_id), ',');
$permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id);
if (array_key_exists($membership->contact_id, $permContacts)) {
$this->_membershipContactID = $membership->contact_id;
$validMembership = TRUE;
}
}
}
if (!$validMembership) {
CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
}
}
} else {
CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
}
unset($membership);
}
}
// we do not want to display recently viewed items, so turn off
$this->assign('displayRecent', FALSE);
// Contribution page values are cleared from session, so can't use normal Printer Friendly view.
// Use Browser Print instead.
$this->assign('browserPrint', TRUE);
// action
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
$this->assign('action', $this->_action);
// current mode
$this->_mode = $this->_action == 1024 ? 'test' : 'live';
$this->_values = $this->get('values');
$this->_fields = $this->get('fields');
$this->_bltID = $this->get('bltID');
$this->_paymentProcessor = $this->get('paymentProcessor');
$this->_priceSetId = $this->get('priceSetId');
$this->_priceSet = $this->get('priceSet');
if (!$this->_values) {
// get all the values from the dao object
$this->_values = array();
$this->_fields = array();
CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
// check if form is active
if (!CRM_Utils_Array::value('is_active', $this->_values)) {
// form is inactive, die a fatal death
CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
}
// also check for billing informatin
// get the billing location type
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
// CRM-8108 remove ts around Billing location type
//$this->_bltID = array_search( ts('Billing'), $locationTypes );
$this->_bltID = array_search('Billing', $locationTypes);
if (!$this->_bltID) {
CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
}
$this->set('bltID', $this->_bltID);
// check for is_monetary status
$isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
$isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values);
//FIXME: to support multiple payment processors
//.........这里部分代码省略.........
示例3: getPermissionedLocation
/**
* FIXME: we should make this method like getLocBlock() OR use the same method and
* remove this one.
*
* obtain the location of given contact-id.
* This method is used by on-behalf-of form to dynamically generate poulate the
* location field values for selected permissioned contact.
*/
public static function getPermissionedLocation()
{
$cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
$ufId = CRM_Utils_Request::retrieve('ufId', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
// Verify user id
$user = CRM_Utils_Request::retrieve('uid', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, CRM_Core_Session::singleton()->get('userID'));
if (empty($user) || CRM_Utils_Request::retrieve('cs', 'String', $form, FALSE) && !CRM_Contact_BAO_Contact_Permission::validateChecksumContact($user, CRM_Core_DAO::$_nullObject, FALSE)) {
CRM_Utils_System::civiExit();
}
// Verify user permission on related contact
$organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($user, NULL, NULL, 'Organization');
if (!isset($organizations[$cid])) {
CRM_Utils_System::civiExit();
}
$values = array();
$entityBlock = array('contact_id' => $cid);
$location = CRM_Core_BAO_Location::getValues($entityBlock);
$config = CRM_Core_Config::singleton();
$addressSequence = array_flip($config->addressSequence());
$profileFields = CRM_Core_BAO_UFGroup::getFields($ufId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
$website = CRM_Core_BAO_Website::getValues($entityBlock, $values);
foreach ($location as $fld => $values) {
if (is_array($values) && !empty($values)) {
$locType = $values[1]['location_type_id'];
if ($fld == 'email') {
$elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
unset($profileFields["{$fld}-{$locType}"]);
} elseif ($fld == 'phone') {
$phoneTypeId = $values[1]['phone_type_id'];
$elements["onbehalf_{$fld}-{$locType}-{$phoneTypeId}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
unset($profileFields["{$fld}-{$locType}-{$phoneTypeId}"]);
} elseif ($fld == 'im') {
$providerId = $values[1]['provider_id'];
$elements["onbehalf_{$fld}-{$locType}"] = array('type' => 'Text', 'value' => $location[$fld][1][$fld]);
$elements["onbehalf_{$fld}-{$locType}provider_id"] = array('type' => 'Select', 'value' => $location[$fld][1]['provider_id']);
unset($profileFields["{$fld}-{$locType}-{$providerId}"]);
}
}
}
if (!empty($website)) {
foreach ($website as $key => $val) {
$websiteTypeId = $values[1]['website_type_id'];
$elements["onbehalf_url-1"] = array('type' => 'Text', 'value' => $website[1]['url']);
$elements["onbehalf_url-1-website_type_id"] = array('type' => 'Select', 'value' => $website[1]['website_type_id']);
unset($profileFields["url-1"]);
}
}
$locTypeId = isset($location['address'][1]) ? $location['address'][1]['location_type_id'] : NULL;
$addressFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'county', 'state_province', 'country');
foreach ($addressFields as $field) {
if (array_key_exists($field, $addressSequence)) {
$addField = $field;
$type = 'Text';
if (in_array($field, array('state_province', 'country', 'county'))) {
$addField = "{$field}_id";
$type = 'Select';
}
$elements["onbehalf_{$field}-{$locTypeId}"] = array('type' => $type, 'value' => isset($location['address'][1]) ? CRM_Utils_Array::value($addField, $location['address'][1]) : NULL);
unset($profileFields["{$field}-{$locTypeId}"]);
}
}
//set custom field defaults
$defaults = array();
CRM_Core_BAO_UFGroup::setProfileDefaults($cid, $profileFields, $defaults, TRUE, NULL, NULL, TRUE);
if (!empty($defaults)) {
foreach ($profileFields as $key => $val) {
if (array_key_exists($key, $defaults)) {
$htmlType = CRM_Utils_Array::value('html_type', $val);
if ($htmlType == 'Radio') {
$elements["onbehalf_{$key}"]['type'] = $htmlType;
$elements["onbehalf_{$key}"]['value'] = $defaults[$key];
} elseif ($htmlType == 'CheckBox') {
$elements["onbehalf_{$key}"]['type'] = $htmlType;
foreach ($defaults[$key] as $k => $v) {
$elements["onbehalf_{$key}"]['value'][$k] = $v;
}
} elseif (strstr($htmlType, 'Multi-Select') && $htmlType != 'AdvMulti-Select') {
$elements["onbehalf_{$key}"]['type'] = 'Multi-Select';
$elements["onbehalf_{$key}"]['value'] = array_values($defaults[$key]);
} elseif ($htmlType == 'Autocomplete-Select') {
$elements["onbehalf_{$key}"]['type'] = $htmlType;
$elements["onbehalf_{$key}"]['value'] = $defaults[$key];
} elseif ($htmlType == 'Select Date') {
$elements["onbehalf_{$key}"]['type'] = $htmlType;
$elements["onbehalf_{$key}"]['value'] = $defaults[$key];
$elements["onbehalf_{$key}_display"]['value'] = $defaults[$key];
} else {
$elements["onbehalf_{$key}"]['type'] = $htmlType;
$elements["onbehalf_{$key}"]['value'] = $defaults[$key];
}
} else {
$elements["onbehalf_{$key}"]['value'] = '';
//.........这里部分代码省略.........