| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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-2015 |
| 32 | */ |
| 33 | class CRM_Admin_Form_ParticipantStatusType extends CRM_Admin_Form { |
| 34 | |
| 35 | /** |
| 36 | * Explicitly declare the entity api name. |
| 37 | */ |
| 38 | public function getDefaultEntity() { |
| 39 | return 'ParticipantStatusType'; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Build form. |
| 44 | */ |
| 45 | public function buildQuickForm() { |
| 46 | parent::buildQuickForm(); |
| 47 | |
| 48 | if ($this->_action & CRM_Core_Action::DELETE) { |
| 49 | |
| 50 | return; |
| 51 | |
| 52 | } |
| 53 | |
| 54 | $this->applyFilter('__ALL__', 'trim'); |
| 55 | |
| 56 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType'); |
| 57 | |
| 58 | $this->add('text', 'name', ts('Name'), NULL, TRUE); |
| 59 | |
| 60 | $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE); |
| 61 | |
| 62 | $this->addSelect('class', array('required' => TRUE)); |
| 63 | |
| 64 | $this->add('checkbox', 'is_active', ts('Active?')); |
| 65 | $this->add('checkbox', 'is_counted', ts('Counted?')); |
| 66 | |
| 67 | $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE); |
| 68 | |
| 69 | $this->addSelect('visibility_id', array('label' => ts('Visibility'), 'required' => TRUE)); |
| 70 | |
| 71 | $this->assign('id', $this->_id); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Set default values. |
| 76 | * |
| 77 | * @return array |
| 78 | */ |
| 79 | public function setDefaultValues() { |
| 80 | $defaults = parent::setDefaultValues(); |
| 81 | if (empty($defaults['weight'])) { |
| 82 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType'); |
| 83 | } |
| 84 | $this->_isReserved = CRM_Utils_Array::value('is_reserved', $defaults); |
| 85 | if ($this->_isReserved) { |
| 86 | $this->freeze(array('name', 'class', 'is_active')); |
| 87 | } |
| 88 | return $defaults; |
| 89 | } |
| 90 | |
| 91 | public function postProcess() { |
| 92 | if ($this->_action & CRM_Core_Action::DELETE) { |
| 93 | if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($this->_id)) { |
| 94 | CRM_Core_Session::setStatus(ts('Selected participant status has been deleted.'), ts('Record Deleted'), 'success'); |
| 95 | } |
| 96 | else { |
| 97 | CRM_Core_Session::setStatus(ts('Selected participant status has <strong>NOT</strong> been deleted; there are still participants with this status.'), ts('Sorry'), 'error'); |
| 98 | } |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | $formValues = $this->controller->exportValues($this->_name); |
| 103 | |
| 104 | $params = array( |
| 105 | 'name' => CRM_Utils_Array::value('name', $formValues), |
| 106 | 'label' => CRM_Utils_Array::value('label', $formValues), |
| 107 | 'class' => CRM_Utils_Array::value('class', $formValues), |
| 108 | 'is_active' => CRM_Utils_Array::value('is_active', $formValues, FALSE), |
| 109 | 'is_counted' => CRM_Utils_Array::value('is_counted', $formValues, FALSE), |
| 110 | 'weight' => CRM_Utils_Array::value('weight', $formValues), |
| 111 | 'visibility_id' => CRM_Utils_Array::value('visibility_id', $formValues), |
| 112 | ); |
| 113 | |
| 114 | // make sure a malicious POST does not change these on reserved statuses |
| 115 | if ($this->_isReserved) { |
| 116 | unset($params['name'], $params['class'], $params['is_active']); |
| 117 | } |
| 118 | |
| 119 | if ($this->_action & CRM_Core_Action::UPDATE) { |
| 120 | |
| 121 | $params['id'] = $this->_id; |
| 122 | |
| 123 | } |
| 124 | |
| 125 | if ($this->_id) { |
| 126 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id, 'weight', 'id'); |
| 127 | } |
| 128 | else { |
| 129 | $oldWeight = 0; |
| 130 | } |
| 131 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']); |
| 132 | |
| 133 | $participantStatus = CRM_Event_BAO_ParticipantStatusType::create($params); |
| 134 | |
| 135 | if ($participantStatus->id) { |
| 136 | if ($this->_action & CRM_Core_Action::UPDATE) { |
| 137 | CRM_Core_Session::setStatus(ts('The Participant Status has been updated.'), ts('Saved'), 'success'); |
| 138 | } |
| 139 | else { |
| 140 | CRM_Core_Session::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success'); |
| 141 | } |
| 142 | } |
| 143 | else { |
| 144 | CRM_Core_Session::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success'); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | } |