| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.3 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2013 | |
| 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 |
| 31 | * @copyright CiviCRM LLC (c) 2004-2013 |
| 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 | * |
| 48 | * @return None |
| 49 | */ |
| 50 | public function setDefaultValues() { |
| 51 | $defaults = array(); |
| 52 | $defaults = parent::setDefaultValues(); |
| 53 | |
| 54 | //finding default weight to be put |
| 55 | if (!CRM_Utils_Array::value('weight', $defaults)) { |
| 56 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus'); |
| 57 | } |
| 58 | return $defaults; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Function to build the form |
| 63 | * |
| 64 | * @return None |
| 65 | * @access public |
| 66 | */ |
| 67 | public function buildQuickForm() { |
| 68 | parent::buildQuickForm(); |
| 69 | |
| 70 | if ($this->_action & CRM_Core_Action::DELETE) { |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | $this->applyFilter('__ALL__', 'trim'); |
| 75 | |
| 76 | if ($this->_id) { |
| 77 | $name = $this->add('text', 'name', ts('Name'), |
| 78 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'name') |
| 79 | ); |
| 80 | $name->freeze(); |
| 81 | $this->assign('id', $this->_id); |
| 82 | } |
| 83 | $this->add('text', 'label', ts('Label'), |
| 84 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'label'), TRUE |
| 85 | ); |
| 86 | $this->addRule('label', ts('A membership status with this label already exists. Please select another label.'), |
| 87 | 'objectExists', array('CRM_Member_DAO_MembershipStatus', $this->_id, 'name') |
| 88 | ); |
| 89 | |
| 90 | $this->add('select', 'start_event', ts('Start Event'), CRM_Core_SelectValues::eventDate(), TRUE); |
| 91 | $this->add('select', 'start_event_adjust_unit', ts('Start Event Adjustment'), CRM_Core_SelectValues::unitList()); |
| 92 | $this->add('text', 'start_event_adjust_interval', ts('Start Event Adjust Interval'), |
| 93 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'start_event_adjust_interval') |
| 94 | ); |
| 95 | $this->add('select', 'end_event', ts('End Event'), CRM_Core_SelectValues::eventDate(), FALSE); |
| 96 | $this->add('select', 'end_event_adjust_unit', ts('End Event Adjustment'), CRM_Core_SelectValues::unitList()); |
| 97 | $this->add('text', 'end_event_adjust_interval', ts('End Event Adjust Interval'), |
| 98 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'end_event_adjust_interval') |
| 99 | ); |
| 100 | $this->add('checkbox', 'is_current_member', ts('Current Membership?')); |
| 101 | $this->add('checkbox', 'is_admin', ts('Administrator Only?')); |
| 102 | |
| 103 | $this->add('text', 'weight', ts('Weight'), |
| 104 | CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipStatus', 'weight') |
| 105 | ); |
| 106 | $this->add('checkbox', 'is_default', ts('Default?')); |
| 107 | $this->add('checkbox', 'is_active', ts('Enabled?')); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Function to process the form |
| 112 | * |
| 113 | * @access public |
| 114 | * |
| 115 | * @return None |
| 116 | */ |
| 117 | public function postProcess() { |
| 118 | if ($this->_action & CRM_Core_Action::DELETE) { |
| 119 | $wt = CRM_Utils_Weight::delWeight('CRM_Member_DAO_MembershipStatus', $this->_id); |
| 120 | CRM_Member_BAO_MembershipStatus::del($this->_id); |
| 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(); |
| 127 | |
| 128 | if ($this->_action & CRM_Core_Action::UPDATE) { |
| 129 | $ids['membershipStatus'] = $this->_id; |
| 130 | } |
| 131 | $oldWeight = NULL; |
| 132 | if ($this->_id) { |
| 133 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $this->_id, 'weight', 'id'); |
| 134 | } |
| 135 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Member_DAO_MembershipStatus', $oldWeight, $params['weight']); |
| 136 | |
| 137 | // only for add mode, set label to name. |
| 138 | if ($this->_action & CRM_Core_Action::ADD) { |
| 139 | $params['name'] = $params['label']; |
| 140 | } |
| 141 | |
| 142 | $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params, $ids); |
| 143 | CRM_Core_Session::setStatus(ts('The membership status \'%1\' has been saved.', |
| 144 | array(1 => $membershipStatus->label) |
| 145 | ), ts('Saved'), 'success'); |
| 146 | } |
| 147 | } |
| 148 | } |