ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
PageSetup.php
Go to the documentation of this file.
1 <?php
108 {
109  /* Paper size */
110  const PAPERSIZE_LETTER = 1;
112  const PAPERSIZE_TABLOID = 3;
113  const PAPERSIZE_LEDGER = 4;
114  const PAPERSIZE_LEGAL = 5;
117  const PAPERSIZE_A3 = 8;
118  const PAPERSIZE_A4 = 9;
119  const PAPERSIZE_A4_SMALL = 10;
120  const PAPERSIZE_A5 = 11;
121  const PAPERSIZE_B4 = 12;
122  const PAPERSIZE_B5 = 13;
123  const PAPERSIZE_FOLIO = 14;
124  const PAPERSIZE_QUARTO = 15;
127  const PAPERSIZE_NOTE = 18;
133  const PAPERSIZE_C = 24;
134  const PAPERSIZE_D = 25;
135  const PAPERSIZE_E = 26;
151  const PAPERSIZE_ISO_B4 = 42;
173  const PAPERSIZE_A2_PAPER = 64;
176 
177  /* Page orientation */
178  const ORIENTATION_DEFAULT = 'default';
179  const ORIENTATION_LANDSCAPE = 'landscape';
180  const ORIENTATION_PORTRAIT = 'portrait';
181 
182  /* Print Range Set Method */
184  const SETPRINTRANGE_INSERT = 'I';
185 
186 
193 
200 
209  private $_scale = 100;
210 
217  private $_fitToPage = false;
218 
225  private $_fitToHeight = 1;
226 
233  private $_fitToWidth = 1;
234 
240  private $_columnsToRepeatAtLeft = array('', '');
241 
247  private $_rowsToRepeatAtTop = array(0, 0);
248 
254  private $_horizontalCentered = false;
255 
261  private $_verticalCentered = false;
262 
268  private $_printArea = null;
269 
275  private $_firstPageNumber = null;
276 
280  public function __construct()
281  {
282  }
283 
289  public function getPaperSize() {
290  return $this->_paperSize;
291  }
292 
300  $this->_paperSize = $pValue;
301  return $this;
302  }
303 
309  public function getOrientation() {
310  return $this->_orientation;
311  }
312 
320  $this->_orientation = $pValue;
321  return $this;
322  }
323 
329  public function getScale() {
330  return $this->_scale;
331  }
332 
344  public function setScale($pValue = 100, $pUpdate = true) {
345  // Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
346  // but it is apparently still able to handle any scale >= 0, where 0 results in 100
347  if (($pValue >= 0) || is_null($pValue)) {
348  $this->_scale = $pValue;
349  if ($pUpdate) {
350  $this->_fitToPage = false;
351  }
352  } else {
353  throw new Exception("Scale must not be negative");
354  }
355  return $this;
356  }
357 
363  public function getFitToPage() {
364  return $this->_fitToPage;
365  }
366 
373  public function setFitToPage($pValue = true) {
374  $this->_fitToPage = $pValue;
375  return $this;
376  }
377 
383  public function getFitToHeight() {
384  return $this->_fitToHeight;
385  }
386 
394  public function setFitToHeight($pValue = 1, $pUpdate = true) {
395  $this->_fitToHeight = $pValue;
396  if ($pUpdate) {
397  $this->_fitToPage = true;
398  }
399  return $this;
400  }
401 
407  public function getFitToWidth() {
408  return $this->_fitToWidth;
409  }
410 
418  public function setFitToWidth($pValue = 1, $pUpdate = true) {
419  $this->_fitToWidth = $pValue;
420  if ($pUpdate) {
421  $this->_fitToPage = true;
422  }
423  return $this;
424  }
425 
431  public function isColumnsToRepeatAtLeftSet() {
432  if (is_array($this->_columnsToRepeatAtLeft)) {
433  if ($this->_columnsToRepeatAtLeft[0] != '' && $this->_columnsToRepeatAtLeft[1] != '') {
434  return true;
435  }
436  }
437 
438  return false;
439  }
440 
446  public function getColumnsToRepeatAtLeft() {
448  }
449 
456  public function setColumnsToRepeatAtLeft($pValue = null) {
457  if (is_array($pValue)) {
458  $this->_columnsToRepeatAtLeft = $pValue;
459  }
460  return $this;
461  }
462 
470  public function setColumnsToRepeatAtLeftByStartAndEnd($pStart = 'A', $pEnd = 'A') {
471  $this->_columnsToRepeatAtLeft = array($pStart, $pEnd);
472  return $this;
473  }
474 
480  public function isRowsToRepeatAtTopSet() {
481  if (is_array($this->_rowsToRepeatAtTop)) {
482  if ($this->_rowsToRepeatAtTop[0] != 0 && $this->_rowsToRepeatAtTop[1] != 0) {
483  return true;
484  }
485  }
486 
487  return false;
488  }
489 
495  public function getRowsToRepeatAtTop() {
497  }
498 
505  public function setRowsToRepeatAtTop($pValue = null) {
506  if (is_array($pValue)) {
507  $this->_rowsToRepeatAtTop = $pValue;
508  }
509  return $this;
510  }
511 
519  public function setRowsToRepeatAtTopByStartAndEnd($pStart = 1, $pEnd = 1) {
520  $this->_rowsToRepeatAtTop = array($pStart, $pEnd);
521  return $this;
522  }
523 
529  public function getHorizontalCentered() {
531  }
532 
539  public function setHorizontalCentered($value = false) {
540  $this->_horizontalCentered = $value;
541  return $this;
542  }
543 
549  public function getVerticalCentered() {
551  }
552 
559  public function setVerticalCentered($value = false) {
560  $this->_verticalCentered = $value;
561  return $this;
562  }
563 
574  public function getPrintArea($index = 0) {
575  if ($index == 0) {
576  return $this->_printArea;
577  }
578  $printAreas = explode(',',$this->_printArea);
579  if (isset($printAreas[$index-1])) {
580  return $printAreas[$index-1];
581  }
582  throw new Exception("Requested Print Area does not exist");
583  }
584 
594  public function isPrintAreaSet($index = 0) {
595  if ($index == 0) {
596  return !is_null($this->_printArea);
597  }
598  $printAreas = explode(',',$this->_printArea);
599  return isset($printAreas[$index-1]);
600  }
601 
611  public function clearPrintArea($index = 0) {
612  if ($index == 0) {
613  $this->_printArea = NULL;
614  } else {
615  $printAreas = explode(',',$this->_printArea);
616  if (isset($printAreas[$index-1])) {
617  unset($printAreas[$index-1]);
618  $this->_printArea = implode(',',$printAreas);
619  }
620  }
621 
622  return $this;
623  }
624 
645  public function setPrintArea($value, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) {
646  if (strpos($value,'!') !== false) {
647  throw new Exception('Cell coordinate must not specify a worksheet.');
648  } elseif (strpos($value,':') === false) {
649  throw new Exception('Cell coordinate must be a range of cells.');
650  } elseif (strpos($value,'$') !== false) {
651  throw new Exception('Cell coordinate must not be absolute.');
652  }
653  $value = strtoupper($value);
654 
655  if ($method == self::SETPRINTRANGE_OVERWRITE) {
656  if ($index == 0) {
657  $this->_printArea = $value;
658  } else {
659  $printAreas = explode(',',$this->_printArea);
660  if($index < 0) {
661  $index = count($printAreas) - abs($index) + 1;
662  }
663  if (($index <= 0) || ($index > count($printAreas))) {
664  throw new Exception('Invalid index for setting print range.');
665  }
666  $printAreas[$index-1] = $value;
667  $this->_printArea = implode(',',$printAreas);
668  }
669  } elseif($method == self::SETPRINTRANGE_INSERT) {
670  if ($index == 0) {
671  $this->_printArea .= ($this->_printArea == '') ? $value : ','.$value;
672  } else {
673  $printAreas = explode(',',$this->_printArea);
674  if($index < 0) {
675  $index = abs($index) - 1;
676  }
677  if ($index > count($printAreas)) {
678  throw new Exception('Invalid index for setting print range.');
679  }
680  $printAreas = array_merge(array_slice($printAreas,0,$index),array($value),array_slice($printAreas,$index));
681  $this->_printArea = implode(',',$printAreas);
682  }
683  } else {
684  throw new Exception('Invalid method for setting print range.');
685  }
686 
687  return $this;
688  }
689 
703  public function addPrintArea($value, $index = -1) {
704  return $this->setPrintArea($value, $index, self::SETPRINTRANGE_INSERT);
705  }
706 
730  public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE)
731  {
732  return $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, $method);
733  }
734 
751  public function addPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = -1)
752  {
753  return $this->setPrintArea(PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, self::SETPRINTRANGE_INSERT);
754  }
755 
761  public function getFirstPageNumber() {
763  }
764 
771  public function setFirstPageNumber($value = null) {
772  $this->_firstPageNumber = $value;
773  return $this;
774  }
775 
781  public function resetFirstPageNumber() {
782  return $this->setFirstPageNumber(null);
783  }
784 
788  public function __clone() {
789  $vars = get_object_vars($this);
790  foreach ($vars as $key => $value) {
791  if (is_object($value)) {
792  $this->$key = clone $value;
793  } else {
794  $this->$key = $value;
795  }
796  }
797  }
798 }