ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
CacheBase.php
Go to the documentation of this file.
1<?php
37
43 protected $_parent;
44
50 protected $_currentObject = null;
51
57 protected $_currentObjectID = null;
58
59
65 protected $_currentCellIsDirty = true;
66
73 protected $_cellCache = array();
74
75
81 public function __construct(PHPExcel_Worksheet $parent) {
82 // Set our parent worksheet.
83 // This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
84 // they are woken from a serialized state
85 $this->_parent = $parent;
86 } // function __construct()
87
88
94 public function getParent()
95 {
96 return $this->_parent;
97 }
98
105 public function isDataSet($pCoord) {
106 if ($pCoord === $this->_currentObjectID) {
107 return true;
108 }
109 // Check if the requested entry exists in the cache
110 return isset($this->_cellCache[$pCoord]);
111 } // function isDataSet()
112
113
121 public function moveCell($fromAddress, $toAddress) {
122 if ($fromAddress === $this->_currentObjectID) {
123 $this->_currentObjectID = $toAddress;
124 }
125 $this->_currentCellIsDirty = true;
126 if (isset($this->_cellCache[$fromAddress])) {
127 $this->_cellCache[$toAddress] = &$this->_cellCache[$fromAddress];
128 unset($this->_cellCache[$fromAddress]);
129 }
130
131 return TRUE;
132 } // function moveCell()
133
134
142 public function updateCacheData(PHPExcel_Cell $cell) {
143 return $this->addCacheData($cell->getCoordinate(),$cell);
144 } // function updateCacheData()
145
146
153 public function deleteCacheData($pCoord) {
154 if ($pCoord === $this->_currentObjectID && !is_null($this->_currentObject)) {
155 $this->_currentObject->detach();
156 $this->_currentObjectID = $this->_currentObject = null;
157 }
158
159 if (is_object($this->_cellCache[$pCoord])) {
160 $this->_cellCache[$pCoord]->detach();
161 unset($this->_cellCache[$pCoord]);
162 }
163 $this->_currentCellIsDirty = false;
164 } // function deleteCacheData()
165
166
172 public function getCellList() {
173 return array_keys($this->_cellCache);
174 } // function getCellList()
175
176
182 public function getSortedCellList() {
183 $sortKeys = array();
184 foreach ($this->getCellList() as $coord) {
185 sscanf($coord,'%[A-Z]%d', $column, $row);
186 $sortKeys[sprintf('%09d%3s',$row,$column)] = $coord;
187 }
188 ksort($sortKeys);
189
190 return array_values($sortKeys);
191 } // function sortCellList()
192
193
194
200 public function getHighestRowAndColumn()
201 {
202 // Lookup highest column and highest row
203 $col = array('A' => '1A');
204 $row = array(1);
205 foreach ($this->getCellList() as $coord) {
206 sscanf($coord,'%[A-Z]%d', $c, $r);
207 $row[$r] = $r;
208 $col[$c] = strlen($c).$c;
209 }
210 if (!empty($row)) {
211 // Determine highest column and row
212 $highestRow = max($row);
213 $highestColumn = substr(max($col),1);
214 }
215
216 return array( 'row' => $highestRow,
217 'column' => $highestColumn
218 );
219 }
220
221
227 public function getCurrentAddress()
228 {
230 }
231
237 public function getCurrentColumn()
238 {
239 sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
240 return $column;
241 }
242
248 public function getCurrentRow()
249 {
250 sscanf($this->_currentObjectID, '%[A-Z]%d', $column, $row);
251 return (integer) $row;
252 }
253
261 public function getHighestColumn($row = null)
262 {
263 if ($row == null) {
264 $colRow = $this->getHighestRowAndColumn();
265 return $colRow['column'];
266 }
267
268 $columnList = array(1);
269 foreach ($this->getCellList() as $coord) {
270 sscanf($coord,'%[A-Z]%d', $c, $r);
271 if ($r != $row) {
272 continue;
273 }
274 $columnList[] = PHPExcel_Cell::columnIndexFromString($c);
275 }
276 return PHPExcel_Cell::stringFromColumnIndex(max($columnList) - 1);
277 }
278
286 public function getHighestRow($column = null)
287 {
288 if ($column == null) {
289 $colRow = $this->getHighestRowAndColumn();
290 return $colRow['row'];
291 }
292
293 $rowList = array(0);
294 foreach ($this->getCellList() as $coord) {
295 sscanf($coord,'%[A-Z]%d', $c, $r);
296 if ($c != $column) {
297 continue;
298 }
299 $rowList[] = $r;
300 }
301
302 return max($rowList);
303 }
304
305
311 protected function _getUniqueID() {
312 if (function_exists('posix_getpid')) {
313 $baseUnique = posix_getpid();
314 } else {
315 $baseUnique = mt_rand();
316 }
317 return uniqid($baseUnique,true);
318 }
319
326 public function copyCellCollection(PHPExcel_Worksheet $parent) {
328 $this->_storeData();
329
330 $this->_parent = $parent;
331 if (($this->_currentObject !== NULL) && (is_object($this->_currentObject))) {
332 $this->_currentObject->attach($this);
333 }
334 } // function copyCellCollection()
335
342 public function removeRow($row) {
343 foreach ($this->getCellList() as $coord) {
344 sscanf($coord,'%[A-Z]%d', $c, $r);
345 if ($r == $row) {
346 $this->deleteCacheData($coord);
347 }
348 }
349 }
350
357 public function removeColumn($column) {
358 foreach ($this->getCellList() as $coord) {
359 sscanf($coord,'%[A-Z]%d', $c, $r);
360 if ($c == $column) {
361 $this->deleteCacheData($coord);
362 }
363 }
364 }
365
372 public static function cacheMethodIsAvailable() {
373 return true;
374 }
375
376}
sprintf('%.4f', $callTime)
$column
Definition: 39dropdown.php:62
An exception for terminatinating execution or to throw for unit testing.
getCellList()
Get a list of all cell addresses currently held in cache.
Definition: CacheBase.php:172
isDataSet($pCoord)
Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
Definition: CacheBase.php:105
getCurrentAddress()
Return the cell address of the currently active cell object.
Definition: CacheBase.php:227
__construct(PHPExcel_Worksheet $parent)
Initialise this new cell collection.
Definition: CacheBase.php:81
removeColumn($column)
Remove a column, deleting all cells in that column.
Definition: CacheBase.php:357
getCurrentRow()
Return the row address of the currently active cell object.
Definition: CacheBase.php:248
moveCell($fromAddress, $toAddress)
Move a cell object from one address to another.
Definition: CacheBase.php:121
static cacheMethodIsAvailable()
Identify whether the caching method is currently available Some methods are dependent on the availabi...
Definition: CacheBase.php:372
deleteCacheData($pCoord)
Delete a cell in cache identified by coordinate address.
Definition: CacheBase.php:153
copyCellCollection(PHPExcel_Worksheet $parent)
Clone the cell collection.
Definition: CacheBase.php:326
getParent()
Return the parent worksheet for this cell collection.
Definition: CacheBase.php:94
_getUniqueID()
Generate a unique ID for cache referencing.
Definition: CacheBase.php:311
getSortedCellList()
Sort the list of all cell addresses currently held in cache by row and column.
Definition: CacheBase.php:182
updateCacheData(PHPExcel_Cell $cell)
Add or Update a cell in cache.
Definition: CacheBase.php:142
getCurrentColumn()
Return the column address of the currently active cell object.
Definition: CacheBase.php:237
getHighestRowAndColumn()
Get highest worksheet column and highest row that have cell records.
Definition: CacheBase.php:200
removeRow($row)
Remove a row, deleting all cells in that row.
Definition: CacheBase.php:342
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
Definition: Cell.php:825
getCoordinate()
Get cell coordinate.
Definition: Cell.php:171
static columnIndexFromString($pString='A')
Column index from string.
Definition: Cell.php:782
$r
Definition: example_031.php:79
$toAddress