ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Alignment.php
Go to the documentation of this file.
1 <?php
37 {
38  /* Horizontal alignment styles */
39  const HORIZONTAL_GENERAL = 'general';
40  const HORIZONTAL_LEFT = 'left';
41  const HORIZONTAL_RIGHT = 'right';
42  const HORIZONTAL_CENTER = 'center';
43  const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
44  const HORIZONTAL_JUSTIFY = 'justify';
45  const HORIZONTAL_FILL = 'fill';
46  const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
47 
48  /* Vertical alignment styles */
49  const VERTICAL_BOTTOM = 'bottom';
50  const VERTICAL_TOP = 'top';
51  const VERTICAL_CENTER = 'center';
52  const VERTICAL_JUSTIFY = 'justify';
53  const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
54 
55  /* Read order */
56  const READORDER_CONTEXT = 0;
57  const READORDER_LTR = 1;
58  const READORDER_RTL = 2;
59 
66 
73 
79  protected $_textRotation = 0;
80 
86  protected $_wrapText = FALSE;
87 
93  protected $_shrinkToFit = FALSE;
94 
100  protected $_indent = 0;
101 
107  protected $_readorder = 0;
108 
119  public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
120  {
121  // Supervisor?
122  parent::__construct($isSupervisor);
123 
124  if ($isConditional) {
125  $this->_horizontal = NULL;
126  $this->_vertical = NULL;
127  $this->_textRotation = NULL;
128  }
129  }
130 
137  public function getSharedComponent()
138  {
139  return $this->_parent->getSharedComponent()->getAlignment();
140  }
141 
148  public function getStyleArray($array)
149  {
150  return array('alignment' => $array);
151  }
152 
171  public function applyFromArray($pStyles = NULL) {
172  if (is_array($pStyles)) {
173  if ($this->_isSupervisor) {
174  $this->getActiveSheet()->getStyle($this->getSelectedCells())
175  ->applyFromArray($this->getStyleArray($pStyles));
176  } else {
177  if (isset($pStyles['horizontal'])) {
178  $this->setHorizontal($pStyles['horizontal']);
179  }
180  if (isset($pStyles['vertical'])) {
181  $this->setVertical($pStyles['vertical']);
182  }
183  if (isset($pStyles['rotation'])) {
184  $this->setTextRotation($pStyles['rotation']);
185  }
186  if (isset($pStyles['wrap'])) {
187  $this->setWrapText($pStyles['wrap']);
188  }
189  if (isset($pStyles['shrinkToFit'])) {
190  $this->setShrinkToFit($pStyles['shrinkToFit']);
191  }
192  if (isset($pStyles['indent'])) {
193  $this->setIndent($pStyles['indent']);
194  }
195  if (isset($pStyles['readorder'])) {
196  $this->setReadorder($pStyles['readorder']);
197  }
198  }
199  } else {
200  throw new PHPExcel_Exception("Invalid style array passed.");
201  }
202  return $this;
203  }
204 
210  public function getHorizontal() {
211  if ($this->_isSupervisor) {
212  return $this->getSharedComponent()->getHorizontal();
213  }
214  return $this->_horizontal;
215  }
216 
224  if ($pValue == '') {
226  }
227 
228  if ($this->_isSupervisor) {
229  $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
230  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
231  }
232  else {
233  $this->_horizontal = $pValue;
234  }
235  return $this;
236  }
237 
243  public function getVertical() {
244  if ($this->_isSupervisor) {
245  return $this->getSharedComponent()->getVertical();
246  }
247  return $this->_vertical;
248  }
249 
257  if ($pValue == '') {
259  }
260 
261  if ($this->_isSupervisor) {
262  $styleArray = $this->getStyleArray(array('vertical' => $pValue));
263  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
264  } else {
265  $this->_vertical = $pValue;
266  }
267  return $this;
268  }
269 
275  public function getTextRotation() {
276  if ($this->_isSupervisor) {
277  return $this->getSharedComponent()->getTextRotation();
278  }
279  return $this->_textRotation;
280  }
281 
289  public function setTextRotation($pValue = 0) {
290  // Excel2007 value 255 => PHPExcel value -165
291  if ($pValue == 255) {
292  $pValue = -165;
293  }
294 
295  // Set rotation
296  if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
297  if ($this->_isSupervisor) {
298  $styleArray = $this->getStyleArray(array('rotation' => $pValue));
299  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
300  } else {
301  $this->_textRotation = $pValue;
302  }
303  } else {
304  throw new PHPExcel_Exception("Text rotation should be a value between -90 and 90.");
305  }
306 
307  return $this;
308  }
309 
315  public function getWrapText() {
316  if ($this->_isSupervisor) {
317  return $this->getSharedComponent()->getWrapText();
318  }
319  return $this->_wrapText;
320  }
321 
328  public function setWrapText($pValue = FALSE) {
329  if ($pValue == '') {
330  $pValue = FALSE;
331  }
332  if ($this->_isSupervisor) {
333  $styleArray = $this->getStyleArray(array('wrap' => $pValue));
334  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
335  } else {
336  $this->_wrapText = $pValue;
337  }
338  return $this;
339  }
340 
346  public function getShrinkToFit() {
347  if ($this->_isSupervisor) {
348  return $this->getSharedComponent()->getShrinkToFit();
349  }
350  return $this->_shrinkToFit;
351  }
352 
359  public function setShrinkToFit($pValue = FALSE) {
360  if ($pValue == '') {
361  $pValue = FALSE;
362  }
363  if ($this->_isSupervisor) {
364  $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
365  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
366  } else {
367  $this->_shrinkToFit = $pValue;
368  }
369  return $this;
370  }
371 
377  public function getIndent() {
378  if ($this->_isSupervisor) {
379  return $this->getSharedComponent()->getIndent();
380  }
381  return $this->_indent;
382  }
383 
390  public function setIndent($pValue = 0) {
391  if ($pValue > 0) {
392  if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
393  $this->getHorizontal() != self::HORIZONTAL_LEFT &&
394  $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
395  $pValue = 0; // indent not supported
396  }
397  }
398  if ($this->_isSupervisor) {
399  $styleArray = $this->getStyleArray(array('indent' => $pValue));
400  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
401  } else {
402  $this->_indent = $pValue;
403  }
404  return $this;
405  }
406 
412  public function getReadorder() {
413  if ($this->_isSupervisor) {
414  return $this->getSharedComponent()->getReadorder();
415  }
416  return $this->_readorder;
417  }
418 
425  public function setReadorder($pValue = 0) {
426  if ($pValue < 0 || $pValue > 2) {
427  $pValue = 0;
428  }
429  if ($this->_isSupervisor) {
430  $styleArray = $this->getStyleArray(array('readorder' => $pValue));
431  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
432  } else {
433  $this->_readorder = $pValue;
434  }
435  return $this;
436  }
437 
443  public function getHashCode() {
444  if ($this->_isSupervisor) {
445  return $this->getSharedComponent()->getHashCode();
446  }
447  return md5(
448  $this->_horizontal
449  . $this->_vertical
450  . $this->_textRotation
451  . ($this->_wrapText ? 't' : 'f')
452  . ($this->_shrinkToFit ? 't' : 'f')
453  . $this->_indent
454  . $this->_readorder
455  . __CLASS__
456  );
457  }
458 
459 }
getWrapText()
Get Wrap Text.
Definition: Alignment.php:315
setTextRotation($pValue=0)
Set TextRotation.
Definition: Alignment.php:289
getHorizontal()
Get Horizontal.
Definition: Alignment.php:210
setVertical($pValue=PHPExcel_Style_Alignment::VERTICAL_BOTTOM)
Set Vertical.
Definition: Alignment.php:256
getIndent()
Get indent.
Definition: Alignment.php:377
getHashCode()
Get hash code.
Definition: Alignment.php:443
getSelectedCells()
Get the currently active cell coordinate in currently active sheet.
Definition: Supervisor.php:103
getStyleArray($array)
Build style array from subcomponents.
Definition: Alignment.php:148
getShrinkToFit()
Get Shrink to fit.
Definition: Alignment.php:346
setReadorder($pValue=0)
Set read order.
Definition: Alignment.php:425
getTextRotation()
Get TextRotation.
Definition: Alignment.php:275
__construct($isSupervisor=FALSE, $isConditional=FALSE)
Create a new PHPExcel_Style_Alignment.
Definition: Alignment.php:119
getSharedComponent()
Get the shared style component for the currently active cell in currently active sheet.
Definition: Alignment.php:137
setShrinkToFit($pValue=FALSE)
Set Shrink to fit.
Definition: Alignment.php:359
setHorizontal($pValue=PHPExcel_Style_Alignment::HORIZONTAL_GENERAL)
Set Horizontal.
Definition: Alignment.php:223
getVertical()
Get Vertical.
Definition: Alignment.php:243
const HORIZONTAL_CENTER_CONTINUOUS
Definition: Alignment.php:43
setIndent($pValue=0)
Set indent.
Definition: Alignment.php:390
Create styles array
The data for the language used.
getReadorder()
Get read order.
Definition: Alignment.php:412
applyFromArray($pStyles=NULL)
Apply styles from array.
Definition: Alignment.php:171
setWrapText($pValue=FALSE)
Set Wrap Text.
Definition: Alignment.php:328
getActiveSheet()
Get the currently active sheet.
Definition: Supervisor.php:92