Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
$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');
$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');
Expand Down Expand Up @@ -77,9 +79,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') {
Expand Down Expand Up @@ -108,6 +112,7 @@
$resourceArray,
array(
'store' => $store->toArray(),
'totalStores' => $totalStores,
'onclick' => 'storeLocatorMap.setCenter(new google.maps.LatLng('.$store->get('latitude').', '.$store->get('longitude').')); storeLocatorMap.setZoom('.$storeZoom.');'
)
));
Expand All @@ -116,7 +121,8 @@
$infoWindowOutput = $storeLocator->getChunk($storeInfoWindowTpl, array_merge(
$resourceArray,
array(
'store' => $store->toArray()
'store' => $store->toArray(),
'totalStores' => $totalStores
)
));

Expand All @@ -130,22 +136,33 @@
));

$i++;
$matchedStores++;
}
}

// Nothing is found
if ($i == 0) {
$storeListOutput = $storeLocator->getChunk($noResultsTpl);
}

$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
));
$emptyStartResults = 0;
//check for startResult
if (strtolower($_SERVER['REQUEST_METHOD']) != 'post' && $startResults == 0) {
$emptyStartResults = 1;
}

// Parse output to place holders
$modx->toPlaceHolders(array(
'map' => '<div id="storelocator_canvas" style="width: '.$width.'px; height: '.$height.'px;"></div>',
'storeList' => $storeListOutput,
'form' => $locatorFormOutput
), 'StoreLocator');
'form' => $locatorFormOutput,
'totalStores' => $totalStores,
'emptyStartResult' => $emptyStartResults,
'matchedStores' => $matchedStores
), 'StoreLocator');