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