Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class provides the functionality to delete a group of | |
22 | * participations. This class provides functionality for the actual | |
23 | * deletion. | |
24 | */ | |
25 | class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task { | |
26 | ||
27 | /** | |
28 | * Are we operating in "single mode", i.e. deleting one | |
29 | * specific participation? | |
30 | * | |
d51c6add | 31 | * @var bool |
6a488035 TO |
32 | */ |
33 | protected $_single = FALSE; | |
34 | ||
35 | /** | |
eceb18cc | 36 | * Build all the data structures needed to build the form. |
6a488035 TO |
37 | * |
38 | * @return void | |
6a488035 | 39 | */ |
00be9182 | 40 | public function preProcess() { |
6a488035 TO |
41 | |
42 | //check for delete | |
43 | if (!CRM_Core_Permission::checkActionPermission('CiviEvent', CRM_Core_Action::DELETE)) { | |
beb414cc | 44 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); |
6a488035 TO |
45 | } |
46 | parent::preProcess(); | |
47 | foreach ($this->_participantIds as $participantId) { | |
48 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { | |
49 | $this->assign('additionalParticipants', TRUE); | |
50 | } | |
51 | } | |
52 | } | |
53 | ||
54 | /** | |
eceb18cc | 55 | * Build the form object. |
6a488035 | 56 | * |
6a488035 TO |
57 | * |
58 | * @return void | |
59 | */ | |
00be9182 | 60 | public function buildQuickForm() { |
be2fb01f | 61 | $deleteParticipants = [ |
6ea503d4 | 62 | 1 => ts('Delete this participant record along with associated participant record(s).'), |
6a488035 | 63 | 2 => ts('Delete only this participant record.'), |
be2fb01f | 64 | ]; |
6a488035 | 65 | |
6a488035 | 66 | $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />'); |
be2fb01f | 67 | $this->setDefaults(['delete_participant' => 1]); |
6a488035 TO |
68 | |
69 | $this->addDefaultButtons(ts('Delete Participations'), 'done'); | |
70 | } | |
71 | ||
72 | /** | |
eceb18cc | 73 | * Process the form after the input has been submitted and validated. |
6a488035 | 74 | * |
6a488035 | 75 | * |
355ba699 | 76 | * @return void |
6a488035 TO |
77 | */ |
78 | public function postProcess() { | |
79 | $params = $this->controller->exportValues($this->_name); | |
80 | ||
1e6547ff | 81 | $participantLinks = NULL; |
6a488035 | 82 | if (CRM_Utils_Array::value('delete_participant', $params) == 2) { |
be2fb01f | 83 | $links = []; |
6a488035 TO |
84 | foreach ($this->_participantIds as $participantId) { |
85 | $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); | |
86 | $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId)); | |
87 | } | |
88 | } | |
89 | $deletedParticipants = $additionalCount = 0; | |
90 | foreach ($this->_participantIds as $participantId) { | |
91 | if (CRM_Utils_Array::value('delete_participant', $params) == 1) { | |
1e6547ff | 92 | $primaryParticipantId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id'); |
6a488035 TO |
93 | if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { |
94 | $additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); | |
1e6547ff | 95 | $additionalCount += count($additionalIds); |
6a488035 TO |
96 | foreach ($additionalIds as $value) { |
97 | CRM_Event_BAO_Participant::deleteParticipant($value); | |
98 | } | |
99 | CRM_Event_BAO_Participant::deleteParticipant($participantId); | |
1e6547ff | 100 | $deletedParticipants++; |
101 | } | |
102 | // delete participant only if it is not an additional participant | |
103 | // or if it is additional and its primary participant is not selected in $this->_participantIds. | |
d931a208 | 104 | elseif (empty($primaryParticipantId) || (!in_array($primaryParticipantId, $this->_participantIds))) { |
1e6547ff | 105 | CRM_Event_BAO_Participant::deleteParticipant($participantId); |
106 | $deletedParticipants++; | |
6a488035 | 107 | } |
6a488035 TO |
108 | } |
109 | else { | |
110 | CRM_Event_BAO_Participant::deleteParticipant($participantId); | |
111 | $deletedParticipants++; | |
112 | } | |
113 | } | |
114 | if ($additionalCount) { | |
115 | $deletedParticipants += $additionalCount; | |
116 | } | |
117 | ||
be2fb01f | 118 | $status = ts('%count participant deleted.', ['plural' => '%count participants deleted.', 'count' => $deletedParticipants]); |
99483ce8 CW |
119 | |
120 | if ($participantLinks) { | |
121 | $status .= '<p>' . 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:') | |
122 | . '</p>' . $participantLinks; | |
0bc90828 | 123 | } |
99483ce8 | 124 | CRM_Core_Session::setStatus($status, ts('Removed'), 'info'); |
6a488035 | 125 | } |
96025800 | 126 | |
6a488035 | 127 | } |