ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Database.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35  require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36 }
37 
38 
47 
48 
67  private static function __fieldExtract($database,$field) {
68  $field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
69  $fieldNames = array_map('strtoupper',array_shift($database));
70 
71  if (is_numeric($field)) {
72  $keys = array_keys($fieldNames);
73  return $keys[$field-1];
74  }
75  $key = array_search($field,$fieldNames);
76  return ($key) ? $key : NULL;
77  }
78 
98  private static function __filter($database,$criteria) {
99  $fieldNames = array_shift($database);
100  $criteriaNames = array_shift($criteria);
101 
102  // Convert the criteria into a set of AND/OR conditions with [:placeholders]
103  $testConditions = $testValues = array();
104  $testConditionsCount = 0;
105  foreach($criteriaNames as $key => $criteriaName) {
106  $testCondition = array();
107  $testConditionCount = 0;
108  foreach($criteria as $row => $criterion) {
109  if ($criterion[$key] > '') {
110  $testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::_ifCondition($criterion[$key]);
111  $testConditionCount++;
112  }
113  }
114  if ($testConditionCount > 1) {
115  $testConditions[] = 'OR('.implode(',',$testCondition).')';
116  $testConditionsCount++;
117  } elseif($testConditionCount == 1) {
118  $testConditions[] = $testCondition[0];
119  $testConditionsCount++;
120  }
121  }
122 
123  if ($testConditionsCount > 1) {
124  $testConditionSet = 'AND('.implode(',',$testConditions).')';
125  } elseif($testConditionsCount == 1) {
126  $testConditionSet = $testConditions[0];
127  }
128 
129  // Loop through each row of the database
130  foreach($database as $dataRow => $dataValues) {
131  // Substitute actual values from the database row for our [:placeholders]
132  $testConditionList = $testConditionSet;
133  foreach($criteriaNames as $key => $criteriaName) {
134  $k = array_search($criteriaName,$fieldNames);
135  if (isset($dataValues[$k])) {
136  $dataValue = $dataValues[$k];
137  $dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::_wrapResult(strtoupper($dataValue)) : $dataValue;
138  $testConditionList = str_replace('[:'.$criteriaName.']',$dataValue,$testConditionList);
139  }
140  }
141  // evaluate the criteria against the row data
142  $result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
143  // If the row failed to meet the criteria, remove it from the database
144  if (!$result) {
145  unset($database[$dataRow]);
146  }
147  }
148 
149  return $database;
150  }
151 
152 
180  public static function DAVERAGE($database,$field,$criteria) {
181  $field = self::__fieldExtract($database,$field);
182  if (is_null($field)) {
183  return NULL;
184  }
185  // reduce the database to a set of rows that match all the criteria
186  $database = self::__filter($database,$criteria);
187  // extract an array of values for the requested column
188  $colData = array();
189  foreach($database as $row) {
190  $colData[] = $row[$field];
191  }
192 
193  // Return
195  } // function DAVERAGE()
196 
197 
232  public static function DCOUNT($database,$field,$criteria) {
233  $field = self::__fieldExtract($database,$field);
234  if (is_null($field)) {
235  return NULL;
236  }
237 
238  // reduce the database to a set of rows that match all the criteria
239  $database = self::__filter($database,$criteria);
240  // extract an array of values for the requested column
241  $colData = array();
242  foreach($database as $row) {
243  $colData[] = $row[$field];
244  }
245 
246  // Return
248  } // function DCOUNT()
249 
250 
281  public static function DCOUNTA($database,$field,$criteria) {
282  $field = self::__fieldExtract($database,$field);
283  if (is_null($field)) {
284  return NULL;
285  }
286 
287  // reduce the database to a set of rows that match all the criteria
288  $database = self::__filter($database,$criteria);
289  // extract an array of values for the requested column
290  $colData = array();
291  foreach($database as $row) {
292  $colData[] = $row[$field];
293  }
294 
295  // Return
297  } // function DCOUNTA()
298 
299 
328  public static function DGET($database,$field,$criteria) {
329  $field = self::__fieldExtract($database,$field);
330  if (is_null($field)) {
331  return NULL;
332  }
333 
334  // reduce the database to a set of rows that match all the criteria
335  $database = self::__filter($database,$criteria);
336  // extract an array of values for the requested column
337  $colData = array();
338  foreach($database as $row) {
339  $colData[] = $row[$field];
340  }
341 
342  // Return
343  if (count($colData) > 1) {
345  }
346 
347  return $colData[0];
348  } // function DGET()
349 
350 
379  public static function DMAX($database,$field,$criteria) {
380  $field = self::__fieldExtract($database,$field);
381  if (is_null($field)) {
382  return NULL;
383  }
384 
385  // reduce the database to a set of rows that match all the criteria
386  $database = self::__filter($database,$criteria);
387  // extract an array of values for the requested column
388  $colData = array();
389  foreach($database as $row) {
390  $colData[] = $row[$field];
391  }
392 
393  // Return
394  return PHPExcel_Calculation_Statistical::MAX($colData);
395  } // function DMAX()
396 
397 
426  public static function DMIN($database,$field,$criteria) {
427  $field = self::__fieldExtract($database,$field);
428  if (is_null($field)) {
429  return NULL;
430  }
431 
432  // reduce the database to a set of rows that match all the criteria
433  $database = self::__filter($database,$criteria);
434  // extract an array of values for the requested column
435  $colData = array();
436  foreach($database as $row) {
437  $colData[] = $row[$field];
438  }
439 
440  // Return
441  return PHPExcel_Calculation_Statistical::MIN($colData);
442  } // function DMIN()
443 
444 
472  public static function DPRODUCT($database,$field,$criteria) {
473  $field = self::__fieldExtract($database,$field);
474  if (is_null($field)) {
475  return NULL;
476  }
477 
478  // reduce the database to a set of rows that match all the criteria
479  $database = self::__filter($database,$criteria);
480  // extract an array of values for the requested column
481  $colData = array();
482  foreach($database as $row) {
483  $colData[] = $row[$field];
484  }
485 
486  // Return
488  } // function DPRODUCT()
489 
490 
519  public static function DSTDEV($database,$field,$criteria) {
520  $field = self::__fieldExtract($database,$field);
521  if (is_null($field)) {
522  return NULL;
523  }
524 
525  // reduce the database to a set of rows that match all the criteria
526  $database = self::__filter($database,$criteria);
527  // extract an array of values for the requested column
528  $colData = array();
529  foreach($database as $row) {
530  $colData[] = $row[$field];
531  }
532 
533  // Return
535  } // function DSTDEV()
536 
537 
566  public static function DSTDEVP($database,$field,$criteria) {
567  $field = self::__fieldExtract($database,$field);
568  if (is_null($field)) {
569  return NULL;
570  }
571 
572  // reduce the database to a set of rows that match all the criteria
573  $database = self::__filter($database,$criteria);
574  // extract an array of values for the requested column
575  $colData = array();
576  foreach($database as $row) {
577  $colData[] = $row[$field];
578  }
579 
580  // Return
582  } // function DSTDEVP()
583 
584 
612  public static function DSUM($database,$field,$criteria) {
613  $field = self::__fieldExtract($database,$field);
614  if (is_null($field)) {
615  return NULL;
616  }
617 
618  // reduce the database to a set of rows that match all the criteria
619  $database = self::__filter($database,$criteria);
620  // extract an array of values for the requested column
621  $colData = array();
622  foreach($database as $row) {
623  $colData[] = $row[$field];
624  }
625 
626  // Return
627  return PHPExcel_Calculation_MathTrig::SUM($colData);
628  } // function DSUM()
629 
630 
659  public static function DVAR($database,$field,$criteria) {
660  $field = self::__fieldExtract($database,$field);
661  if (is_null($field)) {
662  return NULL;
663  }
664 
665  // reduce the database to a set of rows that match all the criteria
666  $database = self::__filter($database,$criteria);
667  // extract an array of values for the requested column
668  $colData = array();
669  foreach($database as $row) {
670  $colData[] = $row[$field];
671  }
672 
673  // Return
675  } // function DVAR()
676 
677 
706  public static function DVARP($database,$field,$criteria) {
707  $field = self::__fieldExtract($database,$field);
708  if (is_null($field)) {
709  return NULL;
710  }
711 
712  // reduce the database to a set of rows that match all the criteria
713  $database = self::__filter($database,$criteria);
714  // extract an array of values for the requested column
715  $colData = array();
716  foreach($database as $row) {
717  $colData[] = $row[$field];
718  }
719 
720  // Return
722  } // function DVARP()
723 
724 
725 } // class PHPExcel_Calculation_Database
static DVARP($database, $field, $criteria)
Definition: Database.php:706
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:662
$result
static DAVERAGE($database, $field, $criteria)
Definition: Database.php:180
static DCOUNT($database, $field, $criteria)
Definition: Database.php:232
static DCOUNTA($database, $field, $criteria)
Definition: Database.php:281
static DGET($database, $field, $criteria)
Definition: Database.php:328
static _wrapResult($value)
Wrap string values in quotes.
static DSUM($database, $field, $criteria)
Definition: Database.php:612
$keys
static DPRODUCT($database, $field, $criteria)
Definition: Database.php:472
static DSTDEVP($database, $field, $criteria)
Definition: Database.php:566
static _ifCondition($condition)
Definition: Functions.php:309
static DSTDEV($database, $field, $criteria)
Definition: Database.php:519
Create styles array
The data for the language used.
static DVAR($database, $field, $criteria)
Definition: Database.php:659
static DMIN($database, $field, $criteria)
Definition: Database.php:426
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static DMAX($database, $field, $criteria)
Definition: Database.php:379
static __fieldExtract($database, $field)
__fieldExtract
Definition: Database.php:67
static __filter($database, $criteria)
__filter
Definition: Database.php:98
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$key
Definition: croninfo.php:18