ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
Protection.php
Go to the documentation of this file.
1 <?php
37 {
39  const PROTECTION_INHERIT = 'inherit';
40  const PROTECTION_PROTECTED = 'protected';
41  const PROTECTION_UNPROTECTED = 'unprotected';
42 
48  private $_locked;
49 
55  private $_hidden;
56 
63 
69  private $_isSupervisor;
70 
76  private $_parent;
77 
81  public function __construct($isSupervisor = false)
82  {
83  // Supervisor?
84  $this->_isSupervisor = $isSupervisor;
85 
86  // Initialise values
87  $this->_locked = self::PROTECTION_INHERIT;
88  $this->_hidden = self::PROTECTION_INHERIT;
89  }
90 
97  public function bindParent($parent)
98  {
99  $this->_parent = $parent;
100  return $this;
101  }
102 
108  public function getIsSupervisor()
109  {
110  return $this->_isSupervisor;
111  }
112 
119  public function getSharedComponent()
120  {
121  return $this->_parent->getSharedComponent()->getProtection();
122  }
123 
129  public function getActiveSheet()
130  {
131  return $this->_parent->getActiveSheet();
132  }
133 
140  public function getSelectedCells()
141  {
142  return $this->getActiveSheet()->getSelectedCells();
143  }
144 
151  public function getActiveCell()
152  {
153  return $this->getActiveSheet()->getActiveCell();
154  }
155 
162  public function getStyleArray($array)
163  {
164  return array('protection' => $array);
165  }
166 
178  public function applyFromArray($pStyles = null) {
179  if (is_array($pStyles)) {
180  if ($this->_isSupervisor) {
181  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
182  } else {
183  if (array_key_exists('locked', $pStyles)) {
184  $this->setLocked($pStyles['locked']);
185  }
186  if (array_key_exists('hidden', $pStyles)) {
187  $this->setHidden($pStyles['hidden']);
188  }
189  }
190  } else {
191  throw new Exception("Invalid style array passed.");
192  }
193  return $this;
194  }
195 
201  public function getLocked() {
202  if ($this->_isSupervisor) {
203  return $this->getSharedComponent()->getLocked();
204  }
205  return $this->_locked;
206  }
207 
214  public function setLocked($pValue = self::PROTECTION_INHERIT) {
215  if ($this->_isSupervisor) {
216  $styleArray = $this->getStyleArray(array('locked' => $pValue));
217  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
218  } else {
219  $this->_locked = $pValue;
220  }
221  return $this;
222  }
223 
229  public function getHidden() {
230  if ($this->_isSupervisor) {
231  return $this->getSharedComponent()->getHidden();
232  }
233  return $this->_hidden;
234  }
235 
242  public function setHidden($pValue = self::PROTECTION_INHERIT) {
243  if ($this->_isSupervisor) {
244  $styleArray = $this->getStyleArray(array('hidden' => $pValue));
245  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
246  } else {
247  $this->_hidden = $pValue;
248  }
249  return $this;
250  }
251 
257  public function getHashCode() {
258  if ($this->_isSupervisor) {
259  return $this->getSharedComponent()->getHashCode();
260  }
261  return md5(
262  $this->_locked
263  . $this->_hidden
264  . __CLASS__
265  );
266  }
267 
271  public function __clone() {
272  $vars = get_object_vars($this);
273  foreach ($vars as $key => $value) {
274  if ((is_object($value)) && ($key != '_parent')) {
275  $this->$key = clone $value;
276  } else {
277  $this->$key = $value;
278  }
279  }
280  }
281 }