3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Admin_Form_ParticipantStatusType
extends CRM_Admin_Form
{
22 public $submitOnce = TRUE;
25 * Explicitly declare the entity api name.
27 public function getDefaultEntity() {
28 return 'ParticipantStatusType';
34 public function buildQuickForm() {
35 parent
::buildQuickForm();
37 if ($this->_action
& CRM_Core_Action
::DELETE
) {
43 $this->applyFilter('__ALL__', 'trim');
45 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_ParticipantStatusType');
47 $this->add('text', 'name', ts('Name'), NULL, TRUE);
49 $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE);
51 $this->addSelect('class', ['required' => TRUE]);
53 $this->add('checkbox', 'is_active', ts('Active?'));
54 $this->add('checkbox', 'is_counted', ts('Counted?'));
56 $this->add('number', 'weight', ts('Order'), $attributes['weight'], TRUE);
58 $this->addSelect('visibility_id', ['label' => ts('Visibility'), 'required' => TRUE]);
60 $this->assign('id', $this->_id
);
68 public function setDefaultValues() {
69 $defaults = parent
::setDefaultValues();
70 if (empty($defaults['weight'])) {
71 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
73 $this->_isReserved
= $defaults['is_reserved'] ??
NULL;
74 if ($this->_isReserved
) {
75 $this->freeze(['name', 'class', 'is_active']);
80 public function postProcess() {
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');
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');
91 $formValues = $this->controller
->exportValues($this->_name
);
94 'name' => $formValues['name'] ??
NULL,
95 'label' => $formValues['label'] ??
NULL,
96 'class' => $formValues['class'] ??
NULL,
97 'is_active' => $formValues['is_active'] ??
FALSE,
98 'is_counted' => $formValues['is_counted'] ??
FALSE,
99 'weight' => $formValues['weight'] ??
NULL,
100 'visibility_id' => $formValues['visibility_id'] ??
NULL,
103 // make sure a malicious POST does not change these on reserved statuses
104 if ($this->_isReserved
) {
105 unset($params['name'], $params['class'], $params['is_active']);
108 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
110 $params['id'] = $this->_id
;
115 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id
, 'weight', 'id');
120 $params['weight'] = CRM_Utils_Weight
::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']);
122 $participantStatus = CRM_Event_BAO_ParticipantStatusType
::create($params);
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');
129 CRM_Core_Session
::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success');
133 CRM_Core_Session
::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success');