3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * This class generates form components for Membership Type
37 class CRM_Member_Form_MembershipStatus
extends CRM_Member_Form_MembershipConfig
{
41 * Explicitly declare the entity api name.
43 public function getDefaultEntity() {
44 return 'MembershipStatus';
48 * Explicitly declare the form context.
50 public function getDefaultContext() {
55 * Set default values for the form. MobileProvider that in edit/view mode
56 * the default values are retrieved from the database
61 public function setDefaultValues() {
62 $defaults = parent
::setDefaultValues();
64 //finding default weight to be put
65 if (empty($defaults['weight'])) {
66 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
72 * Build the form object.
76 public function buildQuickForm() {
77 parent
::buildQuickForm();
79 if ($this->_action
& CRM_Core_Action
::DELETE
) {
83 $this->applyFilter('__ALL__', 'trim');
86 $name = $this->add('text', 'name', ts('Name'),
87 CRM_Core_DAO
::getAttribute('CRM_Member_DAO_MembershipStatus', 'name')
90 $this->assign('id', $this->_id
);
92 $this->add('text', 'label', ts('Label'),
93 CRM_Core_DAO
::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE
95 $this->addRule('label', ts('A membership status with this label already exists. Please select another label.'),
96 'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id
, 'name')
99 $this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues
::eventDate(), TRUE);
100 $this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues
::unitList());
101 $this->add('text', 'start_event_adjust_interval', ts('Start Event Adjust Interval'),
102 CRM_Core_DAO
::getAttribute('CRM_Member_DAO_MembershipStatus', 'start_event_adjust_interval')
104 $this->add('select', 'end_event', ts('End Event'), array('' => ts('- select -')) + CRM_Core_SelectValues
::eventDate());
105 $this->add('select', 'end_event_adjust_unit', ts('End Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues
::unitList());
106 $this->add('text', 'end_event_adjust_interval', ts('End Event Adjust Interval'),
107 CRM_Core_DAO
::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval')
109 $this->add('checkbox', 'is_current_member', ts('Current Membership?'));
110 $this->add('checkbox', 'is_admin', ts('Administrator Only?'));
112 $this->add('text', 'weight', ts('Order'),
113 CRM_Core_DAO
::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight')
115 $this->add('checkbox', 'is_default', ts('Default?'));
116 $this->add('checkbox', 'is_active', ts('Enabled?'));
120 * Process the form submission.
125 public function postProcess() {
126 if ($this->_action
& CRM_Core_Action
::DELETE
) {
128 CRM_Member_BAO_MembershipStatus
::del($this->_id
);
130 catch (CRM_Core_Exception
$e) {
131 CRM_Core_Error
::statusBounce($e->getMessage(), NULL, ts('Delete Failed'));
133 CRM_Core_Session
::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success');
136 $params = $ids = array();
137 // store the submitted values in an array
138 $params = $this->exportValues();
139 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
140 $params['is_current_member'] = CRM_Utils_Array
::value('is_current_member', $params, FALSE);
141 $params['is_admin'] = CRM_Utils_Array
::value('is_admin', $params, FALSE);
142 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
144 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
145 $ids['membershipStatus'] = $this->_id
;
149 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id
, 'weight', 'id');
151 $params['weight'] = CRM_Utils_Weight
::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']);
153 // only for add mode, set label to name.
154 if ($this->_action
& CRM_Core_Action
::ADD
) {
155 $params['name'] = $params['label'];
158 $membershipStatus = CRM_Member_BAO_MembershipStatus
::add($params, $ids);
159 CRM_Core_Session
::setStatus(ts('The membership status \'%1\' has been saved.',
160 array(1 => $membershipStatus->label
)
161 ), ts('Saved'), 'success');