ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
DiscISAM.php
Go to the documentation of this file.
1 <?php
37 
38  private $_fileName = null;
39  private $_fileHandle = null;
40 
41 
42  private function _storeData() {
43  $this->_currentObject->detach();
44 
45  fseek($this->_fileHandle,0,SEEK_END);
46  $offset = ftell($this->_fileHandle);
47  fwrite($this->_fileHandle, serialize($this->_currentObject));
48  $this->_cellCache[$this->_currentObjectID] = array('ptr' => $offset,
49  'sz' => ftell($this->_fileHandle) - $offset
50  );
51  $this->_currentObjectID = $this->_currentObject = null;
52  } // function _storeData()
53 
54 
63  public function addCacheData($pCoord, PHPExcel_Cell $cell) {
64  if (($pCoord !== $this->_currentObjectID) && ($this->_currentObjectID !== null)) {
65  $this->_storeData();
66  }
67 
68  $this->_currentObjectID = $pCoord;
69  $this->_currentObject = $cell;
70 
71  return $cell;
72  } // function addCacheData()
73 
74 
82  public function getCacheData($pCoord) {
83  if ($pCoord === $this->_currentObjectID) {
84  return $this->_currentObject;
85  }
86  $this->_storeData();
87 
88  // Check if the entry that has been requested actually exists
89  if (!isset($this->_cellCache[$pCoord])) {
90  // Return null if requested entry doesn't exist in cache
91  return null;
92  }
93 
94  // Set current entry to the requested entry
95  $this->_currentObjectID = $pCoord;
96  fseek($this->_fileHandle,$this->_cellCache[$pCoord]['ptr']);
97  $this->_currentObject = unserialize(fread($this->_fileHandle,$this->_cellCache[$pCoord]['sz']));
98  // Re-attach the parent worksheet
99  $this->_currentObject->attach($this->_parent);
100 
101  // Return requested entry
102  return $this->_currentObject;
103  } // function getCacheData()
104 
105 
111  public function copyCellCollection(PHPExcel_Worksheet $parent) {
113  // Get a new id for the new file name
114  $baseUnique = $this->_getUniqueID();
115  $newFileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
116  // Copy the existing cell cache file
117  copy ($this->_fileName,$newFileName);
118  $this->_fileName = $newFileName;
119  // Open the copied cell cache file
120  $this->_fileHandle = fopen($this->_fileName,'a+');
121  } // function copyCellCollection()
122 
123 
124  public function unsetWorksheetCells() {
125  if(!is_null($this->_currentObject)) {
126  $this->_currentObject->detach();
127  $this->_currentObject = $this->_currentObjectID = null;
128  }
129  $this->_cellCache = array();
130 
131  // detach ourself from the worksheet, so that it can then delete this object successfully
132  $this->_parent = null;
133 
134  // Close down the temporary cache file
135  $this->__destruct();
136  } // function unsetWorksheetCells()
137 
138 
139  public function __construct(PHPExcel_Worksheet $parent) {
140  parent::__construct($parent);
141  if (is_null($this->_fileHandle)) {
142  $baseUnique = $this->_getUniqueID();
143  $this->_fileName = PHPExcel_Shared_File::sys_get_temp_dir().'/PHPExcel.'.$baseUnique.'.cache';
144  $this->_fileHandle = fopen($this->_fileName,'a+');
145  }
146  } // function __construct()
147 
148 
149  public function __destruct() {
150  if (!is_null($this->_fileHandle)) {
151  fclose($this->_fileHandle);
152  unlink($this->_fileName);
153  }
154  $this->_fileHandle = null;
155  } // function __destruct()
156 
157 }