-
-
Notifications
You must be signed in to change notification settings - Fork 827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separate delete participant form from edit participant form #27660
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
107aace
Separate delete participant form from edit participant form
eileenmcnaughton e03ee8d
Simplify check for additional participants
eileenmcnaughton 2f54650
Fix title - note the setTitle applies purify
eileenmcnaughton 46a4b37
Run gencode
eileenmcnaughton 9dd2654
Fix delete from view participant
eileenmcnaughton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?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 | ||
*/ | ||
|
||
/** | ||
* Back office participant delete form. | ||
*/ | ||
class CRM_Event_Form_Participant_Delete extends CRM_Contribute_Form_AbstractEditPayment { | ||
use CRM_Event_Form_EventFormTrait; | ||
use CRM_Contact_Form_ContactFormTrait; | ||
|
||
/** | ||
* @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); | ||
$this->setTitle(ts('Delete participant record for %1', [1 => $this->getContactValue('display_name')])); | ||
$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 = (int) CRM_Core_DAO::singleValueQuery( | ||
'SELECT count(*) FROM civicrm_participant WHERE registered_by_id = %1 AND id <> registered_by_id', | ||
[1 => [$this->getParticipantID(), 'Integer']] | ||
); | ||
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' => ' ', | ||
'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')); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the if can go later - but getting that right in tpls can be error prone so didn't want to do it here