ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
Borders.php
Go to the documentation of this file.
1 <?php
37 {
38  /* Diagonal directions */
39  const DIAGONAL_NONE = 0;
40  const DIAGONAL_UP = 1;
41  const DIAGONAL_DOWN = 2;
42  const DIAGONAL_BOTH = 3;
43 
49  private $_left;
50 
56  private $_right;
57 
63  private $_top;
64 
70  private $_bottom;
71 
77  private $_diagonal;
78 
85 
91  private $_allBorders;
92 
98  private $_outline;
99 
105  private $_inside;
106 
112  private $_vertical;
113 
119  private $_horizontal;
120 
127 
133  private $_isSupervisor;
134 
140  private $_parent;
141 
145  public function __construct($isSupervisor = false)
146  {
147  // Supervisor?
148  $this->_isSupervisor = $isSupervisor;
149 
150  // Initialise values
151  $this->_left = new PHPExcel_Style_Border($isSupervisor);
152  $this->_right = new PHPExcel_Style_Border($isSupervisor);
153  $this->_top = new PHPExcel_Style_Border($isSupervisor);
154  $this->_bottom = new PHPExcel_Style_Border($isSupervisor);
155  $this->_diagonal = new PHPExcel_Style_Border($isSupervisor);
156  $this->_diagonalDirection = PHPExcel_Style_Borders::DIAGONAL_NONE;
157 
158  // Specially for supervisor
159  if ($isSupervisor) {
160  // Initialize pseudo-borders
161  $this->_allBorders = new PHPExcel_Style_Border(true);
162  $this->_outline = new PHPExcel_Style_Border(true);
163  $this->_inside = new PHPExcel_Style_Border(true);
164  $this->_vertical = new PHPExcel_Style_Border(true);
165  $this->_horizontal = new PHPExcel_Style_Border(true);
166 
167  // bind parent if we are a supervisor
168  $this->_left->bindParent($this, '_left');
169  $this->_right->bindParent($this, '_right');
170  $this->_top->bindParent($this, '_top');
171  $this->_bottom->bindParent($this, '_bottom');
172  $this->_diagonal->bindParent($this, '_diagonal');
173  $this->_allBorders->bindParent($this, '_allBorders');
174  $this->_outline->bindParent($this, '_outline');
175  $this->_inside->bindParent($this, '_inside');
176  $this->_vertical->bindParent($this, '_vertical');
177  $this->_horizontal->bindParent($this, '_horizontal');
178  }
179  }
180 
187  public function bindParent($parent)
188  {
189  $this->_parent = $parent;
190  return $this;
191  }
192 
198  public function getIsSupervisor()
199  {
200  return $this->_isSupervisor;
201  }
202 
209  public function getSharedComponent()
210  {
211  return $this->_parent->getSharedComponent()->getBorders();
212  }
213 
219  public function getActiveSheet()
220  {
221  return $this->_parent->getActiveSheet();
222  }
223 
230  public function getSelectedCells()
231  {
232  return $this->getActiveSheet()->getSelectedCells();
233  }
234 
241  public function getActiveCell()
242  {
243  return $this->getActiveSheet()->getActiveCell();
244  }
245 
252  public function getStyleArray($array)
253  {
254  return array('borders' => $array);
255  }
256 
295  public function applyFromArray($pStyles = null) {
296  if (is_array($pStyles)) {
297  if ($this->_isSupervisor) {
298  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
299  } else {
300  if (array_key_exists('left', $pStyles)) {
301  $this->getLeft()->applyFromArray($pStyles['left']);
302  }
303  if (array_key_exists('right', $pStyles)) {
304  $this->getRight()->applyFromArray($pStyles['right']);
305  }
306  if (array_key_exists('top', $pStyles)) {
307  $this->getTop()->applyFromArray($pStyles['top']);
308  }
309  if (array_key_exists('bottom', $pStyles)) {
310  $this->getBottom()->applyFromArray($pStyles['bottom']);
311  }
312  if (array_key_exists('diagonal', $pStyles)) {
313  $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
314  }
315  if (array_key_exists('diagonaldirection', $pStyles)) {
316  $this->setDiagonalDirection($pStyles['diagonaldirection']);
317  }
318  if (array_key_exists('allborders', $pStyles)) {
319  $this->getLeft()->applyFromArray($pStyles['allborders']);
320  $this->getRight()->applyFromArray($pStyles['allborders']);
321  $this->getTop()->applyFromArray($pStyles['allborders']);
322  $this->getBottom()->applyFromArray($pStyles['allborders']);
323  }
324  }
325  } else {
326  throw new Exception("Invalid style array passed.");
327  }
328  return $this;
329  }
330 
336  public function getLeft() {
337  return $this->_left;
338  }
339 
345  public function getRight() {
346  return $this->_right;
347  }
348 
354  public function getTop() {
355  return $this->_top;
356  }
357 
363  public function getBottom() {
364  return $this->_bottom;
365  }
366 
372  public function getDiagonal() {
373  return $this->_diagonal;
374  }
375 
382  public function getAllBorders() {
383  if (!$this->_isSupervisor) {
384  throw new Exception('Can only get pseudo-border for supervisor.');
385  }
386  return $this->_allBorders;
387  }
388 
395  public function getOutline() {
396  if (!$this->_isSupervisor) {
397  throw new Exception('Can only get pseudo-border for supervisor.');
398  }
399  return $this->_outline;
400  }
401 
408  public function getInside() {
409  if (!$this->_isSupervisor) {
410  throw new Exception('Can only get pseudo-border for supervisor.');
411  }
412  return $this->_inside;
413  }
414 
421  public function getVertical() {
422  if (!$this->_isSupervisor) {
423  throw new Exception('Can only get pseudo-border for supervisor.');
424  }
425  return $this->_vertical;
426  }
427 
434  public function getHorizontal() {
435  if (!$this->_isSupervisor) {
436  throw new Exception('Can only get pseudo-border for supervisor.');
437  }
438  return $this->_horizontal;
439  }
440 
446  public function getDiagonalDirection() {
447  if ($this->_isSupervisor) {
448  return $this->getSharedComponent()->getDiagonalDirection();
449  }
451  }
452 
460  if ($pValue == '') {
462  }
463  if ($this->_isSupervisor) {
464  $styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue));
465  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
466  } else {
467  $this->_diagonalDirection = $pValue;
468  }
469  return $this;
470  }
471 
477  public function getHashCode() {
478  if ($this->_isSupervisor) {
479  return $this->getSharedComponent()->getHashcode();
480  }
481  return md5(
482  $this->getLeft()->getHashCode()
483  . $this->getRight()->getHashCode()
484  . $this->getTop()->getHashCode()
485  . $this->getBottom()->getHashCode()
486  . $this->getDiagonal()->getHashCode()
487  . $this->getDiagonalDirection()
488  . __CLASS__
489  );
490  }
491 
495  public function __clone() {
496  $vars = get_object_vars($this);
497  foreach ($vars as $key => $value) {
498  if ((is_object($value)) && ($key != '_parent')) {
499  $this->$key = clone $value;
500  } else {
501  $this->$key = $value;
502  }
503  }
504  }
505 }