Updated gui for user facility settings (#1327)
[openemr.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Calculation / Logical.php
blob48fdb17f4e2413433d2b8d97e8cea4cd987002f2
1 <?php
2 /**
3 * PHPExcel
5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * @category PHPExcel
22 * @package PHPExcel_Calculation
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 /** PHPExcel root directory */
30 if (!defined('PHPEXCEL_ROOT')) {
31 /**
32 * @ignore
34 define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
39 /**
40 * PHPExcel_Calculation_Logical
42 * @category PHPExcel
43 * @package PHPExcel_Calculation
44 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
46 class PHPExcel_Calculation_Logical {
48 /**
49 * TRUE
51 * Returns the boolean TRUE.
53 * Excel Function:
54 * =TRUE()
56 * @access public
57 * @category Logical Functions
58 * @return boolean True
60 public static function TRUE() {
61 return TRUE;
62 } // function TRUE()
65 /**
66 * FALSE
68 * Returns the boolean FALSE.
70 * Excel Function:
71 * =FALSE()
73 * @access public
74 * @category Logical Functions
75 * @return boolean False
77 public static function FALSE() {
78 return FALSE;
79 } // function FALSE()
82 /**
83 * LOGICAL_AND
85 * Returns boolean TRUE if all its arguments are TRUE; returns FALSE if one or more argument is FALSE.
87 * Excel Function:
88 * =AND(logical1[,logical2[, ...]])
90 * The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
91 * or references that contain logical values.
93 * Boolean arguments are treated as True or False as appropriate
94 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
95 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
96 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
98 * @access public
99 * @category Logical Functions
100 * @param mixed $arg,... Data values
101 * @return boolean The logical AND of the arguments.
103 public static function LOGICAL_AND() {
104 // Return value
105 $returnValue = TRUE;
107 // Loop through the arguments
108 $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
109 $argCount = -1;
110 foreach ($aArgs as $argCount => $arg) {
111 // Is it a boolean value?
112 if (is_bool($arg)) {
113 $returnValue = $returnValue && $arg;
114 } elseif ((is_numeric($arg)) && (!is_string($arg))) {
115 $returnValue = $returnValue && ($arg != 0);
116 } elseif (is_string($arg)) {
117 $arg = strtoupper($arg);
118 if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
119 $arg = TRUE;
120 } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
121 $arg = FALSE;
122 } else {
123 return PHPExcel_Calculation_Functions::VALUE();
125 $returnValue = $returnValue && ($arg != 0);
129 // Return
130 if ($argCount < 0) {
131 return PHPExcel_Calculation_Functions::VALUE();
133 return $returnValue;
134 } // function LOGICAL_AND()
138 * LOGICAL_OR
140 * Returns boolean TRUE if any argument is TRUE; returns FALSE if all arguments are FALSE.
142 * Excel Function:
143 * =OR(logical1[,logical2[, ...]])
145 * The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays
146 * or references that contain logical values.
148 * Boolean arguments are treated as True or False as appropriate
149 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
150 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
151 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
153 * @access public
154 * @category Logical Functions
155 * @param mixed $arg,... Data values
156 * @return boolean The logical OR of the arguments.
158 public static function LOGICAL_OR() {
159 // Return value
160 $returnValue = FALSE;
162 // Loop through the arguments
163 $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());
164 $argCount = -1;
165 foreach ($aArgs as $argCount => $arg) {
166 // Is it a boolean value?
167 if (is_bool($arg)) {
168 $returnValue = $returnValue || $arg;
169 } elseif ((is_numeric($arg)) && (!is_string($arg))) {
170 $returnValue = $returnValue || ($arg != 0);
171 } elseif (is_string($arg)) {
172 $arg = strtoupper($arg);
173 if (($arg == 'TRUE') || ($arg == PHPExcel_Calculation::getTRUE())) {
174 $arg = TRUE;
175 } elseif (($arg == 'FALSE') || ($arg == PHPExcel_Calculation::getFALSE())) {
176 $arg = FALSE;
177 } else {
178 return PHPExcel_Calculation_Functions::VALUE();
180 $returnValue = $returnValue || ($arg != 0);
184 // Return
185 if ($argCount < 0) {
186 return PHPExcel_Calculation_Functions::VALUE();
188 return $returnValue;
189 } // function LOGICAL_OR()
193 * NOT
195 * Returns the boolean inverse of the argument.
197 * Excel Function:
198 * =NOT(logical)
200 * The argument must evaluate to a logical value such as TRUE or FALSE
202 * Boolean arguments are treated as True or False as appropriate
203 * Integer or floating point arguments are treated as True, except for 0 or 0.0 which are False
204 * If any argument value is a string, or a Null, the function returns a #VALUE! error, unless the string holds
205 * the value TRUE or FALSE, in which case it is evaluated as the corresponding boolean value
207 * @access public
208 * @category Logical Functions
209 * @param mixed $logical A value or expression that can be evaluated to TRUE or FALSE
210 * @return boolean The boolean inverse of the argument.
212 public static function NOT($logical=FALSE) {
213 $logical = PHPExcel_Calculation_Functions::flattenSingleValue($logical);
214 if (is_string($logical)) {
215 $logical = strtoupper($logical);
216 if (($logical == 'TRUE') || ($logical == PHPExcel_Calculation::getTRUE())) {
217 return FALSE;
218 } elseif (($logical == 'FALSE') || ($logical == PHPExcel_Calculation::getFALSE())) {
219 return TRUE;
220 } else {
221 return PHPExcel_Calculation_Functions::VALUE();
225 return !$logical;
226 } // function NOT()
229 * STATEMENT_IF
231 * Returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE.
233 * Excel Function:
234 * =IF(condition[,returnIfTrue[,returnIfFalse]])
236 * Condition is any value or expression that can be evaluated to TRUE or FALSE.
237 * For example, A10=100 is a logical expression; if the value in cell A10 is equal to 100,
238 * the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE.
239 * This argument can use any comparison calculation operator.
240 * ReturnIfTrue is the value that is returned if condition evaluates to TRUE.
241 * For example, if this argument is the text string "Within budget" and the condition argument evaluates to TRUE,
242 * then the IF function returns the text "Within budget"
243 * If condition is TRUE and ReturnIfTrue is blank, this argument returns 0 (zero). To display the word TRUE, use
244 * the logical value TRUE for this argument.
245 * ReturnIfTrue can be another formula.
246 * ReturnIfFalse is the value that is returned if condition evaluates to FALSE.
247 * For example, if this argument is the text string "Over budget" and the condition argument evaluates to FALSE,
248 * then the IF function returns the text "Over budget".
249 * If condition is FALSE and ReturnIfFalse is omitted, then the logical value FALSE is returned.
250 * If condition is FALSE and ReturnIfFalse is blank, then the value 0 (zero) is returned.
251 * ReturnIfFalse can be another formula.
253 * @access public
254 * @category Logical Functions
255 * @param mixed $condition Condition to evaluate
256 * @param mixed $returnIfTrue Value to return when condition is true
257 * @param mixed $returnIfFalse Optional value to return when condition is false
258 * @return mixed The value of returnIfTrue or returnIfFalse determined by condition
260 public static function STATEMENT_IF($condition = TRUE, $returnIfTrue = 0, $returnIfFalse = FALSE) {
261 $condition = (is_null($condition)) ? TRUE : (boolean) PHPExcel_Calculation_Functions::flattenSingleValue($condition);
262 $returnIfTrue = (is_null($returnIfTrue)) ? 0 : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfTrue);
263 $returnIfFalse = (is_null($returnIfFalse)) ? FALSE : PHPExcel_Calculation_Functions::flattenSingleValue($returnIfFalse);
265 return ($condition) ? $returnIfTrue : $returnIfFalse;
266 } // function STATEMENT_IF()
270 * IFERROR
272 * Excel Function:
273 * =IFERROR(testValue,errorpart)
275 * @access public
276 * @category Logical Functions
277 * @param mixed $testValue Value to check, is also the value returned when no error
278 * @param mixed $errorpart Value to return when testValue is an error condition
279 * @return mixed The value of errorpart or testValue determined by error condition
281 public static function IFERROR($testValue = '', $errorpart = '') {
282 $testValue = (is_null($testValue)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($testValue);
283 $errorpart = (is_null($errorpart)) ? '' : PHPExcel_Calculation_Functions::flattenSingleValue($errorpart);
285 return self::STATEMENT_IF(PHPExcel_Calculation_Functions::IS_ERROR($testValue), $errorpart, $testValue);
286 } // function IFERROR()
288 } // class PHPExcel_Calculation_Logical