From 9056a6e9260021ba8a0ca70e9f7a23dc89a87f2a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 15 Sep 2023 13:34:10 +1200 Subject: [PATCH] Fix notices when deleting participants --- CRM/Event/Form/Task/Delete.php | 33 ++++++++++++------------ templates/CRM/Event/Form/Task/Delete.tpl | 4 +-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CRM/Event/Form/Task/Delete.php b/CRM/Event/Form/Task/Delete.php index daac5af98b..4e261750ac 100644 --- a/CRM/Event/Form/Task/Delete.php +++ b/CRM/Event/Form/Task/Delete.php @@ -35,18 +35,13 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task { * * @return void */ - public function preProcess() { + public function preProcess(): void { //check for delete if (!CRM_Core_Permission::checkActionPermission('CiviEvent', CRM_Core_Action::DELETE)) { CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.')); } parent::preProcess(); - foreach ($this->_participantIds as $participantId) { - if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { - $this->assign('additionalParticipants', TRUE); - } - } } /** @@ -55,14 +50,17 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task { * * @return void */ - public function buildQuickForm() { - $deleteParticipants = [ - 1 => ts('Delete this participant record along with associated participant record(s).'), - 2 => ts('Delete only this participant record.'), - ]; - - $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '
'); - $this->setDefaults(['delete_participant' => 1]); + public function buildQuickForm(): void { + foreach ($this->_participantIds as $participantId) { + if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { + $this->addRadio('delete_participant', NULL, [ + 1 => ts('Delete this participant record along with associated participant record(s).'), + 2 => ts('Delete only this participant record.'), + ], NULL, '
'); + $this->setDefaults(['delete_participant' => 1]); + break; + } + } $this->addDefaultButtons(ts('Delete Participations'), 'done'); } @@ -72,13 +70,14 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task { * * * @return void + * @throws \CRM_Core_Exception + * @throws \Civi\Core\Exception\DBQueryException */ - public function postProcess() { + public function postProcess(): void { $params = $this->controller->exportValues($this->_name); $participantLinks = NULL; if (($params['delete_participant'] ?? NULL) == 2) { - $links = []; foreach ($this->_participantIds as $participantId) { $additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); $participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId)); @@ -87,7 +86,7 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task { $deletedParticipants = $additionalCount = 0; foreach ($this->_participantIds as $participantId) { if (($params['delete_participant'] ?? NULL) == 1) { - $primaryParticipantId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id'); + $primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'registered_by_id', 'id'); if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) { $additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId)); $additionalCount += count($additionalIds); diff --git a/templates/CRM/Event/Form/Task/Delete.tpl b/templates/CRM/Event/Form/Task/Delete.tpl index b99fa017ee..be7ddbd8d1 100644 --- a/templates/CRM/Event/Form/Task/Delete.tpl +++ b/templates/CRM/Event/Form/Task/Delete.tpl @@ -13,10 +13,10 @@ {icon icon="fa-info-circle"}{/icon}

{ts}Are you sure you want to delete the selected participations? This delete operation cannot be undone and will delete all transactions and activity associated with these participations.{/ts}

-

{include file="CRM/Event/Form/Task.tpl"}

+

{ts 1=$totalSelectedParticipants}Number of selected participants: %1{/ts}

-{if $additionalParticipants} +{if array_key_exists('delete_participant', $form)} {$form.delete_participant.html} {/if}

-- 2.25.1