3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Admin_Form_ParticipantStatus
extends CRM_Admin_Form
{
36 public function buildQuickForm() {
37 parent
::buildQuickForm();
39 if ($this->_action
& CRM_Core_Action
::DELETE
) {
45 $this->applyFilter('__ALL__', 'trim');
47 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_ParticipantStatusType');
49 $this->add('text', 'name', ts('Name'), NULL, TRUE);
51 $this->add('text', 'label', ts('Label'), $attributes['label'], TRUE);
55 'Positive', 'Pending', 'Waiting', 'Negative') as $class) {
56 $classes[$class] = CRM_Event_DAO_ParticipantStatusType
::tsEnum('class', $class);
58 $this->add('select', 'class', ts('Class'), $classes, TRUE);
60 $this->add('checkbox', 'is_active', ts('Active?'));
61 $this->add('checkbox', 'is_counted', ts('Counted?'));
63 $this->add('text', 'weight', ts('Weight'), $attributes['weight'], TRUE);
65 $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant
::visibility(), TRUE);
68 function setDefaultValues() {
69 $defaults = parent
::setDefaultValues();
70 if (!CRM_Utils_Array
::value('weight', $defaults)) {
71 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
73 $this->_isReserved
= CRM_Utils_Array
::value('is_reserved', $defaults);
74 if ($this->_isReserved
) {
75 $this->freeze(array('name', 'class', 'is_active'));
80 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' => CRM_Utils_Array
::value('name', $formValues),
95 'label' => CRM_Utils_Array
::value('label', $formValues),
96 'class' => CRM_Utils_Array
::value('class', $formValues),
97 'is_active' => CRM_Utils_Array
::value('is_active', $formValues, FALSE),
98 'is_counted' => CRM_Utils_Array
::value('is_counted', $formValues, FALSE),
99 'weight' => CRM_Utils_Array
::value('weight', $formValues),
100 'visibility_id' => CRM_Utils_Array
::value('visibility_id', $formValues),
103 // make sure a malicious POST does not change these on reserved statuses
104 if ($this->_isReserved
)unset($params['name'], $params['class'], $params['is_active']);
106 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
108 $params['id'] = $this->_id
;
113 $oldWeight = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_ParticipantStatusType', $this->_id
, 'weight', 'id');
118 $params['weight'] = CRM_Utils_Weight
::updateOtherWeights('CRM_Event_DAO_ParticipantStatusType', $oldWeight, $params['weight']);
120 $participantStatus = CRM_Event_BAO_ParticipantStatusType
::create($params);
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');
127 CRM_Core_Session
::setStatus(ts('The new Participant Status has been saved.'), ts('Saved'), 'success');
131 CRM_Core_Session
::setStatus(ts('The changes have not been saved.'), ts('Saved'), 'success');