ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Counts.php
Go to the documentation of this file.
1<?php
2
4
6
7class Counts extends AggregateBase
8{
21 public static function COUNT(...$args)
22 {
23 $returnValue = 0;
24
25 // Loop through arguments
26 $aArgs = Functions::flattenArrayIndexed($args);
27 foreach ($aArgs as $k => $arg) {
28 $arg = self::testAcceptedBoolean($arg, $k);
29 // Is it a numeric value?
30 // Strings containing numeric values are only counted if they are string literals (not cell values)
31 // and then only in MS Excel and in Open Office, not in Gnumeric
32 if (self::isAcceptedCountable($arg, $k)) {
33 ++$returnValue;
34 }
35 }
36
37 return $returnValue;
38 }
39
52 public static function COUNTA(...$args)
53 {
54 $returnValue = 0;
55
56 // Loop through arguments
57 $aArgs = Functions::flattenArrayIndexed($args);
58 foreach ($aArgs as $k => $arg) {
59 // Nulls are counted if literals, but not if cell values
60 if ($arg !== null || (!Functions::isCellValue($k))) {
61 ++$returnValue;
62 }
63 }
64
65 return $returnValue;
66 }
67
80 public static function COUNTBLANK(...$args)
81 {
82 $returnValue = 0;
83
84 // Loop through arguments
85 $aArgs = Functions::flattenArray($args);
86 foreach ($aArgs as $arg) {
87 // Is it a blank cell?
88 if (($arg === null) || ((is_string($arg)) && ($arg == ''))) {
89 ++$returnValue;
90 }
91 }
92
93 return $returnValue;
94 }
95}
An exception for terminatinating execution or to throw for unit testing.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing.
Definition: Functions.php:616
static testAcceptedBoolean($arg, $k)
MS Excel does not count Booleans if passed as cell values, but they are counted if passed as literals...