[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/PHPExcel/PHPExcel/Style/ -> Borders.php (source)

   1  <?php
   2  /**
   3   * PHPExcel
   4   *
   5   * Copyright (c) 2006 - 2012 PHPExcel
   6   *
   7   * This library is free software; you can redistribute it and/or
   8   * modify it under the terms of the GNU Lesser General Public
   9   * License as published by the Free Software Foundation; either
  10   * version 2.1 of the License, or (at your option) any later version.
  11   *
  12   * This library is distributed in the hope that it will be useful,
  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15   * Lesser General Public License for more details.
  16   *
  17   * You should have received a copy of the GNU Lesser General Public
  18   * License along with this library; if not, write to the Free Software
  19   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20   *
  21   * @category   PHPExcel
  22   * @package    PHPExcel_Style
  23   * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24   * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25   * @version    1.7.7, 2012-05-19
  26   */
  27  
  28  
  29  /**
  30   * PHPExcel_Style_Borders
  31   *
  32   * @category   PHPExcel
  33   * @package    PHPExcel_Style
  34   * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  35   */
  36  class PHPExcel_Style_Borders implements PHPExcel_IComparable
  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  
  44      /**
  45       * Left
  46       *
  47       * @var PHPExcel_Style_Border
  48       */
  49      private $_left;
  50  
  51      /**
  52       * Right
  53       *
  54       * @var PHPExcel_Style_Border
  55       */
  56      private $_right;
  57  
  58      /**
  59       * Top
  60       *
  61       * @var PHPExcel_Style_Border
  62       */
  63      private $_top;
  64  
  65      /**
  66       * Bottom
  67       *
  68       * @var PHPExcel_Style_Border
  69       */
  70      private $_bottom;
  71  
  72      /**
  73       * Diagonal
  74       *
  75       * @var PHPExcel_Style_Border
  76       */
  77      private $_diagonal;
  78  
  79      /**
  80       * DiagonalDirection
  81       *
  82       * @var int
  83       */
  84      private $_diagonalDirection;
  85  
  86      /**
  87       * All borders psedo-border. Only applies to supervisor.
  88       *
  89       * @var PHPExcel_Style_Border
  90       */
  91      private $_allBorders;
  92  
  93      /**
  94       * Outline psedo-border. Only applies to supervisor.
  95       *
  96       * @var PHPExcel_Style_Border
  97       */
  98      private $_outline;
  99  
 100      /**
 101       * Inside psedo-border. Only applies to supervisor.
 102       *
 103       * @var PHPExcel_Style_Border
 104       */
 105      private $_inside;
 106  
 107      /**
 108       * Vertical pseudo-border. Only applies to supervisor.
 109       *
 110       * @var PHPExcel_Style_Border
 111       */
 112      private $_vertical;
 113  
 114      /**
 115       * Horizontal pseudo-border. Only applies to supervisor.
 116       *
 117       * @var PHPExcel_Style_Border
 118       */
 119      private $_horizontal;
 120  
 121      /**
 122       * Parent Borders
 123       *
 124       * @var _parentPropertyName string
 125       */
 126      private $_parentPropertyName;
 127  
 128      /**
 129       * Supervisor?
 130       *
 131       * @var boolean
 132       */
 133      private $_isSupervisor;
 134  
 135      /**
 136       * Parent. Only used for supervisor
 137       *
 138       * @var PHPExcel_Style
 139       */
 140      private $_parent;
 141  
 142      /**
 143       * Create a new PHPExcel_Style_Borders
 144       *
 145       * @param    boolean    $isSupervisor    Flag indicating if this is a supervisor or not
 146       */
 147      public function __construct($isSupervisor = false)
 148      {
 149          // Supervisor?
 150          $this->_isSupervisor = $isSupervisor;
 151  
 152          // Initialise values
 153          $this->_left                = new PHPExcel_Style_Border($isSupervisor);
 154          $this->_right                = new PHPExcel_Style_Border($isSupervisor);
 155          $this->_top                    = new PHPExcel_Style_Border($isSupervisor);
 156          $this->_bottom                = new PHPExcel_Style_Border($isSupervisor);
 157          $this->_diagonal            = new PHPExcel_Style_Border($isSupervisor);
 158          $this->_diagonalDirection    = PHPExcel_Style_Borders::DIAGONAL_NONE;
 159  
 160          // Specially for supervisor
 161          if ($isSupervisor) {
 162              // Initialize pseudo-borders
 163              $this->_allBorders            = new PHPExcel_Style_Border(true);
 164              $this->_outline                = new PHPExcel_Style_Border(true);
 165              $this->_inside                = new PHPExcel_Style_Border(true);
 166              $this->_vertical            = new PHPExcel_Style_Border(true);
 167              $this->_horizontal            = new PHPExcel_Style_Border(true);
 168  
 169              // bind parent if we are a supervisor
 170              $this->_left->bindParent($this, '_left');
 171              $this->_right->bindParent($this, '_right');
 172              $this->_top->bindParent($this, '_top');
 173              $this->_bottom->bindParent($this, '_bottom');
 174              $this->_diagonal->bindParent($this, '_diagonal');
 175              $this->_allBorders->bindParent($this, '_allBorders');
 176              $this->_outline->bindParent($this, '_outline');
 177              $this->_inside->bindParent($this, '_inside');
 178              $this->_vertical->bindParent($this, '_vertical');
 179              $this->_horizontal->bindParent($this, '_horizontal');
 180          }
 181      }
 182  
 183      /**
 184       * Bind parent. Only used for supervisor
 185       *
 186       * @param PHPExcel_Style $parent
 187       * @return PHPExcel_Style_Borders
 188       */
 189  	public function bindParent($parent)
 190      {
 191          $this->_parent = $parent;
 192          return $this;
 193      }
 194  
 195      /**
 196       * Is this a supervisor or a real style component?
 197       *
 198       * @return boolean
 199       */
 200  	public function getIsSupervisor()
 201      {
 202          return $this->_isSupervisor;
 203      }
 204  
 205      /**
 206       * Get the shared style component for the currently active cell in currently active sheet.
 207       * Only used for style supervisor
 208       *
 209       * @return PHPExcel_Style_Borders
 210       */
 211  	public function getSharedComponent()
 212      {
 213          return $this->_parent->getSharedComponent()->getBorders();
 214      }
 215  
 216      /**
 217       * Get the currently active sheet. Only used for supervisor
 218       *
 219       * @return PHPExcel_Worksheet
 220       */
 221  	public function getActiveSheet()
 222      {
 223          return $this->_parent->getActiveSheet();
 224      }
 225  
 226      /**
 227       * Get the currently active cell coordinate in currently active sheet.
 228       * Only used for supervisor
 229       *
 230       * @return string E.g. 'A1'
 231       */
 232  	public function getSelectedCells()
 233      {
 234          return $this->getActiveSheet()->getSelectedCells();
 235      }
 236  
 237      /**
 238       * Get the currently active cell coordinate in currently active sheet.
 239       * Only used for supervisor
 240       *
 241       * @return string E.g. 'A1'
 242       */
 243  	public function getActiveCell()
 244      {
 245          return $this->getActiveSheet()->getActiveCell();
 246      }
 247  
 248      /**
 249       * Build style array from subcomponents
 250       *
 251       * @param array $array
 252       * @return array
 253       */
 254  	public function getStyleArray($array)
 255      {
 256          return array('borders' => $array);
 257      }
 258  
 259      /**
 260       * Apply styles from array
 261       *
 262       * <code>
 263       * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
 264       *         array(
 265       *             'bottom'     => array(
 266       *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
 267       *                 'color' => array(
 268       *                     'rgb' => '808080'
 269       *                 )
 270       *             ),
 271       *             'top'     => array(
 272       *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
 273       *                 'color' => array(
 274       *                     'rgb' => '808080'
 275       *                 )
 276       *             )
 277       *         )
 278       * );
 279       * </code>
 280       * <code>
 281       * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->applyFromArray(
 282       *         array(
 283       *             'allborders' => array(
 284       *                 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
 285       *                 'color' => array(
 286       *                     'rgb' => '808080'
 287       *                 )
 288       *             )
 289       *         )
 290       * );
 291       * </code>
 292       *
 293       * @param    array    $pStyles    Array containing style information
 294       * @throws    Exception
 295       * @return PHPExcel_Style_Borders
 296       */
 297  	public function applyFromArray($pStyles = null) {
 298          if (is_array($pStyles)) {
 299              if ($this->_isSupervisor) {
 300                  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
 301              } else {
 302                  if (array_key_exists('left', $pStyles)) {
 303                      $this->getLeft()->applyFromArray($pStyles['left']);
 304                  }
 305                  if (array_key_exists('right', $pStyles)) {
 306                      $this->getRight()->applyFromArray($pStyles['right']);
 307                  }
 308                  if (array_key_exists('top', $pStyles)) {
 309                      $this->getTop()->applyFromArray($pStyles['top']);
 310                  }
 311                  if (array_key_exists('bottom', $pStyles)) {
 312                      $this->getBottom()->applyFromArray($pStyles['bottom']);
 313                  }
 314                  if (array_key_exists('diagonal', $pStyles)) {
 315                      $this->getDiagonal()->applyFromArray($pStyles['diagonal']);
 316                  }
 317                  if (array_key_exists('diagonaldirection', $pStyles)) {
 318                      $this->setDiagonalDirection($pStyles['diagonaldirection']);
 319                  }
 320                  if (array_key_exists('allborders', $pStyles)) {
 321                      $this->getLeft()->applyFromArray($pStyles['allborders']);
 322                      $this->getRight()->applyFromArray($pStyles['allborders']);
 323                      $this->getTop()->applyFromArray($pStyles['allborders']);
 324                      $this->getBottom()->applyFromArray($pStyles['allborders']);
 325                  }
 326              }
 327          } else {
 328              throw new Exception("Invalid style array passed.");
 329          }
 330          return $this;
 331      }
 332  
 333      /**
 334       * Get Left
 335       *
 336       * @return PHPExcel_Style_Border
 337       */
 338      public function getLeft() {
 339          return $this->_left;
 340      }
 341  
 342      /**
 343       * Get Right
 344       *
 345       * @return PHPExcel_Style_Border
 346       */
 347      public function getRight() {
 348          return $this->_right;
 349      }
 350  
 351      /**
 352       * Get Top
 353       *
 354       * @return PHPExcel_Style_Border
 355       */
 356      public function getTop() {
 357          return $this->_top;
 358      }
 359  
 360      /**
 361       * Get Bottom
 362       *
 363       * @return PHPExcel_Style_Border
 364       */
 365      public function getBottom() {
 366          return $this->_bottom;
 367      }
 368  
 369      /**
 370       * Get Diagonal
 371       *
 372       * @return PHPExcel_Style_Border
 373       */
 374      public function getDiagonal() {
 375          return $this->_diagonal;
 376      }
 377  
 378      /**
 379       * Get AllBorders (pseudo-border). Only applies to supervisor.
 380       *
 381       * @return PHPExcel_Style_Border
 382       * @throws Exception
 383       */
 384      public function getAllBorders() {
 385          if (!$this->_isSupervisor) {
 386              throw new Exception('Can only get pseudo-border for supervisor.');
 387          }
 388          return $this->_allBorders;
 389      }
 390  
 391      /**
 392       * Get Outline (pseudo-border). Only applies to supervisor.
 393       *
 394       * @return boolean
 395       * @throws Exception
 396       */
 397      public function getOutline() {
 398          if (!$this->_isSupervisor) {
 399              throw new Exception('Can only get pseudo-border for supervisor.');
 400          }
 401          return $this->_outline;
 402      }
 403  
 404      /**
 405       * Get Inside (pseudo-border). Only applies to supervisor.
 406       *
 407       * @return boolean
 408       * @throws Exception
 409       */
 410      public function getInside() {
 411          if (!$this->_isSupervisor) {
 412              throw new Exception('Can only get pseudo-border for supervisor.');
 413          }
 414          return $this->_inside;
 415      }
 416  
 417      /**
 418       * Get Vertical (pseudo-border). Only applies to supervisor.
 419       *
 420       * @return PHPExcel_Style_Border
 421       * @throws Exception
 422       */
 423      public function getVertical() {
 424          if (!$this->_isSupervisor) {
 425              throw new Exception('Can only get pseudo-border for supervisor.');
 426          }
 427          return $this->_vertical;
 428      }
 429  
 430      /**
 431       * Get Horizontal (pseudo-border). Only applies to supervisor.
 432       *
 433       * @return PHPExcel_Style_Border
 434       * @throws Exception
 435       */
 436      public function getHorizontal() {
 437          if (!$this->_isSupervisor) {
 438              throw new Exception('Can only get pseudo-border for supervisor.');
 439          }
 440          return $this->_horizontal;
 441      }
 442  
 443      /**
 444       * Get DiagonalDirection
 445       *
 446       * @return int
 447       */
 448      public function getDiagonalDirection() {
 449          if ($this->_isSupervisor) {
 450              return $this->getSharedComponent()->getDiagonalDirection();
 451          }
 452          return $this->_diagonalDirection;
 453      }
 454  
 455      /**
 456       * Set DiagonalDirection
 457       *
 458       * @param int $pValue
 459       * @return PHPExcel_Style_Borders
 460       */
 461      public function setDiagonalDirection($pValue = PHPExcel_Style_Borders::DIAGONAL_NONE) {
 462          if ($pValue == '') {
 463              $pValue = PHPExcel_Style_Borders::DIAGONAL_NONE;
 464          }
 465          if ($this->_isSupervisor) {
 466              $styleArray = $this->getStyleArray(array('diagonaldirection' => $pValue));
 467              $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
 468          } else {
 469              $this->_diagonalDirection = $pValue;
 470          }
 471          return $this;
 472      }
 473  
 474      /**
 475       * Get hash code
 476       *
 477       * @return string    Hash code
 478       */
 479  	public function getHashCode() {
 480          if ($this->_isSupervisor) {
 481              return $this->getSharedComponent()->getHashcode();
 482          }
 483          return md5(
 484                $this->getLeft()->getHashCode()
 485              . $this->getRight()->getHashCode()
 486              . $this->getTop()->getHashCode()
 487              . $this->getBottom()->getHashCode()
 488              . $this->getDiagonal()->getHashCode()
 489              . $this->getDiagonalDirection()
 490              . __CLASS__
 491          );
 492      }
 493  
 494      /**
 495       * Implement PHP __clone to create a deep clone, not just a shallow copy.
 496       */
 497  	public function __clone() {
 498          $vars = get_object_vars($this);
 499          foreach ($vars as $key => $value) {
 500              if ((is_object($value)) && ($key != '_parent')) {
 501                  $this->$key = clone $value;
 502              } else {
 503                  $this->$key = $value;
 504              }
 505          }
 506      }
 507  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1