Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 | 16 | */ |
84403e23 | 17 | class CRM_Admin_Form_ParticipantStatusType extends CRM_Admin_Form { |
d5965a37 | 18 | |
6e62b28c TM |
19 | /** |
20 | * Explicitly declare the entity api name. | |
21 | */ | |
22 | public function getDefaultEntity() { | |
23 | return 'ParticipantStatusType'; | |
24 | } | |
d5965a37 | 25 | |
ce064e4f | 26 | /** |
27 | * Build form. | |
28 | */ | |
6a488035 TO |
29 | public function buildQuickForm() { |
30 | parent::buildQuickForm(); | |
31 | ||
32 | if ($this->_action & CRM_Core_Action::DELETE) { | |
33 | ||
34 | return; | |
35 | ||
36 | } | |
37 | ||
38 | $this->applyFilter('__ALL__', 'trim'); | |
39 | ||
40 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType'); | |
41 | ||
42 | $this->add('text', 'name', ts('Name'), NULL, TRUE); | |
43 | ||
44 | $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE); | |
45 | ||
be2fb01f | 46 | $this->addSelect('class', ['required' => TRUE]); |
6a488035 TO |
47 | |
48 | $this->add('checkbox', 'is_active', ts('Active?')); | |
49 | $this->add('checkbox', 'is_counted', ts('Counted?')); | |
50 | ||
f20d2b0d | 51 | $this->add('number', 'weight', ts('Order'), $attributes['weight'], TRUE); |
6a488035 | 52 | |
be2fb01f | 53 | $this->addSelect('visibility_id', ['label' => ts('Visibility'), 'required' => TRUE]); |
1d958464 CW |
54 | |
55 | $this->assign('id', $this->_id); | |
6a488035 TO |
56 | } |
57 | ||
e0ef6999 | 58 | /** |
ce064e4f | 59 | * Set default values. |
60 | * | |
e0ef6999 EM |
61 | * @return array |
62 | */ | |
00be9182 | 63 | public function setDefaultValues() { |
6a488035 | 64 | $defaults = parent::setDefaultValues(); |
a7488080 | 65 | if (empty($defaults['weight'])) { |
6a488035 TO |
66 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType'); |
67 | } | |
68 | $this->_isReserved = CRM_Utils_Array::value('is_reserved', $defaults); | |
69 | if ($this->_isReserved) { | |
be2fb01f | 70 | $this->freeze(['name', 'class', 'is_active']); |
6a488035 TO |
71 | } |
72 | return $defaults; | |
73 | } | |
74 | ||
00be9182 | 75 | public function postProcess() { |
6a488035 TO |
76 | if ($this->_action & CRM_Core_Action::DELETE) { |
77 | if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($this->_id)) { | |
78 | CRM_Core_Session::setStatus(ts('Selected participant status has been deleted.'), ts('Record Deleted'), 'success'); | |
79 | } | |
80 | else { | |
81 | CRM_Core_Session::setStatus(ts('Selected participant status has <strong>NOT</strong> been deleted; there are still participants with this status.'), ts('Sorry'), 'error'); | |
82 | } | |
83 | return; | |
84 | } | |
85 | ||
86 | $formValues = $this->controller->exportValues($this->_name); | |
87 | ||
be2fb01f | 88 | $params = [ |
6a488035 TO |
89 | 'name' => CRM_Utils_Array::value('name', $formValues), |
90 | 'label' => CRM_Utils_Array::value('label', $formValues), | |
91 | 'class' => CRM_Utils_Array::value('class', $formValues), | |
92 | 'is_active' => CRM_Utils_Array::value('is_active', $formValues, FALSE), | |
93 | 'is_counted' => CRM_Utils_Array::value('is_counted', $formValues, FALSE), | |
94 | 'weight' => CRM_Utils_Array::value('weight', $formValues), | |
95 | 'visibility_id' => CRM_Utils_Array::value('visibility_id', $formValues), | |
be2fb01f | 96 | ]; |
6a488035 TO |
97 | |
98 | // make sure a malicious POST does not change these on reserved statuses | |
4f99ca55 TO |
99 | if ($this->_isReserved) { |
100 | unset($params['name'], $params['class'], $params['is_active']); | |
02fc859b | 101 | } |
6a488035 TO |
102 | |
103 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
104 | ||
105 | $params['id'] = $this->_id; | |
106 | ||
107 | } | |
108 | ||
109 | if ($this->_id) { | |
110 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id, 'weight', 'id'); | |
111 | } | |
112 | else { | |
113 | $oldWeight = 0; | |
114 | } | |
115 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']); | |
116 | ||
117 | $participantStatus = CRM_Event_BAO_ParticipantStatusType::create($params); | |
118 | ||
119 | if ($participantStatus->id) { | |
120 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
121 | CRM_Core_Session::setStatus(ts('The Participant Status has been updated.'), ts('Saved'), 'success'); | |
122 | } | |
123 | else { | |
124 | CRM_Core_Session::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success'); | |
125 | } | |
126 | } | |
127 | else { | |
128 | CRM_Core_Session::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success'); | |
129 | } | |
130 | } | |
96025800 | 131 | |
6a488035 | 132 | } |