From d1f8e2785867806ee6d8335dc317aef73ed8b65e Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 21 Jul 2015 01:17:01 +0530 Subject: [PATCH] Initial changes --- CRM/Contribute/BAO/ContributionPage.php | 69 +++++++++++- CRM/Contribute/Form/ContributionPage.php | 11 -- .../Form/ContributionPage/Settings.php | 106 +++++++++++------- xml/schema/Contribute/ContributionPage.xml | 21 ---- 4 files changed, 136 insertions(+), 71 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 553b8db234..05e3d89b86 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -844,8 +844,75 @@ LEFT JOIN civicrm_premiums ON ( civicrm_premiums.entity_id = civicrm } /** - * Generate html for pdf in confirmation receipt email attachment. + * Get or Set multilingually affected on behalf params for processing module_data or setting default values. * + * @param string $params : + * @param bool $setDefault : If yes then returns array to used for setting default value afterward + * + * @return array|string + */ + public static function formatMultilingualOnBehalfParams($params, $setDefault = FALSE) { + $config = CRM_Core_Config::singleton(); + $onBehalfJson = $onBehalfJsonDecode = NULL; + $domain = new CRM_Core_DAO_Domain(); + $domain->find(TRUE); + + if ($setDefault) { + $onBehalfJsonDecode = json_decode($params); + $onBehalfJsonDecode = (array) $onBehalfJsonDecode->is_for_organization; + if (!$domain->locales && !empty($onBehalfJsonDecode['default'])) { + //monolingual state + $onBehalfJsonDecode += (array) $onBehalfJsonDecode['default']; + } + elseif (!empty($onBehalfJsonDecode[$config->lcMessages])) { + //multilingual state + foreach ($sctJsonDecode[$config->lcMessages] as $column => $value) { + $onBehalfJsonDecode[$column] = $value; + } + unset($onBehalfJsonDecode[$config->lcMessages]); + } + return $onBehalfJsonDecode; + } + + //check and handle multilingual honoree params + if (!$domain->locales) { + //if in singlelingual state simply return the array format + $onBehalfJson = json_encode( + array( + 'on_behalf' => array( + 'is_for_organization' => $params['is_for_organization'], + 'default' => array( + 'for_organization' => $params['for_organization'], + ), + ), + ) + ); + } + else { + $onBehalfJson = array( + 'on_behalf' => array( + 'is_for_organization' => $params['is_for_organization'], + $config->lcMessages => array( + 'for_organization' => $params['for_organization'], + ), + ), + ); + + $ufJoinDAO = new CRM_Core_DAO_UFJoin(); + $ufJoinDAO->module = 'on_behalf'; + $ufJoinDAO->entity_id = $params['id']; + $ufJoinDAO->find(TRUE); + $jsonData = json_decode($ufJoinDAO->module_data); + if ($jsonData) { + $onBehalfJson['on_behalf'] = array_merge((array) $jsonData->soft_credit, $onBehalfJson['on_behalf']); + } + $onBehalfJson = json_encode($onBehalfJson); + } + return $onBehalfJson; + } + + /** + * Generate html for pdf in confirmation receipt email attachment. * @param int $contributionId * Contribution Page Id. * @param int $userID diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 3c08ea6338..09889fd453 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -321,10 +321,6 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(); } - if (!isset($defaults['for_organization'])) { - $defaults['for_organization'] = ts('I am contributing on behalf of an organization.'); - } - if (!empty($defaults['recur_frequency_unit'])) { $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['recur_frequency_unit'] @@ -335,13 +331,6 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { $defaults['recur_frequency_unit'] = array('month' => 1); } - if (!empty($defaults['is_for_organization'])) { - $defaults['is_organization'] = 1; - } - else { - $defaults['is_for_organization'] = 1; - } - // confirm page starts out enabled if (!isset($defaults['is_confirm_enabled'])) { $defaults['is_confirm_enabled'] = 1; diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index 448645e660..8007d4d0ed 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -47,36 +47,52 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $soft_credit_types = CRM_Core_OptionGroup::values('soft_credit_type', TRUE, FALSE, FALSE, NULL, 'name'); if ($this->_id) { - $ufJoinParams = array( - 'module' => 'OnBehalf', - 'entity_table' => 'civicrm_contribution_page', - 'entity_id' => $this->_id, + $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', + $this->_id, + 'title' ); - $onBehalfIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); - if ($onBehalfIDs) { - // get the first one only - $defaults['onbehalf_profile_id'] = $onBehalfIDs[0]; - } - - $ufJoinDAO = new CRM_Core_DAO_UFJoin(); - $ufJoinDAO->module = 'soft_credit'; - $ufJoinDAO->entity_id = $this->_id; - if ($ufJoinDAO->find(TRUE)) { - $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id; - $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE); - $defaults = array_merge($defaults, $jsonData); - $defaults['honor_block_is_active'] = $ufJoinDAO->is_active; - } - else { - $ufGroupDAO = new CRM_Core_DAO_UFGroup(); - $ufGroupDAO->name = 'honoree_individual'; - if ($ufGroupDAO->find(TRUE)) { - $defaults['honoree_profile'] = $ufGroupDAO->id; + CRM_Utils_System::setTitle(ts('Title and Settings') . " ($title)"); + + foreach (array('on_behalf', 'soft_credit') as $module) { + $ufJoinDAO = new CRM_Core_DAO_UFJoin(); + $ufJoinDAO->module = $module; + $ufJoinDAO->entity_id = $this->_id; + if ($ufJoinDAO->find(TRUE)) { + if ($module == 'soft_credit') { + $defaults['honoree_profile'] = $ufJoinDAO->uf_group_id; + $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($ufJoinDAO->module_data, TRUE); + $defaults = array_merge($defaults, $jsonData); + $defaults['honor_block_is_active'] = $ufJoinDAO->is_active; + } + else { + $defaults['onbehalf_profile_id'] = $ufJoinDAO->uf_group_id; + $jsonData = CRM_Contribute_BAO_ContributionPage::formatMultilingualOnBehalfParams($ufJoinDAO->module_data, TRUE); + $defaults = array_merge($defaults, $jsonData); + $defaults['is_organization'] = $ufJoinDAO->is_active; + } + } + else { + if ($module == 'soft_credit') { + $ufGroupDAO = new CRM_Core_DAO_UFGroup(); + $ufGroupDAO->name = 'honoree_individual'; + if ($ufGroupDAO->find(TRUE)) { + $defaults['honoree_profile'] = $ufGroupDAO->id; + } + $defaults['soft_credit_types'] = array( + CRM_Utils_Array::value('in_honor_of', $soft_credit_types), + CRM_Utils_Array::value('in_memory_of', $soft_credit_types), + ); + } + else { + $ufGroupDAO = new CRM_Core_DAO_UFGroup(); + $ufGroupDAO->name = 'on_behalf_organization'; + if ($ufGroupDAO->find(TRUE)) { + $defaults['onbehalf_profile_id'] = $ufGroupDAO->id; + } + $defaults['for_organization'] = ts('I am contributing on behalf of an organization.'); + $defaults['is_for_organization'] = 1; + } } - $defaults['soft_credit_types'] = array( - CRM_Utils_Array::value('in_honor_of', $soft_credit_types), - CRM_Utils_Array::value('in_memory_of', $soft_credit_types), - ); } } else { @@ -147,7 +163,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1); $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2); $this->addGroup($options, 'is_for_organization', ''); - $this->add('textarea', 'for_organization', ts('On behalf of Label'), $attributes['for_organization']); + $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50)); // collect goal amount $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12)); @@ -292,6 +308,8 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); + CRM_Core_Error::debug( '$params', $params ); + exit; // we do this in case the user has hit the forward/back button if ($this->_id) { @@ -325,12 +343,13 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $sctJSON = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($params); } + + $dao = CRM_Contribute_BAO_ContributionPage::create($params); $ufJoinParams = array( - 'onbehalf_profile_id' => array( - 'is_active' => 1, - 'module' => 'OnBehalf', + 'is_organization' => array( + 'module' => 'on_behalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id, ), @@ -343,21 +362,32 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ foreach ($ufJoinParams as $index => $ufJoinParam) { if (!empty($params[$index])) { + // first delete all past entries + CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); + $ufJoinParam['uf_group_id'] = $params[$index]; $ufJoinParam['weight'] = 1; + $ufJoinParam['is_active'] = 1; if ($index == 'honor_block_is_active') { - $ufJoinParam['is_active'] = 1; $ufJoinParam['module'] = 'soft_credit'; $ufJoinParam['uf_group_id'] = $params['honoree_profile']; - $ufJoinParam['module_data'] = $sctJSON; + $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($params); } else { - // first delete all past entries - CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); - $ufJoinParam['uf_group_id'] = $params[$index]; + $ufJoinParam['module'] = 'on_behalf'; + $ufJoinParam['uf_group_id'] = $params['onbehalf_profile_id']; + $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatMultilingualHonorParams($params); } CRM_Core_BAO_UFJoin::create($ufJoinParam); } - elseif ($index == 'honor_block_is_active') { + else { + if ($index == 'honor_block_is_active') { + $params['honor_block_title'] = NULL; + $params['honor_block_text'] = NULL; + } + else { + $params['for_organization'] = NULL; + } + //On subsequent honor_block_is_active uncheck, disable(don't delete) //that particular honoree profile entry in UFjoin table, CRM-13981 $ufId = CRM_Core_BAO_UFJoin::findJoinEntryId($ufJoinParam); diff --git a/xml/schema/Contribute/ContributionPage.xml b/xml/schema/Contribute/ContributionPage.xml index 4ddacb7354..8d197dc330 100644 --- a/xml/schema/Contribute/ContributionPage.xml +++ b/xml/schema/Contribute/ContributionPage.xml @@ -270,27 +270,6 @@ Text and html allowed. displayed at the bottom of the success page. Common usage is to include link(s) to other pages such as tell-a-friend, etc. 1.3 - - is_for_organization - Allow For Organization - boolean - if true, signup is done on behalf of an organization - 0 - 2.1 - - - for_organization - On Behalf Of Organization - text - - TextArea - 2 - 50 - - true - This text field is shown when is_for_organization is checked. For example - I am contributing on behalf on an organization. - 2.1 - is_email_receipt Send email Receipt -- 2.25.1