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