From fb3082b2e0193352c8c366ce9105dfbaa3b2235e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 14 Nov 2014 04:03:42 +1300 Subject: [PATCH] CRM-15555 break sharing of parent class between unrelated forms admin forms (membership_type & membership_status) don't have much in common with membership & renewal forms - disconnect --- CRM/Member/Form.php | 25 +---- CRM/Member/Form/MembershipConfig.php | 156 +++++++++++++++++++++++++++ CRM/Member/Form/MembershipStatus.php | 2 +- CRM/Member/Form/MembershipType.php | 2 +- 4 files changed, 162 insertions(+), 23 deletions(-) create mode 100644 CRM/Member/Form/MembershipConfig.php diff --git a/CRM/Member/Form.php b/CRM/Member/Form.php index 495ce91d46..b832a56c04 100644 --- a/CRM/Member/Form.php +++ b/CRM/Member/Form.php @@ -46,16 +46,8 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { */ public $_id; - /** - * The name of the BAO object for this form - * - * @var string - */ - protected $_BAOName; - function preProcess() { - $this->_id = $this->get('id'); - $this->_BAOName = $this->get('BAOName'); + } /** @@ -69,12 +61,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { function setDefaultValues() { $defaults = array(); - if (isset($this->_id)) { - $params = array('id' => $this->_id); - $baoName = $this->_BAOName; - $baoName::retrieve($params, $defaults); - } - if (isset($defaults['minimum_fee'])) { $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a'); } @@ -153,12 +139,12 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { } } - /* - * Function to extract values from the contact create boxes on the form and assign appropriatley to + /** + * Function to extract values from the contact create boxes on the form and assign appropriately to * * - $this->_contributorEmail, * - $this->_memberEmail & - * - $this->_contributonName + * - $this->_contributionName * - $this->_memberName * - $this->_contactID (effectively memberContactId but changing might have spin-off effects) * - $this->_contributorContactId - id of the contributor @@ -171,9 +157,6 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment { * - contact_id * - soft_credit_contact_id */ - /** - * @param $formValues - */ function storeContactFields($formValues){ // in a 'standalone form' (contact id not in the url) the contact will be in the form values if (!empty($formValues['contact_id'])) { diff --git a/CRM/Member/Form/MembershipConfig.php b/CRM/Member/Form/MembershipConfig.php new file mode 100644 index 0000000000..3f5f107561 --- /dev/null +++ b/CRM/Member/Form/MembershipConfig.php @@ -0,0 +1,156 @@ +_id = $this->get('id'); + $this->_BAOName = $this->get('BAOName'); + } + + /** + * This function sets the default values for the form. MobileProvider that in edit/view mode + * the default values are retrieved from the database + * + * @access public + * + * @return array defaults + */ + function setDefaultValues() { + $defaults = array(); + + if (isset($this->_id)) { + $params = array('id' => $this->_id); + $baoName = $this->_BAOName; + $baoName::retrieve($params, $defaults); + } + + if (isset($defaults['minimum_fee'])) { + $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a'); + } + + if (isset($defaults['status'])) { + $this->assign('membershipStatus', $defaults['status']); + } + + if ($this->_action & CRM_Core_Action::ADD) { + $defaults['is_active'] = 1; + } + + if (isset($defaults['member_of_contact_id']) && + $defaults['member_of_contact_id'] + ) { + $defaults['member_org'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', + $defaults['member_of_contact_id'], 'display_name' + ); + } + return $defaults; + } + + /** + * Function to actually build the form + * + * @return void + * @access public + */ + public function buildQuickForm() { + if ($this->_action & CRM_Core_Action::RENEW) { + $this->addButtons(array( + array( + 'type' => 'upload', + 'name' => ts('Renew'), + 'isDefault' => TRUE + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel') + ) + ) + ); + } + elseif ($this->_action & CRM_Core_Action::DELETE) { + $this->addButtons(array( + array( + 'type' => 'next', + 'name' => ts('Delete'), + 'isDefault' => TRUE + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel') + ) + ) + ); + } + else { + $this->addButtons(array( + array( + 'type' => 'upload', + 'name' => ts('Save'), + 'isDefault' => TRUE + ), + array( + 'type' => 'upload', + 'name' => ts('Save and New'), + 'subName' => 'new' + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel') + ) + ) + ); + } + } +} + diff --git a/CRM/Member/Form/MembershipStatus.php b/CRM/Member/Form/MembershipStatus.php index c91c2660e5..56ef913072 100644 --- a/CRM/Member/Form/MembershipStatus.php +++ b/CRM/Member/Form/MembershipStatus.php @@ -37,7 +37,7 @@ * This class generates form components for Membership Type * */ -class CRM_Member_Form_MembershipStatus extends CRM_Member_Form { +class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig { /** * This function sets the default values for the form. MobileProvider that in edit/view mode diff --git a/CRM/Member/Form/MembershipType.php b/CRM/Member/Form/MembershipType.php index 4cca8ce15d..ebe231973a 100644 --- a/CRM/Member/Form/MembershipType.php +++ b/CRM/Member/Form/MembershipType.php @@ -37,7 +37,7 @@ * This class generates form components for Membership Type * */ -class CRM_Member_Form_MembershipType extends CRM_Member_Form { +class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { /** * max number of contacts we will display for membership-organisation -- 2.25.1