From 0ea2996e1eb8821687c979e7ed8c07f8a53117b0 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 12 Apr 2023 09:09:40 +1200 Subject: [PATCH] Unconditionally assign smarty-var, remove unused variables --- CRM/Event/Form/ManageEvent.php | 14 ++++- CRM/Event/Form/ManageEvent/EventInfo.php | 57 +++++++++---------- CRM/Event/Form/ManageEvent/Repeat.php | 34 +++++------ .../CRM/Event/Form/ManageEvent/EventInfo.tpl | 3 +- 4 files changed, 55 insertions(+), 53 deletions(-) diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index eef37a34c8..f496bdc670 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -95,8 +95,7 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { $this->assign('action', $this->_action); - $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); - if ($this->_id) { + if ($this->getEventID()) { $this->_isRepeatingEvent = CRM_Core_BAO_RecurringEntity::getParentFor($this->_id, 'civicrm_event'); $this->assign('eventId', $this->_id); $this->_single = TRUE; @@ -386,4 +385,15 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { CRM_UF_Page_ProfileEditor::registerSchemas(['IndividualModel', 'ParticipantModel']); } + /** + * @return int|null + * @throws \CRM_Core_Exception + */ + public function getEventID() { + if (!$this->_id) { + $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'GET'); + } + return $this->_id ? (int) $this->_id : NULL; + } + } diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index ae762f2a82..9743f45c45 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -14,6 +14,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\Api4\Event; + /** * This class generates form components for processing Event. */ @@ -23,28 +25,19 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { * Event type. * @var int */ - protected $_eventType = NULL; + protected $_eventType; /** * Set variables up before form is built. + * + * @throws \CRM_Core_Exception */ - public function preProcess() { + public function preProcess(): void { parent::preProcess(); $this->setSelectedChild('settings'); - $entityID = $this->_id ?: $this->_templateId; - if ($entityID) { - $this->assign('entityID', $entityID); - $eventType = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', - $entityID, - 'event_type_id' - ); - } - else { - $eventType = 'null'; - } - - $showLocation = FALSE; + $entityID = $this->getEventID() ?: $this->_templateId; + $this->assign('eventID', $entityID); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { $this->set('type', 'Event'); @@ -61,7 +54,9 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { /** * Set default values for the form. * - * For edit/view mode he default values are retrieved from the database. + * For edit/view mode the default values are retrieved from the database. + * + * @return array */ public function setDefaultValues() { $defaults = parent::setDefaultValues(); @@ -71,26 +66,26 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { $this->assign('customDataSubType', $defaults['event_type_id']); } - $this->_showHide = new CRM_Core_ShowHideBlocks(); + $showHideBlocks = new CRM_Core_ShowHideBlocks(); // Show waitlist features or event_full_text if max participants set if (!empty($defaults['max_participants'])) { - $this->_showHide->addShow('id-waitlist'); + $showHideBlocks->addShow('id-waitlist'); if (!empty($defaults['has_waitlist'])) { - $this->_showHide->addShow('id-waitlist-text'); - $this->_showHide->addHide('id-event_full'); + $showHideBlocks->addShow('id-waitlist-text'); + $showHideBlocks->addHide('id-event_full'); } else { - $this->_showHide->addHide('id-waitlist-text'); - $this->_showHide->addShow('id-event_full'); + $showHideBlocks->addHide('id-waitlist-text'); + $showHideBlocks->addShow('id-event_full'); } } else { - $this->_showHide->addHide('id-event_full'); - $this->_showHide->addHide('id-waitlist'); - $this->_showHide->addHide('id-waitlist-text'); + $showHideBlocks->addHide('id-event_full'); + $showHideBlocks->addHide('id-waitlist'); + $showHideBlocks->addHide('id-waitlist-text'); } - $this->_showHide->addToTemplate(); + $showHideBlocks->addToTemplate(); $this->assign('elemType', 'table-row'); $this->assign('description', CRM_Utils_Array::value('description', $defaults)); @@ -106,8 +101,10 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { /** * Build the form object. + * + * @throws \CRM_Core_Exception */ - public function buildQuickForm() { + public function buildQuickForm(): void { //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Event'); if ($this->_eventType) { @@ -123,7 +120,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { } if ($this->_action & CRM_Core_Action::ADD) { - $eventTemplates = \Civi\Api4\Event::get(FALSE) + $eventTemplates = Event::get(FALSE) ->addWhere('is_template', '=', TRUE) ->addWhere('is_active', '=', TRUE) ->execute() @@ -254,7 +251,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { $url = 'civicrm/event/manage/location'; $urlParams = "action=update&reset=1&id={$event->id}"; // special case for 'Save and Done' consistency. - if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { + if ('_qf_EventInfo_upload_done' === $this->controller->getButtonName('submit')) { $url = 'civicrm/event/manage'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", @@ -273,7 +270,7 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { * * @return string */ - public function getTitle() { + public function getTitle(): string { return ts('Event Information and Settings'); } diff --git a/CRM/Event/Form/ManageEvent/Repeat.php b/CRM/Event/Form/ManageEvent/Repeat.php index 5910607862..f84c3de494 100644 --- a/CRM/Event/Form/ManageEvent/Repeat.php +++ b/CRM/Event/Form/ManageEvent/Repeat.php @@ -26,19 +26,12 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { */ protected $_parentEventEndDate = NULL; - /** - * @return int - */ - protected function getEventId() { - return $this->_id; - } - public function preProcess() { parent::preProcess(); $this->setSelectedChild('repeat'); - $this->assign('currentEventId', $this->getEventId()); + $this->assign('currentEventId', $this->getEventID()); - $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->getEventId(), 'civicrm_event'); + $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($this->getEventID(), 'civicrm_event'); //If this ID has parent, send parent id if ($checkParentExistsForThisId) { /** @@ -73,7 +66,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { } } - $parentEventParams = ['id' => $this->getEventId()]; + $parentEventParams = ['id' => $this->getEventID()]; $parentEventValues = []; $parentEventReturnProperties = ['start_date', 'end_date']; $parentEventAttributes = CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $parentEventParams, $parentEventValues, $parentEventReturnProperties); @@ -92,7 +85,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { $defaults = []; //Always pass current event's start date by default - $defaults['repetition_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->getEventId(), 'start_date', 'id'); + $defaults['repetition_start_date'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->getEventID(), 'start_date', 'id'); $recurringEntityDefaults = CRM_Core_Form_RecurringEntity::setDefaultValues(); return array_merge($defaults, $recurringEntityDefaults); } @@ -101,8 +94,11 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { CRM_Core_Form_RecurringEntity::buildQuickForm($this); } + /** + * @throws \CRM_Core_Exception + */ public function postProcess() { - if ($this->getEventId()) { + if ($this->getEventID()) { $params = $this->controller->exportValues($this->_name); if ($this->_parentEventStartDate && $this->_parentEventEndDate) { $interval = CRM_Core_BAO_RecurringEntity::getInterval($this->_parentEventStartDate, $this->_parentEventEndDate); @@ -111,22 +107,22 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { $params['dateColumns'] = ['start_date']; $params['excludeDateRangeColumns'] = ['start_date', 'end_date']; $params['entity_table'] = 'civicrm_event'; - $params['entity_id'] = $this->getEventId(); + $params['entity_id'] = $this->getEventID(); // CRM-16568 - check if parent exist for the event. - $parentId = CRM_Core_BAO_RecurringEntity::getParentFor($this->getEventId(), 'civicrm_event'); + $parentId = CRM_Core_BAO_RecurringEntity::getParentFor($this->getEventID(), 'civicrm_event'); $params['parent_entity_id'] = !empty($parentId) ? $parentId : $params['entity_id']; //Unset event id unset($params['id']); $url = 'civicrm/event/manage/repeat'; - $urlParams = "action=update&reset=1&id={$this->getEventId()}&selectedChild=repeat"; + $urlParams = "action=update&reset=1&id={$this->getEventID()}&selectedChild=repeat"; $linkedEntities = [ [ 'table' => 'civicrm_price_set_entity', 'findCriteria' => [ - 'entity_id' => $this->getEventId(), + 'entity_id' => $this->getEventID(), 'entity_table' => 'civicrm_event', ], 'linkedColumns' => ['entity_id'], @@ -135,7 +131,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { [ 'table' => 'civicrm_uf_join', 'findCriteria' => [ - 'entity_id' => $this->getEventId(), + 'entity_id' => $this->getEventID(), 'entity_table' => 'civicrm_event', ], 'linkedColumns' => ['entity_id'], @@ -144,7 +140,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { [ 'table' => 'civicrm_tell_friend', 'findCriteria' => [ - 'entity_id' => $this->getEventId(), + 'entity_id' => $this->getEventID(), 'entity_table' => 'civicrm_event', ], 'linkedColumns' => ['entity_id'], @@ -153,7 +149,7 @@ class CRM_Event_Form_ManageEvent_Repeat extends CRM_Event_Form_ManageEvent { [ 'table' => 'civicrm_pcp_block', 'findCriteria' => [ - 'entity_id' => $this->getEventId(), + 'entity_id' => $this->getEventID(), 'entity_table' => 'civicrm_event', ], 'linkedColumns' => ['entity_id'], diff --git a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl index 9a95351e40..3415737f7a 100644 --- a/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl +++ b/templates/CRM/Event/Form/ManageEvent/EventInfo.tpl @@ -10,7 +10,6 @@ {* Step 1 of New Event Wizard, and Edit Event Info form. *}
- {assign var=eventID value=$id}
{include file="CRM/common/formButtons.tpl" location="top"}
@@ -42,7 +41,7 @@ - {$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId} + {$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$eventID} {$form.participant_listing_id.html} -- 2.25.1