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 | |
88aae6d4 A |
19 | /** |
20 | * @var bool | |
21 | */ | |
22 | public $submitOnce = TRUE; | |
23 | ||
6e62b28c TM |
24 | /** |
25 | * Explicitly declare the entity api name. | |
26 | */ | |
27 | public function getDefaultEntity() { | |
28 | return 'ParticipantStatusType'; | |
29 | } | |
d5965a37 | 30 | |
ce064e4f | 31 | /** |
32 | * Build form. | |
33 | */ | |
6a488035 TO |
34 | public function buildQuickForm() { |
35 | parent::buildQuickForm(); | |
36 | ||
37 | if ($this->_action & CRM_Core_Action::DELETE) { | |
38 | ||
39 | return; | |
40 | ||
41 | } | |
42 | ||
43 | $this->applyFilter('__ALL__', 'trim'); | |
44 | ||
45 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_ParticipantStatusType'); | |
46 | ||
47 | $this->add('text', 'name', ts('Name'), NULL, TRUE); | |
48 | ||
49 | $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE); | |
50 | ||
be2fb01f | 51 | $this->addSelect('class', ['required' => TRUE]); |
6a488035 TO |
52 | |
53 | $this->add('checkbox', 'is_active', ts('Active?')); | |
54 | $this->add('checkbox', 'is_counted', ts('Counted?')); | |
55 | ||
f20d2b0d | 56 | $this->add('number', 'weight', ts('Order'), $attributes['weight'], TRUE); |
6a488035 | 57 | |
be2fb01f | 58 | $this->addSelect('visibility_id', ['label' => ts('Visibility'), 'required' => TRUE]); |
1d958464 CW |
59 | |
60 | $this->assign('id', $this->_id); | |
6a488035 TO |
61 | } |
62 | ||
e0ef6999 | 63 | /** |
ce064e4f | 64 | * Set default values. |
65 | * | |
e0ef6999 EM |
66 | * @return array |
67 | */ | |
00be9182 | 68 | public function setDefaultValues() { |
6a488035 | 69 | $defaults = parent::setDefaultValues(); |
a7488080 | 70 | if (empty($defaults['weight'])) { |
6a488035 TO |
71 | $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType'); |
72 | } | |
9c1bc317 | 73 | $this->_isReserved = $defaults['is_reserved'] ?? NULL; |
6a488035 | 74 | if ($this->_isReserved) { |
be2fb01f | 75 | $this->freeze(['name', 'class', 'is_active']); |
6a488035 TO |
76 | } |
77 | return $defaults; | |
78 | } | |
79 | ||
00be9182 | 80 | public function postProcess() { |
6a488035 TO |
81 | if ($this->_action & CRM_Core_Action::DELETE) { |
82 | if (CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($this->_id)) { | |
83 | CRM_Core_Session::setStatus(ts('Selected participant status has been deleted.'), ts('Record Deleted'), 'success'); | |
84 | } | |
85 | else { | |
86 | CRM_Core_Session::setStatus(ts('Selected participant status has <strong>NOT</strong> been deleted; there are still participants with this status.'), ts('Sorry'), 'error'); | |
87 | } | |
88 | return; | |
89 | } | |
90 | ||
91 | $formValues = $this->controller->exportValues($this->_name); | |
92 | ||
be2fb01f | 93 | $params = [ |
6b409353 CW |
94 | 'name' => $formValues['name'] ?? NULL, |
95 | 'label' => $formValues['label'] ?? NULL, | |
96 | 'class' => $formValues['class'] ?? NULL, | |
6187cca4 CW |
97 | 'is_active' => $formValues['is_active'] ?? FALSE, |
98 | 'is_counted' => $formValues['is_counted'] ?? FALSE, | |
6b409353 CW |
99 | 'weight' => $formValues['weight'] ?? NULL, |
100 | 'visibility_id' => $formValues['visibility_id'] ?? NULL, | |
be2fb01f | 101 | ]; |
6a488035 TO |
102 | |
103 | // make sure a malicious POST does not change these on reserved statuses | |
4f99ca55 TO |
104 | if ($this->_isReserved) { |
105 | unset($params['name'], $params['class'], $params['is_active']); | |
02fc859b | 106 | } |
6a488035 TO |
107 | |
108 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
109 | ||
110 | $params['id'] = $this->_id; | |
111 | ||
112 | } | |
113 | ||
114 | if ($this->_id) { | |
115 | $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id, 'weight', 'id'); | |
116 | } | |
117 | else { | |
118 | $oldWeight = 0; | |
119 | } | |
120 | $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']); | |
121 | ||
122 | $participantStatus = CRM_Event_BAO_ParticipantStatusType::create($params); | |
123 | ||
124 | if ($participantStatus->id) { | |
125 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
126 | CRM_Core_Session::setStatus(ts('The Participant Status has been updated.'), ts('Saved'), 'success'); | |
127 | } | |
128 | else { | |
129 | CRM_Core_Session::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success'); | |
130 | } | |
131 | } | |
132 | else { | |
133 | CRM_Core_Session::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success'); | |
134 | } | |
135 | } | |
96025800 | 136 | |
6a488035 | 137 | } |