From: eileen Date: Mon, 17 Feb 2020 04:50:04 +0000 (+1300) Subject: [NFC] Minor code cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5db18d97615954a7476552056d7f519d3a05d224;p=civicrm-core.git [NFC] Minor code cleanup Declare exceptions, use single quotes & strict comparison, do not declare unused params --- diff --git a/CRM/Event/Form/SelfSvcTransfer.php b/CRM/Event/Form/SelfSvcTransfer.php index e5a628241c..8fac0d8119 100644 --- a/CRM/Event/Form/SelfSvcTransfer.php +++ b/CRM/Event/Form/SelfSvcTransfer.php @@ -14,8 +14,6 @@ * * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing - * $Id$ - * */ /** @@ -131,9 +129,10 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { * be transferred to this participant - at this point no transaction changes processed * * return @void + * + * @throws \CRM_Core_Exception */ public function preProcess() { - $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $this->_userContext = $session->readUserContext(); $this->_from_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST'); @@ -155,7 +154,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { if ($this->_from_participant_id) { $this->assign('participantId', $this->_from_participant_id); } - $event = []; + $daoName = 'title'; $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); $daoName = 'start_date'; @@ -163,7 +162,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_from_contact_id); $this->_contact_name = $displayName; $this->_contact_email = $email; - $details = []; + $details = CRM_Event_BAO_Participant::participantDetails($this->_from_participant_id); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); $query = " @@ -296,7 +295,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { // verify whether this contact already registered for this event $contact_details = CRM_Contact_BAO_Contact::getContactDetails($contact_id); $display_name = $contact_details[0]; - $query = "select event_id from civicrm_participant where contact_id = " . $contact_id; + $query = 'select event_id from civicrm_participant where contact_id = ' . $contact_id; $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { $to_event_id[] = $dao->event_id; @@ -313,6 +312,8 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { /** * Process transfer - first add the new participant to the event, then cancel * source participant - send confirmation email to transferee + * + * @throws \CiviCRM_API3_Exception */ public function postProcess() { //For transfer, process form to allow selection of transferree @@ -324,7 +325,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { //cancel 'from' participant row $contact_id_result = civicrm_api3('Contact', 'get', [ 'sequential' => 1, - 'return' => ["id"], + 'return' => ['id'], 'email' => $params['email'], 'options' => ['limit' => 1], ]); @@ -335,8 +336,8 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { CRM_Core_Error::statusBounce(ts('Contact does not exist.')); } } - $from_participant = $params = []; - $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; + + $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; $dao = CRM_Core_DAO::executeQuery($query); $value_to = []; while ($dao->fetch()) { @@ -397,6 +398,8 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { * Based on input, create participant row for transferee and send email * * return @ void + * + * @throws \CRM_Core_Exception */ public function participantTransfer($participant) { $contactDetails = []; @@ -502,7 +505,7 @@ class CRM_Event_Form_SelfSvcTransfer extends CRM_Core_Form { foreach ($tokens['domain'] as $token) { $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); } - $participantRoles = []; + $participantRoles = CRM_Event_PseudoConstant::participantRole(); $participantDetails = []; $query = "SELECT * FROM civicrm_participant WHERE id = {$this->_from_participant_id}"; diff --git a/CRM/Event/Form/SelfSvcUpdate.php b/CRM/Event/Form/SelfSvcUpdate.php index 5e4e01f99a..baf595938f 100644 --- a/CRM/Event/Form/SelfSvcUpdate.php +++ b/CRM/Event/Form/SelfSvcUpdate.php @@ -13,8 +13,6 @@ * * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing - * $Id$ - * */ /** @@ -102,6 +100,8 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { * Set variables up before form is built based on participant ID from URL * * @return void + * + * @throws \CRM_Core_Exception */ public function preProcess() { $config = CRM_Core_Config::singleton(); @@ -127,7 +127,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { if ($this->_participant_id) { $this->assign('participantId', $this->_participant_id); } - $event = []; + $daoName = 'title'; $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName); $daoName = 'start_date'; @@ -135,7 +135,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contact_id); $this->_contact_name = $displayName; $this->_contact_email = $email; - $details = []; + $details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id); $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name'); $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id'); @@ -157,7 +157,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $details['event_start_date'] = $dao->start_date; } //verify participant status is still Registered - if ($details['status'] != "Registered") { + if ($details['status'] !== 'Registered') { $status = "You cannot transfer or cancel your registration for " . $this->_event_title . ' as you are not currently registered for this event.'; CRM_Core_Session::setStatus($status, ts('Sorry'), 'alert'); CRM_Utils_System::redirect($url); @@ -171,7 +171,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $start_time = new Datetime($start_date); $timenow = new Datetime(); 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."); + $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 (!$this->isBackoffice && !empty($time_limit) && $time_limit > 0) { @@ -251,11 +251,9 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { $params = $this->controller->exportValues($this->_name); $action = $params['action']; if ($action == "1") { - $action = "Transfer Event"; $this->transferParticipant($params); } elseif ($action == "2") { - $action = "Cancel Event"; $this->cancelParticipant($params); } } @@ -284,6 +282,8 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { * auto-cancellation of payment is handled, so payment needs to be manually cancelled * * return @void + * + * @throws \CRM_Core_Exception */ public function cancelParticipant($params) { //set participant record status to Cancelled, refund payment if possible @@ -309,7 +309,7 @@ class CRM_Event_Form_SelfSvcUpdate extends CRM_Core_Form { foreach ($tokens['domain'] as $token) { $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); } - $participantRoles = []; + $participantRoles = CRM_Event_PseudoConstant::participantRole(); $participantDetails = []; $query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";