From c17cd9eb80e8f8e740b070a958b7b26f0d519889 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 22 Feb 2019 14:27:41 -0500 Subject: [PATCH] Reworking how event categories are saved when editing an event Moving the setup event category call until after it has foreached through the current category list. Doing this each time was needless. --- index.php | 2 +- models/admin/events/list.php | 32 ++++++++++++++++---------------- readme.txt | 3 +++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/index.php b/index.php index 5a028cb..c09ce69 100755 --- a/index.php +++ b/index.php @@ -43,7 +43,7 @@ if (!defined('ABSPATH')) { * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.7.19'); +define('GLM_MEMBERS_EVENTS_PLUGIN_VERSION', '1.7.20'); define('GLM_MEMBERS_EVENTS_PLUGIN_DB_VERSION', '0.1.13'); // This is the minimum version of the GLM Members DB plugin require for this plugin. diff --git a/models/admin/events/list.php b/models/admin/events/list.php index 3aefba1..54036ed 100644 --- a/models/admin/events/list.php +++ b/models/admin/events/list.php @@ -306,7 +306,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $_REQUEST[$locID.'_event'] = $this->eventID; // Check for new cities in this location and if so use the new city real ID - if (isset($_REQEUST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { + if (isset($_REQUEST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']]; } @@ -501,10 +501,10 @@ class GlmMembersAdmin_events_list extends GlmDataEvents if (isset($_REQUEST['locID'])) { // For each location - while (list($id, $locID) = each($_REQUEST['locID'])) { + foreach ( $_REQUEST['locID'] as $id => $locID ) { // Check for new cities in this location and if so use the new city real ID - if (isset($_REQEUST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { + if (isset($_REQUEST[$locID.'_city']) && $_REQUEST[$locID.'_city'][0] == 'n') { $_REQUEST[$locID.'_city'] = $newCityID[$_REQUEST[$locID.'_city']]; } @@ -649,7 +649,6 @@ class GlmMembersAdmin_events_list extends GlmDataEvents case 'list': default: - $where = 'true'; // If we have a back request then go through the PHP_SESSION @@ -708,7 +707,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // Add "selected" element default false; reset($categories); - while (list($k, $v) = each($categories)) { + foreach ( $categories as $k => $v ) { $categories[$k]['selected'] = false; } @@ -867,7 +866,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents // since we're doing paging, we have to break out just the events data $events = $eventsResult['list']; - if (count($events)>0) { + if ( is_array( $events ) && !empty( $events ) && count($events) > 0 ) { $haveEvents = true; } unset($eventsResult); @@ -1118,24 +1117,25 @@ class GlmMembersAdmin_events_list extends GlmDataEvents } - // If there's selected categories - if (count($selectedCategories) > 0) { - - // Update the selected categories for this event record, returns new list - $EventCategories->setEventCategories($this->eventID, $selectedCategories); - - } - // If there's been a new category if ($newCategory) { // Get the full category list again - $this->categories = $Categories->getListSortedParentChild(); + // $this->categories = $Categories->getListSortedParentChild(); } } // For each category being submitted + // If there's selected categories + if (count($selectedCategories) > 0) { + + // Update the selected categories for this event record, returns new list + $EventCategories->setEventCategories($this->eventID, $selectedCategories); + + } + + // Otherwise if this is a submission and there's no categories submitted, so make sure there's none stored } elseif ( isset($_REQUEST['option']) && ( $_REQUEST['option'] === 'submit' || $_REQUEST['option'] === 'update' ) ) { $EventCategories->clearEventCategories($this->eventID); @@ -1240,7 +1240,7 @@ class GlmMembersAdmin_events_list extends GlmDataEvents $Cities = new GlmDataCities($this->wpdb, $this->config); // For each new city submitted - while (list($k, $v) = each($_REQUEST['newCity'])) { + foreach ( $_REQUEST['newCity'] as $k => $v ) { $cName = trim(filter_var($_REQUEST['newCity'][$k])); diff --git a/readme.txt b/readme.txt index a9e77eb..86945cd 100755 --- a/readme.txt +++ b/readme.txt @@ -25,6 +25,9 @@ e.g. 1. Activate the plugin through the 'Plugins' menu in WordPress == Changelog == += 1.7.20 = +* Bugfix - Event Category update reworking to avoid duplication of queries. + = 1.7.19 = * New option (management) sort_by_featured_in_agenda * New option (management) show_search_city -- 2.17.1