Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Event / Form / Task / Delete.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class provides the functionality to delete a group of
38 * participations. This class provides functionality for the actual
39 * deletion.
40 */
41 class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task {
42
43 /**
44 * Are we operating in "single mode", i.e. deleting one
45 * specific participation?
46 *
47 * @var boolean
48 */
49 protected $_single = FALSE;
50
51 /**
52 * build all the data structures needed to build the form
53 *
54 * @return void
55 * @access public
56 */
57 function preProcess() {
58
59 //check for delete
60 if (!CRM_Core_Permission::checkActionPermission('CiviEvent', CRM_Core_Action::DELETE)) {
61 CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
62 }
63 parent::preProcess();
64 foreach ($this->_participantIds as $participantId) {
65 if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) {
66 $this->assign('additionalParticipants', TRUE);
67 }
68 }
69 }
70
71 /**
72 * Build the form
73 *
74 * @access public
75 *
76 * @return void
77 */
78 function buildQuickForm() {
79 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'),
80 2 => ts('Delete only this participant record.'),
81 );
82
83
84 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
85 $this->setDefaults(array('delete_participant' => 1));
86
87 $this->addDefaultButtons(ts('Delete Participations'), 'done');
88 }
89
90 /**
91 * process the form after the input has been submitted and validated
92 *
93 * @access public
94 *
95 * @return None
96 */
97 public function postProcess() {
98 $params = $this->controller->exportValues($this->_name);
99
100 if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
101 $links = array();
102 foreach ($this->_participantIds as $participantId) {
103 $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId));
104 $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId));
105 }
106 }
107 $deletedParticipants = $additionalCount = 0;
108 foreach ($this->_participantIds as $participantId) {
109 if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
110 if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) {
111 $additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId));
112 $additionalCount = count($additionalIds);
113 foreach ($additionalIds as $value) {
114 CRM_Event_BAO_Participant::deleteParticipant($value);
115 }
116 CRM_Event_BAO_Participant::deleteParticipant($participantId);
117 }
118 $deletedParticipants++;
119 }
120 else {
121 CRM_Event_BAO_Participant::deleteParticipant($participantId);
122 $deletedParticipants++;
123 }
124 }
125 if ($additionalCount) {
126 $deletedParticipants += $additionalCount;
127 }
128
129 $status = array(
130 ts('Participant(s) Deleted: %1', array(1 => $deletedParticipants)),
131 ts('Total Selected Participant(s): %1', array(1 => $deletedParticipants)),
132 );
133
134
135 if (!empty($participantLinks)) {
136 $status[] = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br>' . $participantLinks;
137 }
138 CRM_Core_Session::setStatus($status);
139 }
140 }
141