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