wpdatatables
/
lib
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Calculation
/
Database
/
DGet.php
DGet.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Database/DGet.php
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpSpreadsheet\Calculation\Database; |
| 4 | |
| 5 | use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
| 6 | |
| 7 | class DGet extends DatabaseAbstract |
| 8 | { |
| 9 | /** |
| 10 | * DGET. |
| 11 | * |
| 12 | * Extracts a single value from a column of a list or database that matches conditions that you |
| 13 | * specify. |
| 14 | * |
| 15 | * Excel Function: |
| 16 | * DGET(database,field,criteria) |
| 17 | * |
| 18 | * @param mixed[] $database The range of cells that makes up the list or database. |
| 19 | * A database is a list of related data in which rows of related |
| 20 | * information are records, and columns of data are fields. The |
| 21 | * first row of the list contains labels for each column. |
| 22 | * @param int|string $field Indicates which column is used in the function. Enter the |
| 23 | * column label enclosed between double quotation marks, such as |
| 24 | * "Age" or "Yield," or a number (without quotation marks) that |
| 25 | * represents the position of the column within the list: 1 for |
| 26 | * the first column, 2 for the second column, and so on. |
| 27 | * @param mixed[] $criteria The range of cells that contains the conditions you specify. |
| 28 | * You can use any range for the criteria argument, as long as it |
| 29 | * includes at least one column label and at least one cell below |
| 30 | * the column label in which you specify a condition for the |
| 31 | * column. |
| 32 | * |
| 33 | * @return mixed |
| 34 | */ |
| 35 | public static function evaluate($database, $field, $criteria) |
| 36 | { |
| 37 | $field = self::fieldExtract($database, $field); |
| 38 | if ($field === null) { |
| 39 | return ExcelError::VALUE(); |
| 40 | } |
| 41 | |
| 42 | $columnData = self::getFilteredColumn($database, $field, $criteria); |
| 43 | if (count($columnData) > 1) { |
| 44 | return ExcelError::NAN(); |
| 45 | } |
| 46 | |
| 47 | $row = array_pop($columnData); |
| 48 | |
| 49 | return array_pop($row); |
| 50 | } |
| 51 | } |
| 52 |