From e219d53b6b5ccad66a6d6234f9e1cd86d0d25de8 Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Wed, 19 Jul 2017 00:55:20 +0530 Subject: [PATCH] CRM-20879: Extend self-service event registration transfer to backend --- CRM/Event/Form/ParticipantView.php | 17 +++++++ CRM/Event/Form/SelfSvcTransfer.php | 51 +++++++++++++++----- CRM/Event/Form/SelfSvcUpdate.php | 31 +++++++++--- CRM/Event/Selector/Search.php | 14 ++++++ templates/CRM/Event/Form/ParticipantView.tpl | 3 ++ templates/CRM/Event/Form/SelfSvcTransfer.tpl | 42 ++++++++++------ 6 files changed, 123 insertions(+), 35 deletions(-) diff --git a/CRM/Event/Form/ParticipantView.php b/CRM/Event/Form/ParticipantView.php index 1d07f03e59..6ad31e9c9f 100644 --- a/CRM/Event/Form/ParticipantView.php +++ b/CRM/Event/Form/ParticipantView.php @@ -100,6 +100,23 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form { } $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); + // CRM-20879: Show 'Transfer or Cancel' option beside 'Change fee selection' + // only if logged in user have 'edit event participants' permission and + // participant status is not Cancelled or Transferred + if (CRM_Core_Permission::check('edit event participants') && !in_array($status, array('Cancelled', 'Transferred'))) { + $this->assign('transferOrCancelLink', + CRM_Utils_System::url( + 'civicrm/event/selfsvcupdate', + array( + 'reset' => 1, + 'is_backoffice' => 1, + 'pid' => $participantID, + 'cs' => CRM_Contact_BAO_Contact_Utils::generateChecksum($contactID, NULL, 'inf'), + ) + ) + ); + } + if ($values[$participantID]['is_test']) { $values[$participantID]['status'] .= ' (test) '; } diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index 1944a449a0..7452ccb246 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -135,6 +135,13 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { */ protected $contact_id; + /** + * Is backoffice form? + * + * @array bool + */ + protected $isBackoffice = FALSE; + /** * Get source values for transfer based on participant id in URL. Line items will * be transferred to this participant - at this point no transaction changes processed @@ -147,6 +154,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { $this->_userContext = $session->readUserContext(); $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); + $this->isBackoffice = CRM_Utils_Request::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST'); $params = array('id' => $this->_from_participant_id); $participant = $values = array(); $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); @@ -204,9 +212,17 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { * return @void */ public function buildQuickForm() { - $this->add('text', 'email', ts('To Email'), ts($this->_contact_email), TRUE); - $this->add('text', 'last_name', ts('To Last Name'), ts($this->_to_contact_last_name), TRUE); - $this->add('text', 'first_name', ts('To First Name'), ts($this->_to_contact_first_name), TRUE); + // use entityRef select field for contact when this form is used by staff/admin user + if ($this->isBackoffice) { + $this->addEntityRef("contact_id", ts('Select Contact'), array('create' => TRUE), TRUE); + } + // for front-end user show and use the basic three fields used to create a contact + else { + $this->add('text', 'email', ts('To Email'), ts($this->_contact_email), TRUE); + $this->add('text', 'last_name', ts('To Last Name'), ts($this->_to_contact_last_name), TRUE); + $this->add('text', 'first_name', ts('To First Name'), ts($this->_to_contact_first_name), TRUE); + } + $this->addButtons(array( array( 'type' => 'submit', @@ -234,10 +250,15 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { */ public static function formRule($fields, $files, $self) { $errors = array(); - //check that either an email or firstname+lastname is included in the form(CRM-9587) - $to_contact_id = self::checkProfileComplete($fields, $errors, $self); + if (!empty($fields['contact_id'])) { + $to_contact_id = $fields['contact_id']; + } + else { + //check that either an email or firstname+lastname is included in the form(CRM-9587) + $to_contact_id = self::checkProfileComplete($fields, $errors, $self); + } //To check if the user is already registered for the event(CRM-2426) - if ($to_contact_id) { + if (!empty($to_contact_id)) { self::checkRegistration($fields, $self, $to_contact_id, $errors); } //return parent::formrule($fields, $files, $self); @@ -311,11 +332,16 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { public function postProcess() { //For transfer, process form to allow selection of transferree $params = $this->controller->exportValues($this->_name); - //cancel 'from' participant row - $query = "select contact_id from civicrm_email where email = '" . $params['email'] . "'"; - $dao = CRM_Core_DAO::executeQuery($query); - while ($dao->fetch()) { - $contact_id = $dao->contact_id; + if (!empty($params['contact_id'])) { + $contact_id = $params['contact_id']; + } + else { + //cancel 'from' participant row + $query = "select contact_id from civicrm_email where email = '" . $params['email'] . "'"; + $dao = CRM_Core_DAO::executeQuery($query); + while ($dao->fetch()) { + $contact_id = $dao->contact_id; + } } $from_participant = $params = array(); $query = "select role_id, source, fee_level, is_test, is_pay_later, fee_amount, discount_id, fee_currency,campaign_id, discount_amount from civicrm_participant where id = " . $this->_from_participant_id; @@ -364,6 +390,9 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $displayName)); $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $email)); CRM_Core_Session::setStatus($statusMsg, ts('Registration Transferred'), 'success'); + if ($this->isBackoffice) { + return; + } $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}"); CRM_Utils_System::redirect($url); } diff --git a/CRM/Event/Form/SelfSvcUpdate.php b/CRM/Event/Form/SelfSvcUpdate.php index fe7705f844..cb42b301a0 100644 --- a/CRM/Event/Form/SelfSvcUpdate.php +++ b/CRM/Event/Form/SelfSvcUpdate.php @@ -107,6 +107,12 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { * @var array */ protected $_details = array(); + /** + * Is backoffice form? + * + * @array bool + */ + protected $isBackoffice = FALSE; /** * Set variables up before form is built based on participant ID from URL * @@ -119,6 +125,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $participant = $values = array(); $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); $this->_userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this, FALSE, NULL, 'REQUEST'); + $this->isBackoffice = CRM_Utils_Request::retrieve('is_backoffice', 'String', $this, FALSE, NULL, 'REQUEST'); $params = array('id' => $this->_participant_id); $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant); $this->_part_values = $values[$this->_participant_id]; @@ -159,7 +166,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { while ($dao->fetch()) { $details['status'] = $dao->status; $details['role'] = $dao->role; - $details['fee_level'] = $dao->fee_level; + $details['fee_level'] = trim($dao->fee_level, CRM_Core_DAO::VALUE_SEPARATOR); $details['fee_amount'] = $dao->fee_amount; $details['register_date'] = $dao->register_date; $details['event_start_date'] = $dao->start_date; @@ -178,11 +185,11 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { } $start_time = new Datetime($start_date); $timenow = new Datetime(); - if (!empty($start_time) && $start_time < $timenow) { + if (!$this->isBackoffice && !empty($start_time) && $start_time < $timenow) { $status = ts("Registration for this event cannot be cancelled or transferred once the event has begun. Contact the event organizer if you have questions."); CRM_Core_Error::statusBounce($status, $url, ts('Sorry')); } - if (!empty($time_limit) && $time_limit > 0) { + if (!$this->isBackoffice && !empty($time_limit) && $time_limit > 0) { $interval = $timenow->diff($start_time); $days = $interval->format('%d'); $hours = $interval->format('%h'); @@ -274,11 +281,16 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { * return @void */ public function transferParticipant($params) { - $transferUrl = 'civicrm/event/form/selfsvctransfer'; - $url = CRM_Utils_System::url('civicrm/event/selfsvctransfer', 'reset=1&action=add&pid=' . $this->_participant_id . '&cs=' . $this->_userChecksum); - $this->controller->setDestination($url); - $session = CRM_Core_Session::singleton(); - $session->replaceUserContext($url); + $isBackOfficeArg = $this->isBackoffice ? '&is_backoffice=1' : ''; + CRM_Utils_System::redirect(CRM_Utils_System::url( + 'civicrm/event/selfsvctransfer', + array( + 'reset' => 1, + 'action' => 'add', + 'pid' => $this->_participant_id, + 'cs' => $this->_userChecksum, + ) + )); } /** @@ -358,6 +370,9 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name)); $statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email)); CRM_Core_Session::setStatus($statusMsg, ts('Thanks'), 'success'); + if (!empty($this->isBackoffice)) { + return; + } $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true"); CRM_Utils_System::redirect($url); } diff --git a/CRM/Event/Selector/Search.php b/CRM/Event/Selector/Search.php index 2fbb27e898..aae625b240 100644 --- a/CRM/Event/Selector/Search.php +++ b/CRM/Event/Selector/Search.php @@ -395,6 +395,20 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co ); } + // CRM-20879: Show 'Transfer or Cancel' action only if logged in user + // have 'edit event participants' permission and participant status + // is not Cancelled or Transferred + if (in_array(CRM_Core_Permission::EDIT, $permissions) && + !in_array($statusTypes[$row['participant_status_id']], array('Cancelled', 'Transferred')) + ) { + $links[] = array( + 'name' => ts('Transfer or Cancel'), + 'url' => 'civicrm/event/selfsvcupdate', + 'qs' => 'reset=1&pid=%%id%%&is_backoffice=1&cs=' . CRM_Contact_BAO_Contact_Utils::generateChecksum($result->contact_id, NULL, 'inf'), + 'title' => ts('Transfer or Cancel'), + ); + } + $row['action'] = CRM_Core_Action::formLink($links, $mask, array( diff --git a/templates/CRM/Event/Form/ParticipantView.tpl b/templates/CRM/Event/Form/ParticipantView.tpl index 7ed0d17457..52a98def95 100644 --- a/templates/CRM/Event/Form/ParticipantView.tpl +++ b/templates/CRM/Event/Form/ParticipantView.tpl @@ -117,6 +117,9 @@ {if $hasPayment or $parentHasPayment} {ts}Change Selections{/ts} {/if} + {if $transferOrCancelLink} + {ts}Transfer or Cancel{/ts} + {/if} {/if} {else} diff --git a/templates/CRM/Event/Form/SelfSvcTransfer.tpl b/templates/CRM/Event/Form/SelfSvcTransfer.tpl index c6f71303c3..ad737e95b4 100644 --- a/templates/CRM/Event/Form/SelfSvcTransfer.tpl +++ b/templates/CRM/Event/Form/SelfSvcTransfer.tpl @@ -44,22 +44,32 @@ {$details.role} -
-
-
{$form.first_name.label}
-
{$form.first_name.html}
-
+ {if $form.contact_id} +
+
+
{$form.contact_id.label}
+
{$form.contact_id.html}
+
+
-
-
{$form.last_name.label}
-
{$form.last_name.html}
-
-
-
-
{$form.email.label}
-
{$form.email.html}
-
-
-
+ {else} +
+
+
{$form.first_name.label}
+
{$form.first_name.html}
+
+
+
+
{$form.last_name.label}
+
{$form.last_name.html}
+
+
+
+
{$form.email.label}
+
{$form.email.html}
+
+
+
+ {/if}
{include file="CRM/common/formButtons.tpl" location="bottom"}
-- 2.25.1