Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
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 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Membership Type | |
38 | * | |
39 | */ | |
fb3082b2 | 40 | class CRM_Member_Form_MembershipStatus extends CRM_Member_Form_MembershipConfig { |
6a488035 TO |
41 | |
42 | /** | |
c490a46a | 43 | * Set default values for the form. MobileProvider that in edit/view mode |
6a488035 TO |
44 | * the default values are retrieved from the database |
45 | * | |
6a488035 | 46 | * |
355ba699 | 47 | * @return void |
6a488035 TO |
48 | */ |
49 | public function setDefaultValues() { | |
6a488035 TO |
50 | $defaults = parent::setDefaultValues(); |
51 | ||
52 | //finding default weight to be put | |
a7488080 | 53 | if (empty($defaults['weight'])) { |
6a488035 TO |
54 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus'); |
55 | } | |
56 | return $defaults; | |
57 | } | |
58 | ||
59 | /** | |
fe482240 | 60 | * Build the form object. |
6a488035 | 61 | * |
355ba699 | 62 | * @return void |
6a488035 TO |
63 | */ |
64 | public function buildQuickForm() { | |
65 | parent::buildQuickForm(); | |
66 | ||
67 | if ($this->_action & CRM_Core_Action::DELETE) { | |
68 | return; | |
69 | } | |
70 | ||
71 | $this->applyFilter('__ALL__', 'trim'); | |
72 | ||
73 | if ($this->_id) { | |
74 | $name = $this->add('text', 'name', ts('Name'), | |
75 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name') | |
76 | ); | |
77 | $name->freeze(); | |
78 | $this->assign('id', $this->_id); | |
79 | } | |
80 | $this->add('text', 'label', ts('Label'), | |
81 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE | |
82 | ); | |
83 | $this->addRule('label', ts('A membership status with this label already exists. Please select another label.'), | |
84 | 'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id, 'name') | |
85 | ); | |
86 | ||
87 | $this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues::eventDate(), TRUE); | |
6795600d | 88 | $this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList()); |
6a488035 TO |
89 | $this->add('text', 'start_event_adjust_interval', ts('Start Event Adjust Interval'), |
90 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'start_event_adjust_interval') | |
91 | ); | |
6795600d CW |
92 | $this->add('select', 'end_event', ts('End Event'), array('' => ts('- select -')) + CRM_Core_SelectValues::eventDate()); |
93 | $this->add('select', 'end_event_adjust_unit', ts('End Event Adjustment'), array('' => ts('- select -')) + CRM_Core_SelectValues::unitList()); | |
6a488035 TO |
94 | $this->add('text', 'end_event_adjust_interval', ts('End Event Adjust Interval'), |
95 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval') | |
96 | ); | |
97 | $this->add('checkbox', 'is_current_member', ts('Current Membership?')); | |
98 | $this->add('checkbox', 'is_admin', ts('Administrator Only?')); | |
99 | ||
7ecddde4 | 100 | $this->add('text', 'weight', ts('Order'), |
6a488035 TO |
101 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight') |
102 | ); | |
103 | $this->add('checkbox', 'is_default', ts('Default?')); | |
104 | $this->add('checkbox', 'is_active', ts('Enabled?')); | |
105 | } | |
106 | ||
107 | /** | |
fe482240 | 108 | * Process the form submission. |
6a488035 | 109 | * |
6a488035 | 110 | * |
355ba699 | 111 | * @return void |
6a488035 TO |
112 | */ |
113 | public function postProcess() { | |
114 | if ($this->_action & CRM_Core_Action::DELETE) { | |
92e4c2a5 | 115 | try { |
dcc4f6a7 | 116 | CRM_Member_BAO_MembershipStatus::del($this->_id); |
117 | } | |
353ffa53 | 118 | catch (CRM_Core_Exception $e) { |
dcc4f6a7 | 119 | CRM_Core_Error::statusBounce($e->getMessage(), NULL, ts('Delete Failed')); |
120 | } | |
6a488035 TO |
121 | CRM_Core_Session::setStatus(ts('Selected membership status has been deleted.'), ts('Record Deleted'), 'success'); |
122 | } | |
123 | else { | |
124 | $params = $ids = array(); | |
125 | // store the submitted values in an array | |
126 | $params = $this->exportValues(); | |
d4cab3e4 | 127 | $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); |
128 | $params['is_current_member'] = CRM_Utils_Array::value('is_current_member', $params, FALSE); | |
129 | $params['is_admin'] = CRM_Utils_Array::value('is_admin', $params, FALSE); | |
130 | $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); | |
6a488035 TO |
131 | |
132 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
133 | $ids['membershipStatus'] = $this->_id; | |
134 | } | |
135 | $oldWeight = NULL; | |
136 | if ($this->_id) { | |
137 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id'); | |
138 | } | |
139 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']); | |
140 | ||
141 | // only for add mode, set label to name. | |
142 | if ($this->_action & CRM_Core_Action::ADD) { | |
143 | $params['name'] = $params['label']; | |
144 | } | |
145 | ||
146 | $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids); | |
147 | CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', | |
353ffa53 TO |
148 | array(1 => $membershipStatus->label) |
149 | ), ts('Saved'), 'success'); | |
6a488035 TO |
150 | } |
151 | } | |
96025800 | 152 | |
6a488035 | 153 | } |