From: monishdeb Date: Fri, 17 Jul 2015 05:50:44 +0000 (+0530) Subject: removing dependency of onbehalf X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ac38dc5d3477334a941f3881ac5e785b6bd25ac2;p=civicrm-core.git removing dependency of onbehalf --- diff --git a/CRM/Contact/Form/ProfileContact.php b/CRM/Contact/Form/ProfileContact.php index 69d9e4c553..61f3ed48b0 100644 --- a/CRM/Contact/Form/ProfileContact.php +++ b/CRM/Contact/Form/ProfileContact.php @@ -40,8 +40,7 @@ class CRM_Contact_Form_ProfileContact { * @param CRM_Core_Form $form */ public static function preProcess(&$form) { - $session = CRM_Core_Session::singleton(); - $contactID = $session->get('userID'); + $contactID = $form->_contactID; foreach (array('soft_credit', 'on_behalf') as $module) { $ufJoinParams = array( @@ -79,7 +78,7 @@ class CRM_Contact_Form_ProfileContact { } else { $form->_onbehalf = FALSE; - $params = CRM_Contribute_BAO_ContributionPage::formatMultilingualOnBehalfParams($ufJoin->module_data); + $params = CRM_Contribute_BAO_ContributionPage::formatMultilingualOnBehalfParams($ufJoin->module_data, TRUE); if (CRM_Utils_Array::value('is_for_organization', $params)) { if ($params['is_for_organization'] == 2) { $form->_onBehalfRequired = TRUE; @@ -107,6 +106,43 @@ class CRM_Contact_Form_ProfileContact { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.')); } + //CRM-5001,CRM-15787 + $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->_profileId); + 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 ($postID = CRM_Utils_Array::value('custom_post_id', $form->_values)) { + $postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID); + foreach (array( + 'Individual', + 'Organization', + 'Household', + ) as $contactType) { + if (in_array($contactType, $postProfile) && + (in_array('Membership', $postProfile) || + in_array('Contribution', $postProfile) + ) + ) { + CRM_Core_Error::fatal($msg); + } + } + } + } + $form->assign('profileId', $form->_profileId); $form->assign('mode', $form->_mode); @@ -164,7 +200,7 @@ class CRM_Contact_Form_ProfileContact { } } } - $this->assign('onBehalfRequired', $form->_onBehalfRequired); + $form->assign('onBehalfRequired', $form->_onBehalfRequired); } } } @@ -176,6 +212,27 @@ class CRM_Contact_Form_ProfileContact { * */ public static function buildQuickForm(&$form) { + if (!empty($form->_honor_block_is_active)) { + self::buildHonorBlock($form); + } + + if (!empty($form->_onbehalf)) { + self::buildOnBehalfBlock($form); + } + } + + /** + * @param $form + */ + public static function postProcess($form) { + } + + public static function buildHonorBlock(&$form) { + $form->assign('honor_block_is_active', TRUE); + + //build soft-credit section + CRM_Contribute_Form_SoftCredit::buildQuickForm($form); + $ufGroup = new CRM_Core_DAO_UFGroup(); $ufGroup->id = $form->_honoreeProfileId; if (!$ufGroup->find(TRUE)) { @@ -202,10 +259,70 @@ class CRM_Contact_Form_ProfileContact { } } - /** - * @param $form - */ - public static function postProcess($form) { - } + public static function buildOnBehalfBlock(&$form) { + $form->assign('fieldSetTitle', ts('Organization Details')); + $form->assign('buildOnBehalfForm', TRUE); + + $contactID = $form->_contactID; + + if ($form->_membershipContactID) { + $entityBlock = array('contact_id' => $form->_membershipContactID); + //CRM_Core_BAO_Location::getValues($entityBlock, $form->_defaults); + } + + if (!$form->_onBehalfRequired) { + $form->addElement('checkbox', 'is_for_organization', + $form->_values['for_organization'], + NULL, array('onclick' => "showOnBehalf( );") + ); + } + $form->assign('is_for_organization', TRUE); + $form->assign('urlPath', 'civicrm/contribute/transact'); + + if ($contactID && count($form->_employers) >= 1) { + $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one')); + + $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers)); + + $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->add('checkbox', 'mode', ''); + } + + $prefix = 'onbehalf'; + $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, + NULL, FALSE, NULL, FALSE, NULL, + CRM_Core_Permission::CREATE, NULL + ); + $fieldTypes = array('Contact', 'Organization'); + $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); + $fieldTypes = array_merge($fieldTypes, $contactSubType); + + if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) { + $fieldTypes = array_merge($fieldTypes, array('Membership')); + } + else { + $fieldTypes = array_merge($fieldTypes, array('Contribution')); + } + + foreach ($profileFields as $name => $field) { + if (in_array($field['field_type'], $fieldTypes)) { + list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); + if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) { + $field['is_required'] = 1; + } + + CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, $prefix, NULL, $prefix); + } + } + + $form->assign('onBehalfOfFields', $profileFields); + $form->addElement('hidden', 'hidden_onbehalf_profile', 1); + } } diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 680938a938..1f32a03635 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -101,54 +101,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu if (!empty($this->_values['footer_text'])) { $this->assign('footer_text', $this->_values['footer_text']); } - - //CRM-5001 - //CRM-15787 - $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); - if (!empty($this->_values['is_for_organization']) && empty($member['is_active'])) { - $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.'); - $ufJoinParams = array( - 'module' => 'onBehalf', - 'entity_table' => 'civicrm_contribution_page', - 'entity_id' => $this->_id, - ); - $onBehalfProfileIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); - // getUFGroupIDs returns an array with the first item being the ID we need - $onBehalfProfileID = $onBehalfProfileIDs[0]; - if ($onBehalfProfileID) { - $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileID); - 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 ($postID = CRM_Utils_Array::value('custom_post_id', $this->_values)) { - $postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID); - foreach (array( - 'Individual', - 'Organization', - 'Household', - ) as $contactType) { - if (in_array($contactType, $postProfile) && - (in_array('Membership', $postProfile) || - in_array('Contribution', $postProfile) - ) - ) { - CRM_Core_Error::fatal($msg); - } - } - } - } } /** @@ -362,12 +314,11 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID)); } - if ($this->_onbehalf) { - CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this); - // Return if we are in an ajax callback - if ($this->_snippet) { - return; - } + CRM_Contact_Form_ProfileContact::buildQuickForm($this); + + // Return if we are in an ajax callback + if ($this->_onbehalf && $this->_snippet) { + return; } $this->applyFilter('__ALL__', 'trim'); @@ -462,25 +413,11 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } - if ($this->_values['is_for_organization']) { - $this->buildOnBehalfOrganization(); - } - //we allow premium for pledge during pledge creation only. if (empty($this->_values['pledge_id'])) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } - //add honor block - if ($this->_honor_block_is_active) { - $this->assign('honor_block_is_active', TRUE); - - //build soft-credit section - CRM_Contribute_Form_SoftCredit::buildQuickForm($this); - //build honoree profile section - CRM_Contact_Form_ProfileContact::buildQuickForm($this); - } - //don't build pledge block when mid is passed if (!$this->_mid) { $config = CRM_Core_Config::singleton(); @@ -584,26 +521,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); } - /** - * Build elements to enable pay on behalf of an organization. - */ - public function buildOnBehalfOrganization() { - if ($this->_membershipContactID) { - $entityBlock = array('contact_id' => $this->_membershipContactID); - CRM_Core_BAO_Location::getValues($entityBlock, $this->_defaults); - } - - if (!$this->_onBehalfRequired) { - $this->addElement('checkbox', 'is_for_organization', - $this->_values['for_organization'], - NULL, array('onclick' => "showOnBehalf( );") - ); - } - - $this->assign('is_for_organization', TRUE); - $this->assign('urlPath', 'civicrm/contribute/transact'); - } - /** * Build elements to collect information for recurring contributions. * diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 63b18a9698..8fb97b9582 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -25,7 +25,7 @@ *} {* Callback snippet: On-behalf profile *} {if $snippet and !empty($isOnBehalfCallback)} - {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end"} + {* include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl" context="front-end" *} {else} {literal} @@ -172,7 +172,7 @@ {if $is_for_organization}
- {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"} + {include file="CRM/UF/Form/Block.tpl" fields=$onBehalfOfFields mode=8 prefix='onbehalf'}
{/if} diff --git a/templates/CRM/UF/Form/Block.tpl b/templates/CRM/UF/Form/Block.tpl index 356cf9554a..fc2f1ace08 100644 --- a/templates/CRM/UF/Form/Block.tpl +++ b/templates/CRM/UF/Form/Block.tpl @@ -47,7 +47,7 @@
{$field.groupTitle} {/if} - {if ($form.formName eq 'Confirm' OR $form.formName eq 'ThankYou') AND $prefix neq 'honor'} + {if ($form.formName eq 'Confirm' OR $form.formName eq 'ThankYou') AND $prefix neq 'honor' OR $prefix neq 'onbehalf'}
{$field.groupTitle}
{/if} {assign var=fieldset value=`$field.groupTitle`}