ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Borders.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/Style/Border.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
42 
43 
52 {
53  /* Diagonal directions */
54  const DIAGONAL_NONE = 0;
55  const DIAGONAL_UP = 1;
56  const DIAGONAL_DOWN = 2;
57 
63  private $_left;
64 
70  private $_right;
71 
77  private $_top;
78 
84  private $_bottom;
85 
91  private $_diagonal;
92 
99 
105  private $_allBorders;
106 
112  private $_outline;
113 
119  private $_inside;
120 
126  private $_vertical;
127 
133  private $_horizontal;
134 
141 
147  private $_isSupervisor;
148 
154  private $_parent;
155 
159  public function __construct($isSupervisor = false)
160  {
161  // Supervisor?
162  $this->_isSupervisor = $isSupervisor;
163 
164  // Initialise values
165  $this->_left = new PHPExcel_Style_Border($isSupervisor);
166  $this->_right = new PHPExcel_Style_Border($isSupervisor);
167  $this->_top = new PHPExcel_Style_Border($isSupervisor);
168  $this->_bottom = new PHPExcel_Style_Border($isSupervisor);
169  $this->_diagonal = new PHPExcel_Style_Border($isSupervisor);
170  $this->_diagonalDirection = PHPExcel_Style_Borders::DIAGONAL_NONE;
171 
172  // Specially for supervisor
173  if ($isSupervisor) {
174  // Initialize pseudo-borders
175  $this->_allBorders = new PHPExcel_Style_Border(true);
176  $this->_outline = new PHPExcel_Style_Border(true);
177  $this->_inside = new PHPExcel_Style_Border(true);
178  $this->_vertical = new PHPExcel_Style_Border(true);
179  $this->_horizontal = new PHPExcel_Style_Border(true);
180 
181  // bind parent if we are a supervisor
182  $this->_left->bindParent($this, '_left');
183  $this->_right->bindParent($this, '_right');
184  $this->_top->bindParent($this, '_top');
185  $this->_bottom->bindParent($this, '_bottom');
186  $this->_diagonal->bindParent($this, '_diagonal');
187  $this->_allBorders->bindParent($this, '_allBorders');
188  $this->_outline->bindParent($this, '_outline');
189  $this->_inside->bindParent($this, '_inside');
190  $this->_vertical->bindParent($this, '_vertical');
191  $this->_horizontal->bindParent($this, '_horizontal');
192  }
193  }
194 
201  public function bindParent($parent)
202  {
203  $this->_parent = $parent;
204  return $this;
205  }
206 
212  public function getIsSupervisor()
213  {
214  return $this->_isSupervisor;
215  }
216 
223  public function getSharedComponent()
224  {
225  return $this->_parent->getSharedComponent()->getBorders();
226  }
227 
233  public function getActiveSheet()
234  {
235  return $this->_parent->getActiveSheet();
236  }
237 
244  public function getXSelectedCells()
245  {
246  return $this->getActiveSheet()->getXSelectedCells();
247  }
248 
255  public function getXActiveCell()
256  {
257  return $this->getActiveSheet()->getXActiveCell();
258  }
259 
266  public function getStyleArray($array)
267  {
268  return array('borders' => $array);
269  }
270 
309  public function applyFromArray($pStyles = null) {
310  if (is_array($pStyles)) {
311  if ($this->_isSupervisor) {
312  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
313  } else {
314  if (array_key_exists('left', $pStyles)) {
315  $this->getLeft()->applyFromArray($pStyles['left']);
316  }
317  if (array_key_exists('right', $pStyles)) {
318  $this->getRight()->applyFromArray($pStyles['right']);
319  }
320  if (array_key_exists('top', $pStyles)) {
321  $this->getTop()->applyFromArray($pStyles['top']);
322  }
323  if (array_key_exists('bottom', $pStyles)) {
324  $this->getBottom()->applyFromArray($pStyles['bottom']);
325  }
326  if (array_key_exists('diagonal', $pStyles)) {
327  $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
328  }
329  if (array_key_exists('diagonaldirection', $pStyles)) {
330  $this->setDiagonalDirection($pStyles['diagonaldirection']);
331  }
332  }
333  } else {
334  throw new Exception("Invalid style array passed.");
335  }
336  return $this;
337  }
338 
344  public function getLeft() {
345  return $this->_left;
346  }
347 
353  public function getRight() {
354  return $this->_right;
355  }
356 
362  public function getTop() {
363  return $this->_top;
364  }
365 
371  public function getBottom() {
372  return $this->_bottom;
373  }
374 
380  public function getDiagonal() {
381  return $this->_diagonal;
382  }
383 
390  public function getAllBorders() {
391  if (!$this->_isSupervisor) {
392  throw new Exception('Can only get pseudo-border for supervisor.');
393  }
394  return $this->_allBorders;
395  }
396 
403  public function getOutline() {
404  if (!$this->_isSupervisor) {
405  throw new Exception('Can only get pseudo-border for supervisor.');
406  }
407  return $this->_outline;
408  }
409 
416  public function getInside() {
417  if (!$this->_isSupervisor) {
418  throw new Exception('Can only get pseudo-border for supervisor.');
419  }
420  return $this->_inside;
421  }
422 
429  public function getVertical() {
430  if (!$this->_isSupervisor) {
431  throw new Exception('Can only get pseudo-border for supervisor.');
432  }
433  return $this->_vertical;
434  }
435 
442  public function getHorizontal() {
443  if (!$this->_isSupervisor) {
444  throw new Exception('Can only get pseudo-border for supervisor.');
445  }
446  return $this->_horizontal;
447  }
448 
454  public function getDiagonalDirection() {
455  if ($this->_isSupervisor) {
456  return $this->getSharedComponent()->getDiagonalDirection();
457  }
459  }
460 
468  if ($pValue == '') {
470  }
471  if ($this->_isSupervisor) {
472  $styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue));
473  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
474  } else {
475  $this->_diagonalDirection = $pValue;
476  }
477  return $this;
478  }
479 
485  public function getHashCode() {
486  if ($this->_isSupervisor) {
487  return $this->getSharedComponent()->getHashcode();
488  }
489  return md5(
490  $this->getLeft()->getHashCode()
491  . $this->getRight()->getHashCode()
492  . $this->getTop()->getHashCode()
493  . $this->getBottom()->getHashCode()
494  . $this->getDiagonal()->getHashCode()
495  . $this->getDiagonalDirection()
496  . __CLASS__
497  );
498  }
499 
505  private $_hashIndex;
506 
515  public function getHashIndex() {
516  return $this->_hashIndex;
517  }
518 
527  public function setHashIndex($value) {
528  $this->_hashIndex = $value;
529  }
530 
534  public function __clone() {
535  $vars = get_object_vars($this);
536  foreach ($vars as $key => $value) {
537  if (is_object($value)) {
538  $this->$key = clone $value;
539  } else {
540  $this->$key = $value;
541  }
542  }
543  }
544 }