Unconditionally assign smarty-var, remove unused variables
authorEileen McNaughton <emcnaughton@wikimedia.org>
Tue, 11 Apr 2023 21:09:40 +0000 (09:09 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Mon, 4 Sep 2023 22:48:33 +0000 (10:48 +1200)
CRM/Event/Form/ManageEvent.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/Form/ManageEvent/Repeat.php
templates/CRM/Event/Form/ManageEvent/EventInfo.tpl

index eef37a34c8a7b97c6de1d65f18e413bf9ec3d453..f496bdc6704a84891157804df6125d01a0383a08 100644 (file)
@@ -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;
+  }
+
 }
index ae762f2a829726f79ff7ba72e6e086447ccf87cb..9743f45c45662c6356fcd06321c386d2abee63b6 100644 (file)
@@ -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');
   }
 
index 591060786284713f56184818c5baee45ddefe756..f84c3de49420d86c849ae529644e556daf4a3a28 100644 (file)
@@ -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'],
index 9a95351e40bdfa930d9cb7624527bce27d2b34d2..3415737f7aa16cf87232d78cb51686e5562bb772 100644 (file)
@@ -10,7 +10,6 @@
 {* Step 1 of New Event Wizard, and Edit Event Info form. *}
 
 <div class="crm-block crm-form-block crm-event-manage-eventinfo-form-block">
-  {assign var=eventID value=$id}
   <div class="crm-submit-buttons">
     {include file="CRM/common/formButtons.tpl" location="top"}
   </div>
@@ -42,7 +41,7 @@
       </td>
     </tr>
     <tr class="crm-event-manage-eventinfo-form-block-participant_listing_id">
-      <td class="label">{$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$entityId}</td>
+      <td class="label">{$form.participant_listing_id.label} {help id="id-listing" isTemplate=$isTemplate action=$action entityId=$eventID}</td>
       <td>{$form.participant_listing_id.html}</td>
     </tr>
     <tr class="crm-event-manage-eventinfo-form-block-title">