Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
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 | /** | |
100fef9d | 52 | * Build all the data structures needed to build the form |
6a488035 TO |
53 | * |
54 | * @return void | |
6a488035 | 55 | */ |
00be9182 | 56 | public function preProcess() { |
6a488035 TO |
57 | |
58 | //check for delete | |
59 | if (!CRM_Core_Permission::checkActionPermission('CiviEvent', CRM_Core_Action::DELETE)) { | |
0499b0ad | 60 | CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); |
6a488035 TO |
61 | } |
62 | parent::preProcess(); | |
63 | foreach ($this->_participantIds as $participantId) { | |
64 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { | |
65 | $this->assign('additionalParticipants', TRUE); | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
70 | /** | |
c490a46a | 71 | * Build the form object |
6a488035 | 72 | * |
6a488035 TO |
73 | * |
74 | * @return void | |
75 | */ | |
00be9182 | 76 | public function buildQuickForm() { |
6ea503d4 TO |
77 | $deleteParticipants = array( |
78 | 1 => ts('Delete this participant record along with associated participant record(s).'), | |
6a488035 TO |
79 | 2 => ts('Delete only this participant record.'), |
80 | ); | |
81 | ||
6a488035 TO |
82 | $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); |
83 | $this->setDefaults(array('delete_participant' => 1)); | |
84 | ||
85 | $this->addDefaultButtons(ts('Delete Participations'), 'done'); | |
86 | } | |
87 | ||
88 | /** | |
100fef9d | 89 | * Process the form after the input has been submitted and validated |
6a488035 | 90 | * |
6a488035 | 91 | * |
355ba699 | 92 | * @return void |
6a488035 TO |
93 | */ |
94 | public function postProcess() { | |
95 | $params = $this->controller->exportValues($this->_name); | |
96 | ||
97 | if (CRM_Utils_Array::value('delete_participant', $params) == 2) { | |
98 | $links = array(); | |
99 | foreach ($this->_participantIds as $participantId) { | |
100 | $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); | |
101 | $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId)); | |
102 | } | |
103 | } | |
104 | $deletedParticipants = $additionalCount = 0; | |
105 | foreach ($this->_participantIds as $participantId) { | |
106 | if (CRM_Utils_Array::value('delete_participant', $params) == 1) { | |
107 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { | |
108 | $additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); | |
109 | $additionalCount = count($additionalIds); | |
110 | foreach ($additionalIds as $value) { | |
111 | CRM_Event_BAO_Participant::deleteParticipant($value); | |
112 | } | |
113 | CRM_Event_BAO_Participant::deleteParticipant($participantId); | |
114 | } | |
115 | $deletedParticipants++; | |
116 | } | |
117 | else { | |
118 | CRM_Event_BAO_Participant::deleteParticipant($participantId); | |
119 | $deletedParticipants++; | |
120 | } | |
121 | } | |
122 | if ($additionalCount) { | |
123 | $deletedParticipants += $additionalCount; | |
124 | } | |
125 | ||
353ffa53 TO |
126 | $status = array( |
127 | ts('Participant(s) Deleted: %1 (Total Selected: %2)', array( | |
128 | 1 => $deletedParticipants, | |
317fceb4 | 129 | 2 => count($this->_participantIds), |
130 | )), | |
353ffa53 | 131 | ); |
6a488035 | 132 | if (!empty($participantLinks)) { |
d3e86119 | 133 | $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; |
6a488035 | 134 | } |
0bc90828 KM |
135 | foreach ($status as $text) { |
136 | CRM_Core_Session::setStatus($text, '', 'info'); | |
137 | } | |
6a488035 TO |
138 | } |
139 | } |