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
19 * This class provides the functionality to delete a group of
20 * participations. This class provides functionality for the actual
23 class CRM_Event_Form_Task_Delete
extends CRM_Event_Form_Task
{
26 * Are we operating in "single mode", i.e. deleting one
27 * specific participation?
31 protected $_single = FALSE;
34 * Build all the data structures needed to build the form.
38 public function preProcess() {
41 if (!CRM_Core_Permission
::checkActionPermission('CiviEvent', CRM_Core_Action
::DELETE
)) {
42 CRM_Core_Error
::statusBounce(ts('You do not have permission to access this page.'));
45 foreach ($this->_participantIds
as $participantId) {
46 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($participantId)) {
47 $this->assign('additionalParticipants', TRUE);
53 * Build the form object.
58 public function buildQuickForm() {
59 $deleteParticipants = [
60 1 => ts('Delete this participant record along with associated participant record(s).'),
61 2 => ts('Delete only this participant record.'),
64 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
65 $this->setDefaults(['delete_participant' => 1]);
67 $this->addDefaultButtons(ts('Delete Participations'), 'done');
71 * Process the form after the input has been submitted and validated.
76 public function postProcess() {
77 $params = $this->controller
->exportValues($this->_name
);
79 $participantLinks = NULL;
80 if (CRM_Utils_Array
::value('delete_participant', $params) == 2) {
82 foreach ($this->_participantIds
as $participantId) {
83 $additionalId = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId));
84 $participantLinks = (CRM_Event_BAO_Participant
::getAdditionalParticipantUrl($additionalId));
87 $deletedParticipants = $additionalCount = 0;
88 foreach ($this->_participantIds
as $participantId) {
89 if (CRM_Utils_Array
::value('delete_participant', $params) == 1) {
90 $primaryParticipantId = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id');
91 if (CRM_Event_BAO_Participant
::isPrimaryParticipant($participantId)) {
92 $additionalIds = (CRM_Event_BAO_Participant
::getAdditionalParticipantIds($participantId));
93 $additionalCount +
= count($additionalIds);
94 foreach ($additionalIds as $value) {
95 CRM_Event_BAO_Participant
::deleteParticipant($value);
97 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
98 $deletedParticipants++
;
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.
102 elseif (empty($primaryParticipantId) ||
(!in_array($primaryParticipantId, $this->_participantIds
))) {
103 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
104 $deletedParticipants++
;
108 CRM_Event_BAO_Participant
::deleteParticipant($participantId);
109 $deletedParticipants++
;
112 if ($additionalCount) {
113 $deletedParticipants +
= $additionalCount;
116 $status = ts('%count participant deleted.', ['plural' => '%count participants deleted.', 'count' => $deletedParticipants]);
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;
122 CRM_Core_Session
::setStatus($status, ts('Removed'), 'info');