From b848680c7c1672f589eb4d7b0962769548dfe5fc Mon Sep 17 00:00:00 2001 From: JR Date: Thu, 6 Mar 2014 18:02:44 +0100 Subject: [PATCH 1/2] added $startResults option you can include a $startResults option (0/1, default is 0) to display the result window when the form has no been submitted. --- .../snippets/snippet.storelocator.php | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/core/components/storelocator/elements/snippets/snippet.storelocator.php b/core/components/storelocator/elements/snippets/snippet.storelocator.php index 17fe620..6abfad0 100644 --- a/core/components/storelocator/elements/snippets/snippet.storelocator.php +++ b/core/components/storelocator/elements/snippets/snippet.storelocator.php @@ -39,6 +39,7 @@ $markerImage = $modx->getOption('markerImage', $scriptProperties, '0'); $sortDir = $modx->getOption('sortDir', $scriptProperties, 'ASC'); $limit = $modx->getOption('limit', $scriptProperties, 0); +$startResults = $modx->getOption('startResults', $scriptProperties, 0); // Templating parameters $formTpl = $modx->getOption('formTpl', $scriptProperties, 'sl.form'); @@ -77,9 +78,11 @@ $query->sortby('sort', $sortDir); $query->limit($limit); +$totalStores = $modx->getCount('slStore', $query); $stores = $modx->getCollection('slStore', $query); $storeListOutput = ''; $i = 0; +$matchedStores = 0; foreach($stores as $store) { if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { @@ -108,6 +111,7 @@ $resourceArray, array( 'store' => $store->toArray(), + 'totalStores' => $totalStores, 'onclick' => 'storeLocatorMap.setCenter(new google.maps.LatLng('.$store->get('latitude').', '.$store->get('longitude').')); storeLocatorMap.setZoom('.$storeZoom.');' ) )); @@ -116,7 +120,8 @@ $infoWindowOutput = $storeLocator->getChunk($storeInfoWindowTpl, array_merge( $resourceArray, array( - 'store' => $store->toArray() + 'store' => $store->toArray(), + 'totalStores' => $totalStores ) )); @@ -130,9 +135,10 @@ )); $i++; + $matchedStores++; } } - + // Nothing is found if ($i == 0) { $storeListOutput = $storeLocator->getChunk($noResultsTpl); @@ -140,12 +146,21 @@ $locatorFormOutput = $storeLocator->getChunk($formTpl, array( 'query' => str_replace(array('[', ']'), '', $_REQUEST['query']), - 'radius' => isset($_REQUEST['radius']) ? $_REQUEST['radius'] : $defaultRadius + 'radius' => isset($_REQUEST['radius']) ? $_REQUEST['radius'] : $defaultRadius, + 'totalStores' => $totalStores, + 'matchedStores' => $matchedStores )); +//check for startResult +if (strtolower($_SERVER['REQUEST_METHOD']) != 'post' && $startResults == 0) { + $storeListOutput = ''; +} + // Parse output to place holders $modx->toPlaceHolders(array( 'map' => '
', 'storeList' => $storeListOutput, - 'form' => $locatorFormOutput -), 'StoreLocator'); \ No newline at end of file + 'form' => $locatorFormOutput, + 'totalStores' => $totalStores, + 'matchedStores' => $matchedStores +), 'StoreLocator'); From 666fc0be911faa22544793187c585e284ad671d9 Mon Sep 17 00:00:00 2001 From: JR Date: Thu, 6 Mar 2014 18:23:51 +0100 Subject: [PATCH 2/2] Update snippet.storelocator.php --- .../storelocator/elements/snippets/snippet.storelocator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/components/storelocator/elements/snippets/snippet.storelocator.php b/core/components/storelocator/elements/snippets/snippet.storelocator.php index 6abfad0..4a9c3be 100644 --- a/core/components/storelocator/elements/snippets/snippet.storelocator.php +++ b/core/components/storelocator/elements/snippets/snippet.storelocator.php @@ -46,6 +46,7 @@ $storeRowTpl = $modx->getOption('storeRowTpl', $scriptProperties, 'sl.storerow'); $storeInfoWindowTpl = $modx->getOption('storeInfoWindowTpl', $scriptProperties, 'sl.infowindow'); $noResultsTpl = $modx->getOption('noResultsTpl', $scriptProperties, 'sl.noresultstpl'); +$emptyResultsTemplate = $modx->getOption('emptyResultsTemplate', $scriptProperties, 'emptyResultsTemplate'); // Developers templating parameters $scriptWrapperTpl = $modx->getOption('scriptWrapperTpl', $scriptProperties, 'sl.scriptwrapper'); @@ -150,10 +151,10 @@ 'totalStores' => $totalStores, 'matchedStores' => $matchedStores )); - +$emptyStartResults = 0; //check for startResult if (strtolower($_SERVER['REQUEST_METHOD']) != 'post' && $startResults == 0) { - $storeListOutput = ''; + $emptyStartResults = 1; } // Parse output to place holders @@ -162,5 +163,6 @@ 'storeList' => $storeListOutput, 'form' => $locatorFormOutput, 'totalStores' => $totalStores, + 'emptyStartResult' => $emptyStartResults, 'matchedStores' => $matchedStores ), 'StoreLocator');