3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class provides the functionality to delete a group of
22 * participations. This class provides functionality for the actual
25 class CRM_Event_Form_Task_Delete
extends CRM_Event_Form_Task
{
28 * Are we operating in "single mode", i.e. deleting one
29 * specific participation?
33 protected $_single = FALSE;
36 * Build all the data structures needed to build the form.
40 public function preProcess() {
43 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', CRM_Core_Action
::DELETE
)) {
44 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
47 foreach ($this->_participantIds
as $participantId) {
48 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($participantId)) {
49 $this->assign('additionalParticipants', TRUE);
55 * Build the form object.
60 public function buildQuickForm() {
61 $deleteParticipants = [
62 1 => ts('Delete this participant record along with associated participant record(s).'),
63 2 => ts('Delete only this participant record.'),
66 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
67 $this->setDefaults(['delete_participant' => 1]);
69 $this->addDefaultButtons(ts('Delete Participations'), 'done');
73 * Process the form after the input has been submitted and validated.
78 public function postProcess() {
79 $params = $this->controller
->exportValues($this->_name
);
81 $participantLinks = NULL;
82 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
84 foreach ($this->_participantIds
as $participantId) {
85 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId));
86 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
89 $deletedParticipants = $additionalCount = 0;
90 foreach ($this->_participantIds
as $participantId) {
91 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
92 $primaryParticipantId = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id');
93 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($participantId)) {
94 $additionalIds = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId));
95 $additionalCount +
= count($additionalIds);
96 foreach ($additionalIds as $value) {
97 CRM_Event_BAO_Participant
::deleteParticipant($value);
99 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
100 $deletedParticipants++
;
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.
104 elseif (empty($primaryParticipantId) ||
(!in_array($primaryParticipantId, $this->_participantIds
))) {
105 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
106 $deletedParticipants++
;
110 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
111 $deletedParticipants++
;
114 if ($additionalCount) {
115 $deletedParticipants +
= $additionalCount;
118 $status = ts('%count participant deleted.', ['plural' => '%count participants deleted.', 'count' => $deletedParticipants]);
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;
124 CRM_Core_Session
::setStatus($status, ts('Removed'), 'info');