Skip to content

Commit

Permalink
Separate delete participant form from edit participant form
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Sep 27, 2023
1 parent 3548e4b commit 5595b54
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 107 deletions.
4 changes: 2 additions & 2 deletions CRM/Event/BAO/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ public static function create(&$params) {
);
}
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
"action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/participant/delete',
"reset=1&id={$participant->id}"
);
}

Expand Down
76 changes: 5 additions & 71 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@ public function preProcess() {
CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
}

if ($this->_action & CRM_Core_Action::DELETE) {
// check delete permission for contribution
if ($this->_id && $this->_paymentId && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
CRM_Core_Error::statusBounce(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
}
return;
}

// when fee amount is included in form
if (!empty($_POST['hidden_feeblock']) || !empty($_POST['send_receipt'])) {
if ($this->_submitValues['event_id']) {
Expand Down Expand Up @@ -398,10 +390,6 @@ public function setDefaultValues(): array {

$defaults = [];

if ($this->_action & CRM_Core_Action::DELETE) {
return $defaults;
}

if ($this->_id) {
$ids = [];
$params = ['id' => $this->_id];
Expand Down Expand Up @@ -561,39 +549,6 @@ public function buildQuickForm() {

$this->applyFilter('__ALL__', 'trim');

if ($this->_action & CRM_Core_Action::DELETE) {
if ($this->_single) {
$additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id,
NULL,
$this->_contactId,
FALSE,
TRUE
)) - 1;
if ($additionalParticipant) {
$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, '<br />');
$this->setDefaults(['delete_participant' => 1]);
}
$this->assign('additionalParticipant', $additionalParticipant);
}
$this->addButtons([
[
'type' => 'next',
'name' => ts('Delete'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
return;
}

if ($this->_single) {
$contactField = $this->addEntityRef('contact_id', ts('Participant'), ['create' => TRUE, 'api' => ['extra' => ['email']]], TRUE);
if ($this->_context !== 'standalone') {
Expand Down Expand Up @@ -754,13 +709,12 @@ public function addRules(): void {
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $self) {
// If $values['_qf_Participant_next'] is Delete or
// $values['event_id'] is empty, then return
// instead of proceeding further.

if ((($values['_qf_Participant_next'] ?? NULL) === 'Delete') ||
empty($values['event_id'])
) {
// instead of proceeding further - this is legacy handling
// and it is unclear why but perhaps relates to the form's
// 'multitasking' & can go once the form is not overloaded?
// event_id is normally a required field..
if (empty($values['event_id'])) {
return TRUE;
}

Expand Down Expand Up @@ -833,26 +787,6 @@ public function postProcess() {
// get the submitted form values.
$params = $this->controller->exportValues($this->_name);

if ($this->_action & CRM_Core_Action::DELETE) {
if (($params['delete_participant'] ?? NULL) == 2) {
$additionalId = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id));
$participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId));
}
if (($params['delete_participant'] ?? NULL) == 1) {
$additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
foreach ($additionalIds as $value) {
CRM_Event_BAO_Participant::deleteParticipant($value);
}
}
CRM_Event_BAO_Participant::deleteParticipant($this->_id);
CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
if (!empty($participantLinks)) {
$status = 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:') . '<br/>' . $participantLinks;
CRM_Core_Session::setStatus($status, ts('Group Payment Deleted'));
}
return;
}

$statusMsg = $this->submit($params);
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
$session = CRM_Core_Session::singleton();
Expand Down
160 changes: 160 additions & 0 deletions CRM/Event/Form/Participant/Delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Back office participant form.
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\API\EntityLookupTrait;

/**
* Back office participant delete form.
*/
class CRM_Event_Form_Participant_Delete extends CRM_Contribute_Form_AbstractEditPayment {
use CRM_Event_Form_EventFormTrait;

/**
* @var int
*/
private $participantID;

/**
* Get id of participant being edited.
*
* @return int|null
*
* @api This function will not change in a minor release and is supported for
* use outside of core. This annotation / external support for properties
* is only given where there is specific test cover.
*
* No exception is thrown as abort is not TRUE.
* @noinspection PhpUnhandledExceptionInspection
* @noinspection PhpDocMissingThrowsInspection
*/
public function getParticipantID(): ?int {
if ($this->participantID === NULL) {
$id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->participantID = $id ? (int) $id : FALSE;
}
return $this->participantID ?: NULL;
}

/**
* Get the selected Event ID.
*
* @return int|null
*
* @api This function will not change in a minor release and is supported for
* use outside of core. This annotation / external support for properties
* is only given where there is specific test cover.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
public function getEventID(): ?int {
return $this->getParticipantValue('event_id');
}

/**
* Get the relevant contact ID.
*
* @return int|null
*
* @api This function will not change in a minor release and is supported for
* use outside of core. This annotation / external support for properties
* is only given where there is specific test cover.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/
public function getContactID(): ?int {
return $this->getParticipantValue('contact_id');
}

/**
* Set variables up before form is built.
*
* @throws \CRM_Core_Exception
*/
public function preProcess(): void {
$this->setAction(CRM_Core_Action::DELETE);
$contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
$this->getParticipantID(), 'contribution_id', 'participant_id'
);
if ($contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
CRM_Core_Error::statusBounce(ts("This Participant is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
}
}

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm(): void {
$additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->getParticipantID(),
NULL,
$this->getParticipantValue('contact_id'),
FALSE,
TRUE
)) - 1;
if ($additionalParticipant) {
$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, '<br />');
$this->setDefaults(['delete_participant' => 1]);
}
$this->assign('additionalParticipant', $additionalParticipant);
$this->addButtons([
[
'type' => 'next',
'name' => ts('Delete'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}

/**
* Process the form submission.
*
* @throws \Civi\Core\Exception\DBQueryException
*/
public function postProcess(): void {
$deleteParticipantOption = (int) $this->getSubmittedValue('delete_participant');
if ($deleteParticipantOption === 2) {
$additionalID = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->getParticipantID()));
$participantLinks = (CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalID));
}
if ($deleteParticipantOption === 1) {
$additionalIDs = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->getParticipantID());
foreach ($additionalIDs as $value) {
CRM_Event_BAO_Participant::deleteParticipant($value);
}
}
CRM_Event_BAO_Participant::deleteParticipant($this->getParticipantID());
CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
if (!empty($participantLinks)) {
$status = 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:') . '<br/>' . $participantLinks;
CRM_Core_Session::setStatus($status, ts('Group Payment Deleted'));
}
}

}
4 changes: 2 additions & 2 deletions CRM/Event/Form/ParticipantView.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ public function preProcess() {
);
}
if (CRM_Core_Permission::check('delete in CiviEvent')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/participant',
"action=delete&reset=1&id={$values[$participantID]['id']}&cid={$values[$participantID]['contact_id']}&context=home"
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/participant/delete',
"reset=1&id={$values[$participantID]['id']}}"
);
}

Expand Down
11 changes: 1 addition & 10 deletions CRM/Event/Page/Tab.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,7 @@ public function edit() {
}

public function delete() {
$controller = new CRM_Core_Controller_Simple(
'CRM_Event_Form_Participant',
ts('Delete Participant'),
$this->_action
);

$controller->setEmbedded(TRUE);
$controller->set('id', $this->_id);
$controller->set('cid', $this->_contactId);
$controller->run();
CRM_Core_Error::deprecatedFunctionWarning('use civicrm/participant/delete / CRM_Event_Form_Participant_Delete');
}

public function preProcess() {
Expand Down
6 changes: 3 additions & 3 deletions CRM/Event/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function &links($qfKey = NULL, $context = NULL, $compContext = NUL
if ($compContext) {
$extraParams .= "&compContext={$compContext}";
}
elseif ($context == 'search') {
elseif ($context === 'search') {
$extraParams .= '&compContext=participant';
}

Expand All @@ -226,8 +226,8 @@ public static function &links($qfKey = NULL, $context = NULL, $compContext = NUL
],
CRM_Core_Action::DELETE => [
'name' => ts('Delete'),
'url' => 'civicrm/contact/view/participant',
'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
'url' => 'civicrm/participant/delete',
'qs' => 'reset=1&id=%%id%%' . $extraParams,
'title' => ts('Delete Participation'),
'weight' => 100,
],
Expand Down
6 changes: 6 additions & 0 deletions CRM/Event/xml/Menu/Event.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@
<page_callback>CRM_Event_Page_Tab</page_callback>
<weight>4</weight>
</item>
<item>
<path>civicrm/participant/delete</path>
<page_callback>CRM_Event_Form_Participant_Delete</page_callback>
<access_arguments>delete in CiviEvent</access_arguments>
<weight>4</weight>
</item>
<item>
<path>civicrm/ajax/eventFee</path>
<page_callback>CRM_Event_Page_AJAX::eventFee</page_callback>
Expand Down
19 changes: 2 additions & 17 deletions templates/CRM/Event/Form/Participant.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{* This template is used for adding/editing/deleting offline Event Registrations *}
{* This template is used for adding/editing offline Event Registrations *}

{* Ajax callback for showing event fee snippet - to be moved to separate form *}
{if $showFeeBlock}
Expand All @@ -33,22 +33,7 @@
{/if}
<div id="eventFullMsg" class="messages status no-popup" style="display:none;"></div>

{if $action eq 8} {* If action is Delete *}
<div class="crm-participant-form-block-delete messages status no-popup">
<div class="crm-content">
{icon icon="fa-info-circle"}{/icon}
{ts}WARNING: Deleting this registration will result in the loss of related payment records (if any).{/ts} {ts}Do you want to continue?{/ts}
</div>
{if $additionalParticipant}
<div class="crm-content">
{ts 1=$additionalParticipant} There are %1 more Participant(s) registered by this participant.{/ts}
</div>
{/if}
</div>
{if $additionalParticipant}
{$form.delete_participant.html}
{/if}
{else} {* If action is other than Delete *}
{if 1} {* If action is other than Delete *}
<table class="form-layout-compressed">
{if $context EQ 'standalone' OR $context EQ 'participant' OR $action EQ 2}
<tr class="crm-participant-form-contact-id">
Expand Down
Loading

0 comments on commit 5595b54

Please sign in to comment.