From cb804cd91e0e1d15cdd684b0c0e94aab5e94d003 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Sat, 5 Sep 2015 02:52:50 +0530 Subject: [PATCH] Refactor phase2 for honoree block --- CRM/Contact/Form/ProfileContact.php | 120 ------------------ CRM/Contribute/BAO/ContributionPage.php | 2 +- CRM/Contribute/Form/Contribution/Confirm.php | 4 +- .../Form/Contribution/OnBehalfOf.php | 110 ++++++++++++++++ CRM/Contribute/Form/ContributionBase.php | 42 +++++- CRM/Core/xml/Menu/Contact.xml | 7 - CRM/Core/xml/Menu/Misc.xml | 7 + CRM/Upgrade/Incremental/php/FourSeven.php | 1 + .../CRM/Contribute/Form/Contribution/Main.tpl | 27 +++- .../Form/Contribution/OnBehalfOf.tpl} | 2 +- templates/CRM/Contribute/Form/SoftCredit.tpl | 18 +-- 11 files changed, 181 insertions(+), 159 deletions(-) delete mode 100644 CRM/Contact/Form/ProfileContact.php create mode 100644 CRM/Contribute/Form/Contribution/OnBehalfOf.php rename templates/CRM/{Contact/Form/ProfileContact.tpl => Contribute/Form/Contribution/OnBehalfOf.tpl} (98%) diff --git a/CRM/Contact/Form/ProfileContact.php b/CRM/Contact/Form/ProfileContact.php deleted file mode 100644 index 6bcebffff8..0000000000 --- a/CRM/Contact/Form/ProfileContact.php +++ /dev/null @@ -1,120 +0,0 @@ -_profileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, NULL, FALSE, NULL, 'GET'); - $this->_prefix = CRM_Utils_Request::retrieve('prefix', 'String', $this, NULL, FALSE, NULL, 'GET'); - - $this->assign('suppressForm', TRUE); - $this->assign('snippet', TRUE); - $this->controller->_generateQFKey = FALSE; - } - - /** - * Build form for honoree contact / on behalf of organization. - * - * @param CRM_Core_Form $form - * - */ - public function buildQuickForm() { - $contactID = $this->getContactID(); - - if ($this->_prefix == 'onbehalf') { - $this->assign('fieldSetTitle', ts('Organization Details')); - $this->assign('profileId', $this->_profileId); - - if ($contactID) { - $employer = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); - - if (count($employer)) { - // Related org url - pass checksum if needed - $args = array('cid' => ''); - if (!empty($_GET['cs'])) { - $args = array( - 'uid' => $this->_contactID, - 'cs' => $_GET['cs'], - 'cid' => '', - ); - } - $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE); - $this->assign('locDataURL', $locDataURL); - } - if (count($employer) > 0) { - $this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer)); - - $orgOptions = array( - 0 => ts('Select an existing organization'), - 1 => ts('Enter a new organization'), - ); - $this->addRadio('org_option', ts('options'), $orgOptions); - $this->setDefaults(array('org_option' => 0)); - } - } - - $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, - NULL, FALSE, NULL, FALSE, NULL, - CRM_Core_Permission::CREATE, NULL - ); - $this->assign('onBehalfOfFields', $profileFields); - $this->addElement('hidden', 'onbehalf_profile_id', $this->_profileId); - - $fieldTypes = array('Contact', 'Organization'); - $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); - $fieldTypes = array_merge($fieldTypes, $contactSubType); - - 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($this, $field, NULL, NULL, FALSE, $this->_prefix, NULL, $this->_prefix); - } - } - } - - } -} diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index f45d0ae761..9965edc374 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -789,7 +789,7 @@ LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm 'soft_credit_types', 'multilingual' => array( 'honor_block_title', - 'honor_block_text' + 'honor_block_text', ), ), 'on_behalf' => array( diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 68c4dcc6f2..21e393788d 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -232,7 +232,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']); } // if onbehalf-of-organization - if (!empty($this->_params['onbehalf_profile_id'])) { + if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf']['organization_name'])) { // CRM-15182 $this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name'); @@ -465,7 +465,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); - if (!empty($params['onbehalf_profile_id'])) { + if (!empty($params['onbehalf'])) { $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); diff --git a/CRM/Contribute/Form/Contribution/OnBehalfOf.php b/CRM/Contribute/Form/Contribution/OnBehalfOf.php new file mode 100644 index 0000000000..22ae17dffd --- /dev/null +++ b/CRM/Contribute/Form/Contribution/OnBehalfOf.php @@ -0,0 +1,110 @@ +_profileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, NULL, FALSE, NULL, 'GET'); + + $this->assign('suppressForm', TRUE); + $this->assign('snippet', TRUE); + $this->controller->_generateQFKey = FALSE; + } + + /** + * Build form for honoree contact / on behalf of organization. + */ + public function buildQuickForm() { + $contactID = $this->getContactID(); + + $this->assign('fieldSetTitle', ts('Organization Details')); + $this->assign('profileId', $this->_profileId); + + if ($contactID) { + $employer = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); + + if (count($employer)) { + // Related org url - pass checksum if needed + $args = array('cid' => ''); + if (!empty($_GET['cs'])) { + $args = array( + 'uid' => $this->_contactID, + 'cs' => $_GET['cs'], + 'cid' => '', + ); + } + $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE); + $this->assign('locDataURL', $locDataURL); + } + if (count($employer) > 0) { + $this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer)); + + $orgOptions = array( + 0 => ts('Select an existing organization'), + 1 => ts('Enter a new organization'), + ); + $this->addRadio('org_option', ts('options'), $orgOptions); + $this->setDefaults(array('org_option' => 0)); + } + } + + $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, + NULL, FALSE, NULL, FALSE, NULL, + CRM_Core_Permission::CREATE, NULL + ); + $this->assign('onBehalfOfFields', $profileFields); + $this->addElement('hidden', 'onbehalf_profile_id', $this->_profileId); + + $fieldTypes = array('Contact', 'Organization'); + $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); + $fieldTypes = array_merge($fieldTypes, $contactSubType); + + 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($this, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf'); + } + } + } + +} diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index 1d48059ae2..ca3412bfde 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -539,7 +539,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->assign('address', CRM_Utils_Address::format($addressFields)); - if (!empty($this->_params['onbehalf_profile_id'])) { + if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf'])) { $this->assign('onBehalfName', $this->_params['organization_name']); $locTypeId = array_keys($this->_params['onbehalf_location']['email']); $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']); @@ -732,6 +732,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { continue; } + $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, $module); + if ($module == 'soft_credit') { $form->_honoreeProfileId = $ufJoin->uf_group_id; $form->_honor_block_is_active = $ufJoin->is_active; @@ -753,11 +755,43 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { 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.')); } - //build soft-credit section - CRM_Contribute_Form_SoftCredit::buildQuickForm($form); + $form->assign('honor_block_is_active', $form->_honor_block_is_active); + + foreach (array('honor_block_title', 'honor_block_text') as $name) { + $form->assign($name, $params[$name]); + } + + $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); + + // radio button for Honor Type + foreach ($params['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); + + $prefix = 'honor'; + $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL, + NULL, NULL, + FALSE, NULL, + TRUE, NULL, + CRM_Core_Permission::CREATE + ); + $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId); + $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, $prefix); + } } else { - $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, 'on_behalf'); $form->_values = array_merge($params, $form->_values); $onBehalfProfileId = $ufJoin->uf_group_id; diff --git a/CRM/Core/xml/Menu/Contact.xml b/CRM/Core/xml/Menu/Contact.xml index 58987ab372..7f1ac88b2a 100644 --- a/CRM/Core/xml/Menu/Contact.xml +++ b/CRM/Core/xml/Menu/Contact.xml @@ -400,13 +400,6 @@ CRM_Contact_Page_AJAX::flipDupePairs merge duplicate contacts - - civicrm/profileContact/form - 1 - CRM_Contact_Form_ProfileContact - true - 0 - civicrm/activity/sms/add action=add diff --git a/CRM/Core/xml/Menu/Misc.xml b/CRM/Core/xml/Menu/Misc.xml index aec5f169d7..3fde326200 100644 --- a/CRM/Core/xml/Menu/Misc.xml +++ b/CRM/Core/xml/Menu/Misc.xml @@ -207,4 +207,11 @@ access CiviCRM Insert CiviCRM Content + + civicrm/onbehalf/form + 1 + CRM_Contribute_Form_Contribution_OnBehalfOf + true + 0 + diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 710854ac16..71fcc7f9a9 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -199,4 +199,5 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; return TRUE; } + } diff --git a/templates/CRM/Contribute/Form/Contribution/Main.tpl b/templates/CRM/Contribute/Form/Contribution/Main.tpl index 90e280be2e..440d3a05d9 100644 --- a/templates/CRM/Contribute/Form/Contribution/Main.tpl +++ b/templates/CRM/Contribute/Form/Contribution/Main.tpl @@ -160,19 +160,32 @@
- {include file="CRM/Contact/Form/ProfileContact.tpl"} + {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"} {* User account registration option. Displays if enabled for one of the profiles on this page. *} {include file="CRM/common/CMSUser.tpl"} {include file="CRM/Contribute/Form/Contribution/PremiumBlock.tpl" context="makeContribution"} {if $honor_block_is_active} -
- {include file="CRM/Contribute/Form/SoftCredit.tpl"} -
- {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'} -
-
+
+ {crmRegion name="contribution-soft-credit-block"} + {$honor_block_title} +
+ {$honor_block_text} +
+ {if $form.soft_credit_type_id.html} +
+
+ {$form.soft_credit_type_id.html} +
{ts}Select an option to reveal honoree information fields.{/ts}
+
+
+ {/if} + {/crmRegion} +
+ {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'} +
+
{/if}
diff --git a/templates/CRM/Contact/Form/ProfileContact.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl similarity index 98% rename from templates/CRM/Contact/Form/ProfileContact.tpl rename to templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index 723e422231..0319981834 100644 --- a/templates/CRM/Contact/Form/ProfileContact.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -110,7 +110,7 @@ } {/literal}{if $onBehalfprofileId} {capture assign='onBehalfprofileId'}id={$onBehalfprofileId}&{/capture}; - var dataUrl = "{crmURL p='civicrm/profileContact/form' h=0 q="`$onBehalfprofileId`prefix=onbehalf"}"; + var dataUrl = "{crmURL p='civicrm/onbehalf/form' h=0 q="`$onBehalfprofileId`prefix=onbehalf"}"; {/if}{literal} if (typeof dataUrl != 'undefined') {CRM.loadPage(dataUrl, {target: '#on-behalf-block'})}; } diff --git a/templates/CRM/Contribute/Form/SoftCredit.tpl b/templates/CRM/Contribute/Form/SoftCredit.tpl index 7b8e7ab3df..a71f886c2a 100644 --- a/templates/CRM/Contribute/Form/SoftCredit.tpl +++ b/templates/CRM/Contribute/Form/SoftCredit.tpl @@ -24,22 +24,6 @@ +--------------------------------------------------------------------+ *} {* template for adding form elements for soft credit form*} -{if $honor_block_is_active} - {crmRegion name="contribution-soft-credit-block"} - {$honor_block_title} -
- {$honor_block_text} -
- {if $form.soft_credit_type_id.html} -
-
- {$form.soft_credit_type_id.html} -
{ts}Select an option to reveal honoree information fields.{/ts}
-
-
- {/if} - {/crmRegion} -{else} {section name='i' start=1 loop=$rowCount} {assign var='rowNumber' value=$smarty.section.i.index} @@ -63,7 +47,7 @@
-{/if} + {literal}