X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FContribute%2FForm%2FContributionPage%2FSettings.php;h=d62d54edda1ee8c76290b5f2da222737d6fda194;hb=7d86179d7d8e91160bbb5e6643fa265198a99a2d;hp=a880c93629ca383bcc32c60460071c3bd01f8471;hpb=db551313046d894dd1e7669f664ca7caac35f6fe;p=civicrm-core.git diff --git a/CRM/Contribute/Form/ContributionPage/Settings.php b/CRM/Contribute/Form/ContributionPage/Settings.php index a880c93629..d62d54edda 100644 --- a/CRM/Contribute/Form/ContributionPage/Settings.php +++ b/CRM/Contribute/Form/ContributionPage/Settings.php @@ -1,7 +1,7 @@ addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);")); - $allowCoreTypes = array_merge(array('Contact', 'Organization'), CRM_Contact_BAO_ContactType::subTypes('Organization')); - $allowSubTypes = array(); - $entities = array( - array( - 'entity_name' => 'contact_1', - 'entity_type' => 'OrganizationModel', - ), + //CRM-15787 - If applicable, register 'membership_1' + $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); + $coreTypes = array('Contact', 'Organization'); + + $entities[] = array( + 'entity_name' => array ('contact_1'), + 'entity_type' => 'OrganizationModel', ); + if ($member && $member['is_active']) { + $coreTypes[] = 'Membership'; + $entities[] = array( + 'entity_name' => array ('membership_1'), + 'entity_type' => 'MembershipModel', + ); + } + + $allowCoreTypes = array_merge($coreTypes, + CRM_Contact_BAO_ContactType::subTypes('Organization')); + $allowSubTypes = array(); + $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities); - $options = array(); + $options = array(); $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1); $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2); $this->addGroup($options, 'is_for_organization', ts('')); @@ -184,7 +193,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ 'entity' => 'ContributionSoft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, - 'class' => 'huge' + 'class' => 'huge', )); $entities = array( @@ -194,7 +203,12 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ ), ); - $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual')); + $allowCoreTypes = array_merge(array( + 'Contact', + 'Individual', + 'Organization', + 'Household' + ), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities); @@ -216,16 +230,17 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ /** * Global validation rules for the form * - * @param array $values posted values of the form + * @param array $values + * Posted values of the form. * * @param $files * @param $self * - * @return array list of errors to be posted back to the form + * @return array + * list of errors to be posted back to the form * @static - * @access public */ - static function formRule($values, $files, $self) { + public static function formRule($values, $files, $self) { $errors = array(); $contributionPageId = $self->_id; //CRM-4286 @@ -235,7 +250,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ // ensure on-behalf-of profile meets minimum requirements if (!empty($values['is_organization'])) { - if (empty($values['onbehalf_profile_id']) ) { + if (empty($values['onbehalf_profile_id'])) { $errors['onbehalf_profile_id'] = ts('Please select a profile to collect organization information on this contribution page.'); } else { @@ -268,7 +283,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ list($contributionProfiles['custom_pre_id'], $contributionProfiles['custom_post_id'] - ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); + ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $conProfileType = NULL; if ($contributionProfiles['custom_pre_id']) { @@ -281,7 +296,7 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ if ($contributionProfiles['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']); if ($postProfileType == 'Membership') { - $conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'"; + $conProfileType = empty($conProfileType) ? "'Includes Profile (bottom of page)'" : "{$conProfileType} and 'Includes Profile (bottom of page)'"; } } if (!empty($conProfileType)) { @@ -295,7 +310,6 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ * Process the form * * @return void - * @access public */ public function postProcess() { // get the submitted form values. @@ -348,26 +362,25 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ 'module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id, - ) + ), ); - foreach ($ufJoinParams as $index => $ufJoinParam) { if (!empty($params[$index])) { - $ufJoinParam['weight'] = 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; - } - else { - // first delete all past entries - CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); - $ufJoinParam['uf_group_id'] = $params[$index]; - } - CRM_Core_BAO_UFJoin::create($ufJoinParam); + $ufJoinParam['weight'] = 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; } + else { + // first delete all past entries + CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); + $ufJoinParam['uf_group_id'] = $params[$index]; + } + CRM_Core_BAO_UFJoin::create($ufJoinParam); + } elseif ($index == 'honor_block_is_active') { //On subsequent honor_block_is_active uncheck, disable(don't delete) //that particular honoree profile entry in UFjoin table, CRM-13981 @@ -389,8 +402,8 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ $url = 'civicrm/admin/contribute'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", - array(1 => $this->getTitle()) - ), ts('Saved'), 'success'); + array(1 => $this->getTitle()) + ), ts('Saved'), 'success'); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); @@ -402,10 +415,8 @@ class CRM_Contribute_Form_ContributionPage_Settings extends CRM_Contribute_Form_ * Return a descriptive name for the page, used in wizard header * * @return string - * @access public */ public function getTitle() { return ts('Title and Settings'); } } -