Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Created May 8, 2017 14:27
Show Gist options
  • Select an option

  • Save NickDeckerDevs/bef14a48786d91b7c060a399c9f39f0b to your computer and use it in GitHub Desktop.

Select an option

Save NickDeckerDevs/bef14a48786d91b7c060a399c9f39f0b to your computer and use it in GitHub Desktop.
These are additions or replacements for current functions inside the functions.php file
<?php
function getRegionsArray() {
$regionsArray = [];
$regionsData = getClinicData('select DISTINCT STATE_ID, REGION_1, REGION_2, REGION_3, STATE from dbo.CLINICS_DATA WHERE INCLUDEINSEARCH = 1 ORDER BY STATE_ID');
foreach($regionsData as $location) {
// d($location);
$state = $location['STATE_ID'];
if(!array_key_exists($state, $regionsArray)) {
$regionsArray[$state] = [];
}
foreach($location as $index => $value) {
if(strpos($index, 'REGION') > -1) {
if(!is_null($value) && $value != '' && $value != ' ') {
if(!array_key_exists($value, $regionsArray[$state]) && !in_array($value, $regionsArray[$state])) {
array_push($regionsArray[$state], $value);
}
}
}
}
if(array_key_exists('STATE', $location)) {
$regionsArray[$state]['abbr'] = $location['STATE'];
}
}
return $regionsArray;
}
function getClinicRegionMenu() {
$regions_data = getRegionsArray();
foreach($regions_data as $state => $regionArray ) {
$state_short = $regionArray['abbr'];
unset($regionArray['abbr']);
?>
<p class="state"><?php echo $state; ?> <span>+</span></p>
<ul style="display:none;">
<?php
if(count($regionArray) > 0) {
foreach($regionArray as $region) {
?>
<li data-type="region" data-region="<?php echo $region; ?>"><?php echo $region; ?></li>
<?php
}
} else {
?>
<ul style="display:none;">
<li data-type="state" data-state="<?php echo $state_short; ?>">All <?php echo $state; ?> Clinics</li>
</ul>
<?php
}
?>
</ul>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment