ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Functions.php
Go to the documentation of this file.
1<?php
30if (!defined('PHPEXCEL_ROOT')) {
34 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
36}
37
38
40define('MAX_VALUE', 1.2e308);
41
43define('M_2DIVPI', 0.63661977236758134307553505349006);
44
46define('MAX_ITERATIONS', 256);
47
49define('PRECISION', 8.88E-016);
50
51
60
62 const COMPATIBILITY_EXCEL = 'Excel';
63 const COMPATIBILITY_GNUMERIC = 'Gnumeric';
64 const COMPATIBILITY_OPENOFFICE = 'OpenOfficeCalc';
65
68 const RETURNDATE_EXCEL = 'E';
69
70
78
86
93 protected static $_errorCodes = array( 'null' => '#NULL!',
94 'divisionbyzero' => '#DIV/0!',
95 'value' => '#VALUE!',
96 'reference' => '#REF!',
97 'name' => '#NAME?',
98 'num' => '#NUM!',
99 'na' => '#N/A',
100 'gettingdata' => '#GETTING_DATA'
101 );
102
103
116 public static function setCompatibilityMode($compatibilityMode) {
117 if (($compatibilityMode == self::COMPATIBILITY_EXCEL) ||
118 ($compatibilityMode == self::COMPATIBILITY_GNUMERIC) ||
119 ($compatibilityMode == self::COMPATIBILITY_OPENOFFICE)) {
120 self::$compatibilityMode = $compatibilityMode;
121 return True;
122 }
123 return False;
124 } // function setCompatibilityMode()
125
126
138 public static function getCompatibilityMode() {
140 } // function getCompatibilityMode()
141
142
155 public static function setReturnDateType($returnDateType) {
156 if (($returnDateType == self::RETURNDATE_PHP_NUMERIC) ||
157 ($returnDateType == self::RETURNDATE_PHP_OBJECT) ||
158 ($returnDateType == self::RETURNDATE_EXCEL)) {
159 self::$ReturnDateType = $returnDateType;
160 return True;
161 }
162 return False;
163 } // function setReturnDateType()
164
165
177 public static function getReturnDateType() {
179 } // function getReturnDateType()
180
181
189 public static function DUMMY() {
190 return '#Not Yet Implemented';
191 } // function DUMMY()
192
193
201 public static function DIV0() {
202 return self::$_errorCodes['divisionbyzero'];
203 } // function DIV0()
204
205
219 public static function NA() {
220 return self::$_errorCodes['na'];
221 } // function NA()
222
223
233 public static function NaN() {
234 return self::$_errorCodes['num'];
235 } // function NaN()
236
237
247 public static function NAME() {
248 return self::$_errorCodes['name'];
249 } // function NAME()
250
251
261 public static function REF() {
262 return self::$_errorCodes['reference'];
263 } // function REF()
264
265
275 public static function NULL() {
276 return self::$_errorCodes['null'];
277 } // function NULL()
278
279
289 public static function VALUE() {
290 return self::$_errorCodes['value'];
291 } // function VALUE()
292
293
294 public static function isMatrixValue($idx) {
295 return ((substr_count($idx,'.') <= 1) || (preg_match('/\.[A-Z]/',$idx) > 0));
296 }
297
298
299 public static function isValue($idx) {
300 return (substr_count($idx,'.') == 0);
301 }
302
303
304 public static function isCellValue($idx) {
305 return (substr_count($idx,'.') > 1);
306 }
307
308
309 public static function _ifCondition($condition) {
311 if (!isset($condition{0}))
312 $condition = '=""';
313 if (!in_array($condition{0},array('>', '<', '='))) {
314 if (!is_numeric($condition)) { $condition = PHPExcel_Calculation::_wrapResult(strtoupper($condition)); }
315 return '='.$condition;
316 } else {
317 preg_match('/([<>=]+)(.*)/',$condition,$matches);
318 list(,$operator,$operand) = $matches;
319
320 if (!is_numeric($operand)) {
321 $operand = str_replace('"', '""', $operand);
322 $operand = PHPExcel_Calculation::_wrapResult(strtoupper($operand));
323 }
324
325 return $operator.$operand;
326 }
327 } // function _ifCondition()
328
329
336 public static function ERROR_TYPE($value = '') {
337 $value = self::flattenSingleValue($value);
338
339 $i = 1;
340 foreach(self::$_errorCodes as $errorCode) {
341 if ($value === $errorCode) {
342 return $i;
343 }
344 ++$i;
345 }
346 return self::NA();
347 } // function ERROR_TYPE()
348
349
356 public static function IS_BLANK($value = NULL) {
357 if (!is_null($value)) {
358 $value = self::flattenSingleValue($value);
359 }
360
361 return is_null($value);
362 } // function IS_BLANK()
363
364
371 public static function IS_ERR($value = '') {
372 $value = self::flattenSingleValue($value);
373
374 return self::IS_ERROR($value) && (!self::IS_NA($value));
375 } // function IS_ERR()
376
377
384 public static function IS_ERROR($value = '') {
385 $value = self::flattenSingleValue($value);
386
387 if (!is_string($value))
388 return false;
389 return in_array($value, array_values(self::$_errorCodes));
390 } // function IS_ERROR()
391
392
399 public static function IS_NA($value = '') {
400 $value = self::flattenSingleValue($value);
401
402 return ($value === self::NA());
403 } // function IS_NA()
404
405
412 public static function IS_EVEN($value = NULL) {
413 $value = self::flattenSingleValue($value);
414
415 if ($value === NULL)
416 return self::NAME();
417 if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value))))
418 return self::VALUE();
419 return ($value % 2 == 0);
420 } // function IS_EVEN()
421
422
429 public static function IS_ODD($value = NULL) {
430 $value = self::flattenSingleValue($value);
431
432 if ($value === NULL)
433 return self::NAME();
434 if ((is_bool($value)) || ((is_string($value)) && (!is_numeric($value))))
435 return self::VALUE();
436 return (abs($value) % 2 == 1);
437 } // function IS_ODD()
438
439
446 public static function IS_NUMBER($value = NULL) {
447 $value = self::flattenSingleValue($value);
448
449 if (is_string($value)) {
450 return False;
451 }
452 return is_numeric($value);
453 } // function IS_NUMBER()
454
455
462 public static function IS_LOGICAL($value = NULL) {
463 $value = self::flattenSingleValue($value);
464
465 return is_bool($value);
466 } // function IS_LOGICAL()
467
468
475 public static function IS_TEXT($value = NULL) {
476 $value = self::flattenSingleValue($value);
477
478 return (is_string($value) && !self::IS_ERROR($value));
479 } // function IS_TEXT()
480
481
488 public static function IS_NONTEXT($value = NULL) {
489 return !self::IS_TEXT($value);
490 } // function IS_NONTEXT()
491
492
498 public static function VERSION() {
499 return 'PHPExcel 1.8.1, 2015-04-30';
500 } // function VERSION()
501
502
518 public static function N($value = NULL) {
519 while (is_array($value)) {
520 $value = array_shift($value);
521 }
522
523 switch (gettype($value)) {
524 case 'double' :
525 case 'float' :
526 case 'integer' :
527 return $value;
528 break;
529 case 'boolean' :
530 return (integer) $value;
531 break;
532 case 'string' :
533 // Errors
534 if ((strlen($value) > 0) && ($value{0} == '#')) {
535 return $value;
536 }
537 break;
538 }
539 return 0;
540 } // function N()
541
542
557 public static function TYPE($value = NULL) {
558 $value = self::flattenArrayIndexed($value);
559 if (is_array($value) && (count($value) > 1)) {
560 $a = array_keys($value);
561 $a = array_pop($a);
562 // Range of cells is an error
563 if (self::isCellValue($a)) {
564 return 16;
565 // Test for Matrix
566 } elseif (self::isMatrixValue($a)) {
567 return 64;
568 }
569 } elseif(empty($value)) {
570 // Empty Cell
571 return 1;
572 }
573 $value = self::flattenSingleValue($value);
574
575 if (($value === NULL) || (is_float($value)) || (is_int($value))) {
576 return 1;
577 } elseif(is_bool($value)) {
578 return 4;
579 } elseif(is_array($value)) {
580 return 64;
581 } elseif(is_string($value)) {
582 // Errors
583 if ((strlen($value) > 0) && ($value{0} == '#')) {
584 return 16;
585 }
586 return 2;
587 }
588 return 0;
589 } // function TYPE()
590
591
598 public static function flattenArray($array) {
599 if (!is_array($array)) {
600 return (array) $array;
601 }
602
603 $arrayValues = array();
604 foreach ($array as $value) {
605 if (is_array($value)) {
606 foreach ($value as $val) {
607 if (is_array($val)) {
608 foreach ($val as $v) {
609 $arrayValues[] = $v;
610 }
611 } else {
612 $arrayValues[] = $val;
613 }
614 }
615 } else {
616 $arrayValues[] = $value;
617 }
618 }
619
620 return $arrayValues;
621 } // function flattenArray()
622
623
630 public static function flattenArrayIndexed($array) {
631 if (!is_array($array)) {
632 return (array) $array;
633 }
634
635 $arrayValues = array();
636 foreach ($array as $k1 => $value) {
637 if (is_array($value)) {
638 foreach ($value as $k2 => $val) {
639 if (is_array($val)) {
640 foreach ($val as $k3 => $v) {
641 $arrayValues[$k1.'.'.$k2.'.'.$k3] = $v;
642 }
643 } else {
644 $arrayValues[$k1.'.'.$k2] = $val;
645 }
646 }
647 } else {
648 $arrayValues[$k1] = $value;
649 }
650 }
651
652 return $arrayValues;
653 } // function flattenArrayIndexed()
654
655
662 public static function flattenSingleValue($value = '') {
663 while (is_array($value)) {
664 $value = array_pop($value);
665 }
666
667 return $value;
668 } // function flattenSingleValue()
669
670} // class PHPExcel_Calculation_Functions
671
672
673//
674// There are a few mathematical functions that aren't available on all versions of PHP for all platforms
675// These functions aren't available in Windows implementations of PHP prior to version 5.3.0
676// So we test if they do exist for this version of PHP/operating platform; and if not we create them
677//
678if (!function_exists('acosh')) {
679 function acosh($x) {
680 return 2 * log(sqrt(($x + 1) / 2) + sqrt(($x - 1) / 2));
681 } // function acosh()
682}
683
684if (!function_exists('asinh')) {
685 function asinh($x) {
686 return log($x + sqrt(1 + $x * $x));
687 } // function asinh()
688}
689
690if (!function_exists('atanh')) {
691 function atanh($x) {
692 return (log(1 + $x) - log(1 - $x)) / 2;
693 } // function atanh()
694}
695
696
697//
698// Strangely, PHP doesn't have a mb_str_replace multibyte function
699// As we'll only ever use this function with UTF-8 characters, we can simply "hard-code" the character set
700//
701if ((!function_exists('mb_str_replace')) &&
702 (function_exists('mb_substr')) && (function_exists('mb_strlen')) && (function_exists('mb_strpos'))) {
703 function mb_str_replace($search, $replace, $subject) {
704 if(is_array($subject)) {
705 $ret = array();
706 foreach($subject as $key => $val) {
707 $ret[$key] = mb_str_replace($search, $replace, $val);
708 }
709 return $ret;
710 }
711
712 foreach((array) $search as $key => $s) {
713 if($s == '' && $s !== 0) {
714 continue;
715 }
716 $r = !is_array($replace) ? $replace : (array_key_exists($key, $replace) ? $replace[$key] : '');
717 $pos = mb_strpos($subject, $s, 0, 'UTF-8');
718 while($pos !== false) {
719 $subject = mb_substr($subject, 0, $pos, 'UTF-8') . $r . mb_substr($subject, $pos + mb_strlen($s, 'UTF-8'), 65535, 'UTF-8');
720 $pos = mb_strpos($subject, $s, $pos + mb_strlen($r, 'UTF-8'), 'UTF-8');
721 }
722 }
723 return $subject;
724 }
725}
An exception for terminatinating execution or to throw for unit testing.
static IS_TEXT($value=NULL)
IS_TEXT.
Definition: Functions.php:475
static _ifCondition($condition)
Definition: Functions.php:309
static IS_NUMBER($value=NULL)
IS_NUMBER.
Definition: Functions.php:446
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:662
static IS_NONTEXT($value=NULL)
IS_NONTEXT.
Definition: Functions.php:488
static setReturnDateType($returnDateType)
Definition: Functions.php:155
static IS_LOGICAL($value=NULL)
IS_LOGICAL.
Definition: Functions.php:462
static IS_ERR($value='')
IS_ERR.
Definition: Functions.php:371
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:598
const COMPATIBILITY_EXCEL
constants
Definition: Functions.php:62
static IS_BLANK($value=NULL)
IS_BLANK.
Definition: Functions.php:356
static setCompatibilityMode($compatibilityMode)
Definition: Functions.php:116
static IS_ODD($value=NULL)
IS_ODD.
Definition: Functions.php:429
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing.
Definition: Functions.php:630
static ERROR_TYPE($value='')
ERROR_TYPE.
Definition: Functions.php:336
static IS_ERROR($value='')
IS_ERROR.
Definition: Functions.php:384
static IS_NA($value='')
IS_NA.
Definition: Functions.php:399
static IS_EVEN($value=NULL)
IS_EVEN.
Definition: Functions.php:412
static N($value=NULL)
N.
Definition: Functions.php:518
static TYPE($value=NULL)
TYPE.
Definition: Functions.php:557
static _wrapResult($value)
Wrap string values in quotes.
$x
Definition: example_009.php:98
$r
Definition: example_031.php:79
$ret
Definition: parser.php:6
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27