ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Alignment.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 {
50  /* Horizontal alignment styles */
51  const HORIZONTAL_GENERAL = 'general';
52  const HORIZONTAL_LEFT = 'left';
53  const HORIZONTAL_RIGHT = 'right';
54  const HORIZONTAL_CENTER = 'center';
55  const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
56  const HORIZONTAL_JUSTIFY = 'justify';
57 
58  /* Vertical alignment styles */
59  const VERTICAL_BOTTOM = 'bottom';
60  const VERTICAL_TOP = 'top';
61  const VERTICAL_CENTER = 'center';
62  const VERTICAL_JUSTIFY = 'justify';
63 
69  private $_horizontal;
70 
76  private $_vertical;
77 
83  private $_textRotation;
84 
90  private $_wrapText;
91 
97  private $_shrinkToFit;
98 
104  private $_indent;
105 
112 
118  private $_isSupervisor;
119 
125  private $_parent;
126 
130  public function __construct($isSupervisor = false)
131  {
132  // Supervisor?
133  $this->_isSupervisor = $isSupervisor;
134 
135  // Initialise values
138  $this->_textRotation = 0;
139  $this->_wrapText = false;
140  $this->_shrinkToFit = false;
141  $this->_indent = 0;
142  }
143 
150  public function bindParent($parent)
151  {
152  $this->_parent = $parent;
153  return $this;
154  }
155 
161  public function getIsSupervisor()
162  {
163  return $this->_isSupervisor;
164  }
165 
172  public function getSharedComponent()
173  {
174  return $this->_parent->getSharedComponent()->getAlignment();
175  }
176 
182  public function getActiveSheet()
183  {
184  return $this->_parent->getActiveSheet();
185  }
186 
193  public function getXSelectedCells()
194  {
195  return $this->getActiveSheet()->getXSelectedCells();
196  }
197 
204  public function getXActiveCell()
205  {
206  return $this->getActiveSheet()->getXActiveCell();
207  }
208 
215  public function getStyleArray($array)
216  {
217  return array('alignment' => $array);
218  }
219 
238  public function applyFromArray($pStyles = null) {
239  if (is_array($pStyles)) {
240  if ($this->_isSupervisor) {
241  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
242  } else {
243  if (array_key_exists('horizontal', $pStyles)) {
244  $this->setHorizontal($pStyles['horizontal']);
245  }
246  if (array_key_exists('vertical', $pStyles)) {
247  $this->setVertical($pStyles['vertical']);
248  }
249  if (array_key_exists('rotation', $pStyles)) {
250  $this->setTextRotation($pStyles['rotation']);
251  }
252  if (array_key_exists('wrap', $pStyles)) {
253  $this->setWrapText($pStyles['wrap']);
254  }
255  if (array_key_exists('shrinkToFit', $pStyles)) {
256  $this->setShrinkToFit($pStyles['shrinkToFit']);
257  }
258  if (array_key_exists('indent', $pStyles)) {
259  $this->setIndent($pStyles['indent']);
260  }
261  }
262  } else {
263  throw new Exception("Invalid style array passed.");
264  }
265  return $this;
266  }
267 
273  public function getHorizontal() {
274  if ($this->_isSupervisor) {
275  return $this->getSharedComponent()->getHorizontal();
276  }
277  return $this->_horizontal;
278  }
279 
287  if ($pValue == '') {
289  }
290 
291  if ($this->_isSupervisor) {
292  $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
293  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
294  }
295  else {
296  $this->_horizontal = $pValue;
297  }
298  return $this;
299  }
300 
306  public function getVertical() {
307  if ($this->_isSupervisor) {
308  return $this->getSharedComponent()->getVertical();
309  }
310  return $this->_vertical;
311  }
312 
320  if ($pValue == '') {
322  }
323 
324  if ($this->_isSupervisor) {
325  $styleArray = $this->getStyleArray(array('vertical' => $pValue));
326  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
327  } else {
328  $this->_vertical = $pValue;
329  }
330  return $this;
331  }
332 
338  public function getTextRotation() {
339  if ($this->_isSupervisor) {
340  return $this->getSharedComponent()->getTextRotation();
341  }
342  return $this->_textRotation;
343  }
344 
352  public function setTextRotation($pValue = 0) {
353  // Excel2007 value 255 => PHPExcel value -165
354  if ($pValue == 255) {
355  $pValue = -165;
356  }
357 
358  // Set rotation
359  if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
360  if ($this->_isSupervisor) {
361  $styleArray = $this->getStyleArray(array('rotation' => $pValue));
362  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
363  } else {
364  $this->_textRotation = $pValue;
365  }
366  } else {
367  throw new Exception("Text rotation should be a value between -90 and 90.");
368  }
369 
370  return $this;
371  }
372 
378  public function getWrapText() {
379  if ($this->_isSupervisor) {
380  return $this->getSharedComponent()->getWrapText();
381  }
382  return $this->_wrapText;
383  }
384 
391  public function setWrapText($pValue = false) {
392  if ($pValue == '') {
393  $pValue = false;
394  }
395  if ($this->_isSupervisor) {
396  $styleArray = $this->getStyleArray(array('wrap' => $pValue));
397  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
398  } else {
399  $this->_wrapText = $pValue;
400  }
401  return $this;
402  }
403 
409  public function getShrinkToFit() {
410  if ($this->_isSupervisor) {
411  return $this->getSharedComponent()->getShrinkToFit();
412  }
413  return $this->_shrinkToFit;
414  }
415 
422  public function setShrinkToFit($pValue = false) {
423  if ($pValue == '') {
424  $pValue = false;
425  }
426  if ($this->_isSupervisor) {
427  $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
428  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
429  } else {
430  $this->_shrinkToFit = $pValue;
431  }
432  return $this;
433  }
434 
440  public function getIndent() {
441  if ($this->_isSupervisor) {
442  return $this->getSharedComponent()->getIndent();
443  }
444  return $this->_indent;
445  }
446 
453  public function setIndent($pValue = 0) {
454  if ($pValue > 0) {
455  if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
456  $pValue = 0; // indent not supported
457  }
458  }
459  if ($this->_isSupervisor) {
460  $styleArray = $this->getStyleArray(array('indent' => $pValue));
461  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
462  } else {
463  $this->_indent = $pValue;
464  }
465  return $this;
466  }
467 
473  public function getHashCode() {
474  if ($this->_isSupervisor) {
475  return $this->getSharedComponent()->getHashCode();
476  }
477  return md5(
478  $this->_horizontal
479  . $this->_vertical
480  . $this->_textRotation
481  . ($this->_wrapText ? 't' : 'f')
482  . ($this->_shrinkToFit ? 't' : 'f')
483  . $this->_indent
484  . __CLASS__
485  );
486  }
487 
493  private $_hashIndex;
494 
503  public function getHashIndex() {
504  return $this->_hashIndex;
505  }
506 
515  public function setHashIndex($value) {
516  $this->_hashIndex = $value;
517  }
518 
522  public function __clone() {
523  $vars = get_object_vars($this);
524  foreach ($vars as $key => $value) {
525  if (is_object($value)) {
526  $this->$key = clone $value;
527  } else {
528  $this->$key = $value;
529  }
530  }
531  }
532 }