Created
June 5, 2016 01:05
-
-
Save chriscalip/bc85591580beb36ca9e0d5ffd55a111e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$selectedFilters['region'] = 'ALL'; | |
$selectedFilters['state'] = 'ALL'; | |
$selectedFilters['zip'] = 60101; | |
$selectedFilters['specialty'] = 'ALL'; | |
$dataGrid[] = array( | |
'client' => 'A', | |
'region' => 'east', | |
'state' => 'IL', | |
'cardiology' => 1, | |
'radiology' => 0, | |
'oncology' => 1, | |
'zip' => 60131, | |
); | |
$dataGrid[] = array( | |
'client' => 'B', | |
'region' => 'west', | |
'state' => 'WI', | |
'cardiology' => 0, | |
'radiology' => 1, | |
'oncology' => 1, | |
'zip' => 60607 | |
); | |
$dataGrid[] = array( | |
'client' => 'C', | |
'region' => 'midwest', | |
'state' => 'WY', | |
'cardiology' => 0, | |
'radiology' => 0, | |
'oncology' => 0, | |
'zip' => 60126 | |
); | |
$includes = array(); | |
foreach ($selectedFilters as $filterType => $filter) { | |
foreach ($dataGrid as $record) { | |
$includeRecord = FALSE; | |
if ($filterType == 'specialty' || $filterType == 'specialities2') { | |
$includeRecord = parseMultipleColumn($filterType, $filter, $record); | |
} else { | |
$includeRecord = parseSingleColumn($filterType, $filter, $record); | |
} | |
$includes[$record['client']][$filterType] = $includeRecord; | |
} | |
} | |
var_dump($dataGrid); | |
var_dump($includes); | |
function parseSingleColumn($filterType, $filter, $record) { | |
$bool = FALSE; | |
if ( ($filter == 'ALL') || ($filter == $record[$filterType]) ) { | |
$bool = TRUE; | |
return $bool; | |
} | |
return $bool; | |
} | |
/** | |
* parser function to do. | |
* trying enforce | |
* @param [type] $filterType [description] | |
* @param [type] $filter [description] | |
* @param [type] $record [description] | |
* @return [type] [description] | |
*/ | |
function parseMultipleColumn($filterType, $filter, $record) { | |
if ($filterType == 'specialty') { | |
$defaultFilters = array('cardiology', 'radiology', 'oncology'); | |
} elseif ($filterType == 'specialities2') { | |
$defaultFilters = array('ei.clon', 'a', 'ogklkgk'); | |
} | |
$bool = FALSE; | |
$specFilters = array(); | |
if ($filter == 'ALL') { | |
$specFilters = $defaultFilters; | |
} else { | |
$specFilters = array($filter); | |
} | |
foreach ($specFilters as $specFilter) { | |
if ($record[$specFilter] == 1) { | |
$bool = TRUE; | |
} | |
} | |
// ALL is ANY | |
return $bool; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment