ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
NamedRange.php
Go to the documentation of this file.
1 <?php
37 {
43  private $_name;
44 
50  private $_worksheet;
51 
57  private $_range;
58 
64  private $_localOnly;
65 
71  private $_scope;
72 
82  public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null)
83  {
84  // Validate data
85  if (is_null($pName) || is_null($pWorksheet)|| is_null($pRange)) {
86  throw new Exception('Parameters can not be null.');
87  }
88 
89  // Set local members
90  $this->_name = $pName;
91  $this->_worksheet = $pWorksheet;
92  $this->_range = $pRange;
93  $this->_localOnly = $pLocalOnly;
94  $this->_scope = ($pLocalOnly == true) ?
95  (($pScope == null) ? $pWorksheet : $pScope) : null;
96  }
97 
103  public function getName() {
104  return $this->_name;
105  }
106 
113  public function setName($value = null) {
114  if (!is_null($value)) {
115  // Old title
116  $oldTitle = $this->_name;
117 
118  // Re-attach
119  if (!is_null($this->_worksheet)) {
120  $this->_worksheet->getParent()->removeNamedRange($this->_name,$this->_worksheet);
121  }
122  $this->_name = $value;
123 
124  if (!is_null($this->_worksheet)) {
125  $this->_worksheet->getParent()->addNamedRange($this);
126  }
127 
128  // New title
129  $newTitle = $this->_name;
130  PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->_worksheet->getParent(), $oldTitle, $newTitle);
131  }
132  return $this;
133  }
134 
140  public function getWorksheet() {
141  return $this->_worksheet;
142  }
143 
150  public function setWorksheet(PHPExcel_Worksheet $value = null) {
151  if (!is_null($value)) {
152  $this->_worksheet = $value;
153  }
154  return $this;
155  }
156 
162  public function getRange() {
163  return $this->_range;
164  }
165 
172  public function setRange($value = null) {
173  if (!is_null($value)) {
174  $this->_range = $value;
175  }
176  return $this;
177  }
178 
184  public function getLocalOnly() {
185  return $this->_localOnly;
186  }
187 
194  public function setLocalOnly($value = false) {
195  $this->_localOnly = $value;
196  $this->_scope = $value ? $this->_worksheet : null;
197  return $this;
198  }
199 
205  public function getScope() {
206  return $this->_scope;
207  }
208 
215  public function setScope(PHPExcel_Worksheet $value = null) {
216  $this->_scope = $value;
217  $this->_localOnly = ($value == null) ? false : true;
218  return $this;
219  }
220 
228  public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) {
229  return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet);
230  }
231 
235  public function __clone() {
236  $vars = get_object_vars($this);
237  foreach ($vars as $key => $value) {
238  if (is_object($value)) {
239  $this->$key = clone $value;
240  } else {
241  $this->$key = $value;
242  }
243  }
244  }
245 }