ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Protection.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
39 
40 
49 {
51  const PROTECTION_INHERIT = 'inherit';
52  const PROTECTION_PROTECTED = 'protected';
53  const PROTECTION_UNPROTECTED = 'unprotected';
54 
60  private $_locked;
61 
67  private $_hidden;
68 
75 
81  private $_isSupervisor;
82 
88  private $_parent;
89 
93  public function __construct($isSupervisor = false)
94  {
95  // Supervisor?
96  $this->_isSupervisor = $isSupervisor;
97 
98  // Initialise values
99  $this->_locked = self::PROTECTION_INHERIT;
100  $this->_hidden = self::PROTECTION_INHERIT;
101  }
102 
109  public function bindParent($parent)
110  {
111  $this->_parent = $parent;
112  return $this;
113  }
114 
120  public function getIsSupervisor()
121  {
122  return $this->_isSupervisor;
123  }
124 
131  public function getSharedComponent()
132  {
133  return $this->_parent->getSharedComponent()->getProtection();
134  }
135 
141  public function getActiveSheet()
142  {
143  return $this->_parent->getActiveSheet();
144  }
145 
152  public function getXSelectedCells()
153  {
154  return $this->getActiveSheet()->getXSelectedCells();
155  }
156 
163  public function getXActiveCell()
164  {
165  return $this->getActiveSheet()->getXActiveCell();
166  }
167 
174  public function getStyleArray($array)
175  {
176  return array('protection' => $array);
177  }
178 
190  public function applyFromArray($pStyles = null) {
191  if (is_array($pStyles)) {
192  if ($this->_isSupervisor) {
193  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
194  } else {
195  if (array_key_exists('locked', $pStyles)) {
196  $this->setLocked($pStyles['locked']);
197  }
198  if (array_key_exists('hidden', $pStyles)) {
199  $this->setHidden($pStyles['hidden']);
200  }
201  }
202  } else {
203  throw new Exception("Invalid style array passed.");
204  }
205  return $this;
206  }
207 
213  public function getLocked() {
214  if ($this->_isSupervisor) {
215  return $this->getSharedComponent()->getLocked();
216  }
217  return $this->_locked;
218  }
219 
226  public function setLocked($pValue = self::PROTECTION_INHERIT) {
227  if ($this->_isSupervisor) {
228  $styleArray = $this->getStyleArray(array('locked' => $pValue));
229  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
230  } else {
231  $this->_locked = $pValue;
232  }
233  return $this;
234  }
235 
241  public function getHidden() {
242  if ($this->_isSupervisor) {
243  return $this->getSharedComponent()->getHidden();
244  }
245  return $this->_hidden;
246  }
247 
254  public function setHidden($pValue = self::PROTECTION_INHERIT) {
255  if ($this->_isSupervisor) {
256  $styleArray = $this->getStyleArray(array('hidden' => $pValue));
257  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
258  } else {
259  $this->_hidden = $pValue;
260  }
261  return $this;
262  }
263 
269  public function getHashCode() {
270  if ($this->_isSupervisor) {
271  return $this->getSharedComponent()->getHashCode();
272  }
273  return md5(
274  $this->_locked
275  . $this->_hidden
276  . __CLASS__
277  );
278  }
279 
285  private $_hashIndex;
286 
295  public function getHashIndex() {
296  return $this->_hashIndex;
297  }
298 
307  public function setHashIndex($value) {
308  $this->_hashIndex = $value;
309  }
310 
314  public function __clone() {
315  $vars = get_object_vars($this);
316  foreach ($vars as $key => $value) {
317  if (is_object($value)) {
318  $this->$key = clone $value;
319  } else {
320  $this->$key = $value;
321  }
322  }
323  }
324 }