private static function PHPExcel_Calculation_Database::__filter in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Database.php \PHPExcel_Calculation_Database::__filter()
* __filter * * Parses the selection criteria, extracts the database rows that match those criteria, and * returns that subset of rows. * * @access private *
Parameters
mixed[] $database The range of cells that makes up the list or database.: * A database is a list of related data in which rows of related * information are records, and columns of data are fields. The * first row of the list contains labels for each column. * @param mixed[] $criteria The range of cells that contains the conditions you specify. * You can use any range for the criteria argument, as long as it * includes at least one column label and at least one cell below * the column label in which you specify a condition for the * column. * @return array of mixed *
12 calls to PHPExcel_Calculation_Database::__filter()
- PHPExcel_Calculation_Database::DAVERAGE in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php - * DAVERAGE * * Averages the values in a column of a list or database that match conditions you specify. * * Excel Function: * DAVERAGE(database,field,criteria) * * @access public * @category Database Functions *
- PHPExcel_Calculation_Database::DCOUNT in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php - * DCOUNT * * Counts the cells that contain numbers in a column of a list or database that match conditions * that you specify. * * Excel Function: * DCOUNT(database,[field],criteria) * * Excel Function: …
- PHPExcel_Calculation_Database::DCOUNTA in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php - * DCOUNTA * * Counts the nonblank cells in a column of a list or database that match conditions that you specify. * * Excel Function: * DCOUNTA(database,[field],criteria) * * @access public * @category Database Functions *
- PHPExcel_Calculation_Database::DGET in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php - * DGET * * Extracts a single value from a column of a list or database that matches conditions that you * specify. * * Excel Function: * DGET(database,field,criteria) * * @access public * @category Database Functions *
- PHPExcel_Calculation_Database::DMAX in vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php - * DMAX * * Returns the largest number in a column of a list or database that matches conditions you that * specify. * * Excel Function: * DMAX(database,field,criteria) * * @access public * @category Database Functions *
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Database.php, line 98
Class
- PHPExcel_Calculation_Database
- PHPExcel_Calculation_Database
Code
private static function __filter($database, $criteria) {
$fieldNames = array_shift($database);
$criteriaNames = array_shift($criteria);
// Convert the criteria into a set of AND/OR conditions with [:placeholders]
$testConditions = $testValues = array();
$testConditionsCount = 0;
foreach ($criteriaNames as $key => $criteriaName) {
$testCondition = array();
$testConditionCount = 0;
foreach ($criteria as $row => $criterion) {
if ($criterion[$key] > '') {
$testCondition[] = '[:' . $criteriaName . ']' . PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]);
$testConditionCount++;
}
}
if ($testConditionCount > 1) {
$testConditions[] = 'OR(' . implode(',', $testCondition) . ')';
$testConditionsCount++;
}
elseif ($testConditionCount == 1) {
$testConditions[] = $testCondition[0];
$testConditionsCount++;
}
}
if ($testConditionsCount > 1) {
$testConditionSet = 'AND(' . implode(',', $testConditions) . ')';
}
elseif ($testConditionsCount == 1) {
$testConditionSet = $testConditions[0];
}
// Loop through each row of the database
foreach ($database as $dataRow => $dataValues) {
// Substitute actual values from the database row for our [:placeholders]
$testConditionList = $testConditionSet;
foreach ($criteriaNames as $key => $criteriaName) {
$k = array_search($criteriaName, $fieldNames);
if (isset($dataValues[$k])) {
$dataValue = $dataValues[$k];
$dataValue = is_string($dataValue) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue;
$testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList);
}
}
// evaluate the criteria against the row data
$result = PHPExcel_Calculation::getInstance()
->_calculateFormulaValue('=' . $testConditionList);
// If the row failed to meet the criteria, remove it from the database
if (!$result) {
unset($database[$dataRow]);
}
}
return $database;
}