Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * This class generates form components for Membership Type | |
6a488035 | 36 | */ |
fb3082b2 | 37 | class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig { |
6a488035 | 38 | |
763f7a8a | 39 | |
40 | /** | |
41 | * Explicitly declare the entity api name. | |
42 | */ | |
43 | public function getDefaultEntity() { | |
44 | return 'MembershipStatus'; | |
45 | } | |
46 | ||
47 | /** | |
48 | * Explicitly declare the form context. | |
49 | */ | |
50 | public function getDefaultContext() { | |
51 | return 'create'; | |
52 | } | |
53 | ||
6a488035 | 54 | /** |
c490a46a | 55 | * Set default values for the form. MobileProvider that in edit/view mode |
6a488035 TO |
56 | * the default values are retrieved from the database |
57 | * | |
6a488035 | 58 | * |
355ba699 | 59 | * @return void |
6a488035 TO |
60 | */ |
61 | public function setDefaultValues() { | |
6a488035 TO |
62 | $defaults = parent::setDefaultValues(); |
63 | ||
64 | //finding default weight to be put | |
a7488080 | 65 | if (empty($defaults['weight'])) { |
6a488035 TO |
66 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus'); |
67 | } | |
68 | return $defaults; | |
69 | } | |
70 | ||
71 | /** | |
fe482240 | 72 | * Build the form object. |
6a488035 | 73 | * |
355ba699 | 74 | * @return void |
6a488035 TO |
75 | */ |
76 | public function buildQuickForm() { | |
77 | parent::buildQuickForm(); | |
78 | ||
79 | if ($this->_action & CRM_Core_Action::DELETE) { | |
80 | return; | |
81 | } | |
82 | ||
83 | $this->applyFilter('__ALL__', 'trim'); | |
84 | ||
85 | if ($this->_id) { | |
86 | $name = $this->add('text', 'name', ts('Name'), | |
87 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name') | |
88 | ); | |
89 | $name->freeze(); | |
90 | $this->assign('id', $this->_id); | |
91 | } | |
92 | $this->add('text', 'label', ts('Label'), | |
93 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE | |
94 | ); | |
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') | |
97 | ); | |
98 | ||
99 | $this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues::eventDate(), TRUE); | |
6795600d | 100 | $this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList()); |
6a488035 TO |
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') | |
103 | ); | |
6795600d CW |
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()); | |
6a488035 TO |
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') | |
108 | ); | |
109 | $this->add('checkbox', 'is_current_member', ts('Current Membership?')); | |
110 | $this->add('checkbox', 'is_admin', ts('Administrator Only?')); | |
111 | ||
7ecddde4 | 112 | $this->add('text', 'weight', ts('Order'), |
6a488035 TO |
113 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight') |
114 | ); | |
115 | $this->add('checkbox', 'is_default', ts('Default?')); | |
116 | $this->add('checkbox', 'is_active', ts('Enabled?')); | |
117 | } | |
118 | ||
119 | /** | |
fe482240 | 120 | * Process the form submission. |
6a488035 | 121 | * |
6a488035 | 122 | * |
355ba699 | 123 | * @return void |
6a488035 TO |
124 | */ |
125 | public function postProcess() { | |
126 | if ($this->_action & CRM_Core_Action::DELETE) { | |
92e4c2a5 | 127 | try { |
dcc4f6a7 | 128 | CRM_Member_BAO_MembershipStatus::del($this->_id); |
129 | } | |
353ffa53 | 130 | catch (CRM_Core_Exception $e) { |
dcc4f6a7 | 131 | CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed')); |
132 | } | |
6a488035 TO |
133 | CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success'); |
134 | } | |
135 | else { | |
136 | $params = $ids = array(); | |
137 | // store the submitted values in an array | |
138 | $params = $this->exportValues(); | |
d4cab3e4 | 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); | |
6a488035 TO |
143 | |
144 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
145 | $ids['membershipStatus'] = $this->_id; | |
146 | } | |
147 | $oldWeight = NULL; | |
148 | if ($this->_id) { | |
149 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id'); | |
150 | } | |
151 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']); | |
152 | ||
153 | // only for add mode, set label to name. | |
154 | if ($this->_action & CRM_Core_Action::ADD) { | |
155 | $params['name'] = $params['label']; | |
156 | } | |
157 | ||
158 | $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids); | |
159 | CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', | |
353ffa53 TO |
160 | array(1 => $membershipStatus->label) |
161 | ), ts('Saved'), 'success'); | |
6a488035 TO |
162 | } |
163 | } | |
96025800 | 164 | |
6a488035 | 165 | } |