ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
DataSeriesValues.php
Go to the documentation of this file.
1<?php
37{
38
39 const DATASERIES_TYPE_STRING = 'String';
40 const DATASERIES_TYPE_NUMBER = 'Number';
41
42 private static $_dataTypeValues = array(
43 self::DATASERIES_TYPE_STRING,
44 self::DATASERIES_TYPE_NUMBER,
45 );
46
52 private $_dataType = null;
53
59 private $_dataSource = null;
60
66 private $_formatCode = null;
67
73 private $_marker = null;
74
80 private $_pointCount = 0;
81
87 private $_dataValues = array();
88
92 public function __construct($dataType = self::DATASERIES_TYPE_NUMBER, $dataSource = null, $formatCode = null, $pointCount = 0, $dataValues = array(), $marker = null)
93 {
94 $this->setDataType($dataType);
95 $this->_dataSource = $dataSource;
96 $this->_formatCode = $formatCode;
97 $this->_pointCount = $pointCount;
98 $this->_dataValues = $dataValues;
99 $this->_marker = $marker;
100 }
101
107 public function getDataType() {
108 return $this->_dataType;
109 }
110
122 public function setDataType($dataType = self::DATASERIES_TYPE_NUMBER) {
123 if (!in_array($dataType, self::$_dataTypeValues)) {
124 throw new PHPExcel_Chart_Exception('Invalid datatype for chart data series values');
125 }
126 $this->_dataType = $dataType;
127
128 return $this;
129 }
130
136 public function getDataSource() {
137 return $this->_dataSource;
138 }
139
146 public function setDataSource($dataSource = null, $refreshDataValues = true) {
147 $this->_dataSource = $dataSource;
148
149 if ($refreshDataValues) {
150 // TO DO
151 }
152
153 return $this;
154 }
155
161 public function getPointMarker() {
162 return $this->_marker;
163 }
164
171 public function setPointMarker($marker = null) {
172 $this->_marker = $marker;
173
174 return $this;
175 }
176
182 public function getFormatCode() {
183 return $this->_formatCode;
184 }
185
192 public function setFormatCode($formatCode = null) {
193 $this->_formatCode = $formatCode;
194
195 return $this;
196 }
197
203 public function getPointCount() {
204 return $this->_pointCount;
205 }
206
212 public function isMultiLevelSeries() {
213 if (count($this->_dataValues) > 0) {
214 return is_array($this->_dataValues[0]);
215 }
216 return null;
217 }
218
224 public function multiLevelCount() {
225 $levelCount = 0;
226 foreach($this->_dataValues as $dataValueSet) {
227 $levelCount = max($levelCount,count($dataValueSet));
228 }
229 return $levelCount;
230 }
231
237 public function getDataValues() {
238 return $this->_dataValues;
239 }
240
246 public function getDataValue() {
247 $count = count($this->_dataValues);
248 if ($count == 0) {
249 return null;
250 } elseif ($count == 1) {
251 return $this->_dataValues[0];
252 }
253 return $this->_dataValues;
254 }
255
265 public function setDataValues($dataValues = array(), $refreshDataSource = TRUE) {
266 $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($dataValues);
267 $this->_pointCount = count($dataValues);
268
269 if ($refreshDataSource) {
270 // TO DO
271 }
272
273 return $this;
274 }
275
276 private function _stripNulls($var) {
277 return $var !== NULL;
278 }
279
280 public function refresh(PHPExcel_Worksheet $worksheet, $flatten = TRUE) {
281 if ($this->_dataSource !== NULL) {
282 $calcEngine = PHPExcel_Calculation::getInstance($worksheet->getParent());
284 $calcEngine->_calculateFormulaValue(
285 '='.$this->_dataSource,
286 NULL,
287 $worksheet->getCell('A1')
288 )
289 );
290 if ($flatten) {
291 $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
292 foreach($this->_dataValues as &$dataValue) {
293 if ((!empty($dataValue)) && ($dataValue[0] == '#')) {
294 $dataValue = 0.0;
295 }
296 }
297 unset($dataValue);
298 } else {
299 $cellRange = explode('!',$this->_dataSource);
300 if (count($cellRange) > 1) {
301 list(,$cellRange) = $cellRange;
302 }
303
304 $dimensions = PHPExcel_Cell::rangeDimension(str_replace('$','',$cellRange));
305 if (($dimensions[0] == 1) || ($dimensions[1] == 1)) {
306 $this->_dataValues = PHPExcel_Calculation_Functions::flattenArray($newDataValues);
307 } else {
308 $newArray = array_values(array_shift($newDataValues));
309 foreach($newArray as $i => $newDataSet) {
310 $newArray[$i] = array($newDataSet);
311 }
312
313 foreach($newDataValues as $newDataSet) {
314 $i = 0;
315 foreach($newDataSet as $newDataVal) {
316 array_unshift($newArray[$i++],$newDataVal);
317 }
318 }
319 $this->_dataValues = $newArray;
320 }
321 }
322 $this->_pointCount = count($this->_dataValues);
323 }
324
325 }
326
327}
$worksheet
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:598
static getInstance(PHPExcel $workbook=NULL)
Get an instance of this class.
static _unwrapResult($value)
Remove quotes used as a wrapper to identify string values.
static rangeDimension($pRange='A1:A1')
Calculate range dimension.
Definition: Cell.php:741
__construct($dataType=self::DATASERIES_TYPE_NUMBER, $dataSource=null, $formatCode=null, $pointCount=0, $dataValues=array(), $marker=null)
Create a new PHPExcel_Chart_DataSeriesValues object.
setDataSource($dataSource=null, $refreshDataValues=true)
Set Series Data Source (formula)
getFormatCode()
Get Series Format Code.
getPointCount()
Get Series Point Count.
getDataValues()
Get Series Data Values.
getDataSource()
Get Series Data Source (formula)
setDataValues($dataValues=array(), $refreshDataSource=TRUE)
Set Series Data Values.
getDataValue()
Get the first Series Data value.
isMultiLevelSeries()
Identify if the Data Series is a multi-level or a simple series.
getDataType()
Get Series Data Type.
setPointMarker($marker=null)
Set Point Marker.
setFormatCode($formatCode=null)
Set Series Format Code.
refresh(PHPExcel_Worksheet $worksheet, $flatten=TRUE)
setDataType($dataType=self::DATASERIES_TYPE_NUMBER)
Set Series Data Type.
multiLevelCount()
Return the level count of a multi-level Data Series.