ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
46  /* Vertical alignment styles */
47  const VERTICAL_BOTTOM = 'bottom';
48  const VERTICAL_TOP = 'top';
49  const VERTICAL_CENTER = 'center';
50  const VERTICAL_JUSTIFY = 'justify';
51 
58 
65 
71  private $_textRotation = 0;
72 
78  private $_wrapText = false;
79 
85  private $_shrinkToFit = false;
86 
92  private $_indent = 0;
93 
100 
106  private $_isSupervisor;
107 
113  private $_parent;
114 
118  public function __construct($isSupervisor = false)
119  {
120  // Supervisor?
121  $this->_isSupervisor = $isSupervisor;
122  }
123 
130  public function bindParent($parent)
131  {
132  $this->_parent = $parent;
133  return $this;
134  }
135 
141  public function getIsSupervisor()
142  {
143  return $this->_isSupervisor;
144  }
145 
152  public function getSharedComponent()
153  {
154  return $this->_parent->getSharedComponent()->getAlignment();
155  }
156 
162  public function getActiveSheet()
163  {
164  return $this->_parent->getActiveSheet();
165  }
166 
173  public function getSelectedCells()
174  {
175  return $this->getActiveSheet()->getSelectedCells();
176  }
177 
184  public function getActiveCell()
185  {
186  return $this->getActiveSheet()->getActiveCell();
187  }
188 
195  public function getStyleArray($array)
196  {
197  return array('alignment' => $array);
198  }
199 
218  public function applyFromArray($pStyles = null) {
219  if (is_array($pStyles)) {
220  if ($this->_isSupervisor) {
221  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
222  } else {
223  if (array_key_exists('horizontal', $pStyles)) {
224  $this->setHorizontal($pStyles['horizontal']);
225  }
226  if (array_key_exists('vertical', $pStyles)) {
227  $this->setVertical($pStyles['vertical']);
228  }
229  if (array_key_exists('rotation', $pStyles)) {
230  $this->setTextRotation($pStyles['rotation']);
231  }
232  if (array_key_exists('wrap', $pStyles)) {
233  $this->setWrapText($pStyles['wrap']);
234  }
235  if (array_key_exists('shrinkToFit', $pStyles)) {
236  $this->setShrinkToFit($pStyles['shrinkToFit']);
237  }
238  if (array_key_exists('indent', $pStyles)) {
239  $this->setIndent($pStyles['indent']);
240  }
241  }
242  } else {
243  throw new Exception("Invalid style array passed.");
244  }
245  return $this;
246  }
247 
253  public function getHorizontal() {
254  if ($this->_isSupervisor) {
255  return $this->getSharedComponent()->getHorizontal();
256  }
257  return $this->_horizontal;
258  }
259 
267  if ($pValue == '') {
269  }
270 
271  if ($this->_isSupervisor) {
272  $styleArray = $this->getStyleArray(array('horizontal' => $pValue));
273  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
274  }
275  else {
276  $this->_horizontal = $pValue;
277  }
278  return $this;
279  }
280 
286  public function getVertical() {
287  if ($this->_isSupervisor) {
288  return $this->getSharedComponent()->getVertical();
289  }
290  return $this->_vertical;
291  }
292 
300  if ($pValue == '') {
302  }
303 
304  if ($this->_isSupervisor) {
305  $styleArray = $this->getStyleArray(array('vertical' => $pValue));
306  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
307  } else {
308  $this->_vertical = $pValue;
309  }
310  return $this;
311  }
312 
318  public function getTextRotation() {
319  if ($this->_isSupervisor) {
320  return $this->getSharedComponent()->getTextRotation();
321  }
322  return $this->_textRotation;
323  }
324 
332  public function setTextRotation($pValue = 0) {
333  // Excel2007 value 255 => PHPExcel value -165
334  if ($pValue == 255) {
335  $pValue = -165;
336  }
337 
338  // Set rotation
339  if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
340  if ($this->_isSupervisor) {
341  $styleArray = $this->getStyleArray(array('rotation' => $pValue));
342  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
343  } else {
344  $this->_textRotation = $pValue;
345  }
346  } else {
347  throw new Exception("Text rotation should be a value between -90 and 90.");
348  }
349 
350  return $this;
351  }
352 
358  public function getWrapText() {
359  if ($this->_isSupervisor) {
360  return $this->getSharedComponent()->getWrapText();
361  }
362  return $this->_wrapText;
363  }
364 
371  public function setWrapText($pValue = false) {
372  if ($pValue == '') {
373  $pValue = false;
374  }
375  if ($this->_isSupervisor) {
376  $styleArray = $this->getStyleArray(array('wrap' => $pValue));
377  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
378  } else {
379  $this->_wrapText = $pValue;
380  }
381  return $this;
382  }
383 
389  public function getShrinkToFit() {
390  if ($this->_isSupervisor) {
391  return $this->getSharedComponent()->getShrinkToFit();
392  }
393  return $this->_shrinkToFit;
394  }
395 
402  public function setShrinkToFit($pValue = false) {
403  if ($pValue == '') {
404  $pValue = false;
405  }
406  if ($this->_isSupervisor) {
407  $styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
408  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
409  } else {
410  $this->_shrinkToFit = $pValue;
411  }
412  return $this;
413  }
414 
420  public function getIndent() {
421  if ($this->_isSupervisor) {
422  return $this->getSharedComponent()->getIndent();
423  }
424  return $this->_indent;
425  }
426 
433  public function setIndent($pValue = 0) {
434  if ($pValue > 0) {
435  if ($this->getHorizontal() != self::HORIZONTAL_GENERAL && $this->getHorizontal() != self::HORIZONTAL_LEFT && $this->getHorizontal() != self::HORIZONTAL_RIGHT) {
436  $pValue = 0; // indent not supported
437  }
438  }
439  if ($this->_isSupervisor) {
440  $styleArray = $this->getStyleArray(array('indent' => $pValue));
441  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
442  } else {
443  $this->_indent = $pValue;
444  }
445  return $this;
446  }
447 
453  public function getHashCode() {
454  if ($this->_isSupervisor) {
455  return $this->getSharedComponent()->getHashCode();
456  }
457  return md5(
458  $this->_horizontal
459  . $this->_vertical
460  . $this->_textRotation
461  . ($this->_wrapText ? 't' : 'f')
462  . ($this->_shrinkToFit ? 't' : 'f')
463  . $this->_indent
464  . __CLASS__
465  );
466  }
467 
471  public function __clone() {
472  $vars = get_object_vars($this);
473  foreach ($vars as $key => $value) {
474  if ((is_object($value)) && ($key != '_parent')) {
475  $this->$key = clone $value;
476  } else {
477  $this->$key = $value;
478  }
479  }
480  }
481 }