From 75d48d7bcef83f408b99e5c28e77d6090270efdd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 12 May 2023 16:40:22 +1200 Subject: [PATCH] Further separate register task from participant form --- CRM/Event/Form/Participant.php | 40 +------------------------- CRM/Event/Form/Task/Register.php | 48 +++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index cfd7a5b2c2..8511eb1d00 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -895,50 +895,12 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment } return; } - // When adding a single contact, the formRule prevents you from adding duplicates - // (See above in formRule()). When adding more than one contact, the duplicates are - // removed automatically and the user receives one notification. - if ($this->_action & CRM_Core_Action::ADD) { - $event_id = $this->_eventId; - if (empty($event_id) && !empty($params['event_id'])) { - $event_id = $params['event_id']; - } - if (!$this->_single && !empty($event_id)) { - $duplicateContacts = 0; - foreach ($this->_contactIds as $k => $dupeCheckContactId) { - // Eliminate contacts that have already been assigned to this event. - $dupeCheck = new CRM_Event_BAO_Participant(); - $dupeCheck->contact_id = $dupeCheckContactId; - $dupeCheck->event_id = $event_id; - $dupeCheck->find(TRUE); - if (!empty($dupeCheck->id)) { - $duplicateContacts++; - unset($this->_contactIds[$k]); - } - } - if ($duplicateContacts > 0) { - $msg = ts( - "%1 contacts have already been assigned to this event. They were not added a second time.", - [1 => $duplicateContacts] - ); - CRM_Core_Session::setStatus($msg); - } - if (count($this->_contactIds) == 0) { - CRM_Core_Session::setStatus(ts("No participants were added.")); - return; - } - // We have to re-key $this->_contactIds so each contact has the same - // key as their corresponding record in the $participants array that - // will be created below. - $this->_contactIds = array_values($this->_contactIds); - } - } $statusMsg = $this->submit($params); CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); $session = CRM_Core_Session::singleton(); $buttonName = $this->controller->getButtonName(); - if ($this->_context == 'standalone') { + if ($this->_context === 'standalone') { if ($buttonName == $this->getButtonName('upload', 'new')) { $urlParams = 'reset=1&action=add&context=standalone'; if ($this->_mode) { diff --git a/CRM/Event/Form/Task/Register.php b/CRM/Event/Form/Task/Register.php index 6bdcb8ae20..38df66c7ea 100644 --- a/CRM/Event/Form/Task/Register.php +++ b/CRM/Event/Form/Task/Register.php @@ -25,7 +25,6 @@ */ class CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant { - /** * Are we operating in "single mode", i.e. adding / editing only * one participant record, or is this a batch add operation @@ -79,4 +78,51 @@ class CRM_Event_Form_Task_Register extends CRM_Event_Form_Participant { $this->assign('urlPathVar', "_qf_Participant_display=true&context=search"); } + /** + * Process the form submission. + * + * @throws \CRM_Core_Exception + */ + public function postProcess(): void { + $params = $this->controller->exportValues($this->_name); + // When adding more than one contact, the duplicates are + // removed automatically and the user receives one notification. + $event_id = $this->_eventId; + if (!$event_id && !empty($params['event_id'])) { + $event_id = $params['event_id']; + } + if (!empty($event_id)) { + $duplicateContacts = 0; + foreach ($this->_contactIds as $k => $dupeCheckContactId) { + // Eliminate contacts that have already been assigned to this event. + $dupeCheck = new CRM_Event_BAO_Participant(); + $dupeCheck->contact_id = $dupeCheckContactId; + $dupeCheck->event_id = $event_id; + $dupeCheck->find(TRUE); + if (!empty($dupeCheck->id)) { + $duplicateContacts++; + unset($this->_contactIds[$k]); + } + } + if ($duplicateContacts > 0) { + $msg = ts( + '%1 contacts have already been assigned to this event. They were not added a second time.', + [1 => $duplicateContacts] + ); + CRM_Core_Session::setStatus($msg); + } + if (count($this->_contactIds) === 0) { + CRM_Core_Session::setStatus(ts('No participants were added.')); + return; + } + // We have to re-key $this->_contactIds so each contact has the same + // key as their corresponding record in the $participants array that + // will be created below. + $this->_contactIds = array_values($this->_contactIds); + } + + $statusMsg = $this->submit($params); + CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); + } + } -- 2.25.1