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