MDL-63044 course: add get_enrolled_courses_by_timeline_classification
[moodle.git] / lib / phpexcel / PHPExcel / NamedRange.php
blob2848db838bce7a6ec1d22294c688c9deaf7116a2
1 <?php
3 /**
4 * PHPExcel_NamedRange
6 * Copyright (c) 2006 - 2015 PHPExcel
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @category PHPExcel
23 * @package PHPExcel
24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version ##VERSION##, ##DATE##
28 class PHPExcel_NamedRange
30 /**
31 * Range name
33 * @var string
35 private $name;
37 /**
38 * Worksheet on which the named range can be resolved
40 * @var PHPExcel_Worksheet
42 private $worksheet;
44 /**
45 * Range of the referenced cells
47 * @var string
49 private $range;
51 /**
52 * Is the named range local? (i.e. can only be used on $this->worksheet)
54 * @var bool
56 private $localOnly;
58 /**
59 * Scope
61 * @var PHPExcel_Worksheet
63 private $scope;
65 /**
66 * Create a new NamedRange
68 * @param string $pName
69 * @param PHPExcel_Worksheet $pWorksheet
70 * @param string $pRange
71 * @param bool $pLocalOnly
72 * @param PHPExcel_Worksheet|null $pScope Scope. Only applies when $pLocalOnly = true. Null for global scope.
73 * @throws PHPExcel_Exception
75 public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null)
77 // Validate data
78 if (($pName === null) || ($pWorksheet === null) || ($pRange === null)) {
79 throw new PHPExcel_Exception('Parameters can not be null.');
82 // Set local members
83 $this->name = $pName;
84 $this->worksheet = $pWorksheet;
85 $this->range = $pRange;
86 $this->localOnly = $pLocalOnly;
87 $this->scope = ($pLocalOnly == true) ? (($pScope == null) ? $pWorksheet : $pScope) : null;
90 /**
91 * Get name
93 * @return string
95 public function getName()
97 return $this->name;
101 * Set name
103 * @param string $value
104 * @return PHPExcel_NamedRange
106 public function setName($value = null)
108 if ($value !== null) {
109 // Old title
110 $oldTitle = $this->name;
112 // Re-attach
113 if ($this->worksheet !== null) {
114 $this->worksheet->getParent()->removeNamedRange($this->name, $this->worksheet);
116 $this->name = $value;
118 if ($this->worksheet !== null) {
119 $this->worksheet->getParent()->addNamedRange($this);
122 // New title
123 $newTitle = $this->name;
124 PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->worksheet->getParent(), $oldTitle, $newTitle);
126 return $this;
130 * Get worksheet
132 * @return PHPExcel_Worksheet
134 public function getWorksheet()
136 return $this->worksheet;
140 * Set worksheet
142 * @param PHPExcel_Worksheet $value
143 * @return PHPExcel_NamedRange
145 public function setWorksheet(PHPExcel_Worksheet $value = null)
147 if ($value !== null) {
148 $this->worksheet = $value;
150 return $this;
154 * Get range
156 * @return string
158 public function getRange()
160 return $this->range;
164 * Set range
166 * @param string $value
167 * @return PHPExcel_NamedRange
169 public function setRange($value = null)
171 if ($value !== null) {
172 $this->range = $value;
174 return $this;
178 * Get localOnly
180 * @return bool
182 public function getLocalOnly()
184 return $this->localOnly;
188 * Set localOnly
190 * @param bool $value
191 * @return PHPExcel_NamedRange
193 public function setLocalOnly($value = false)
195 $this->localOnly = $value;
196 $this->scope = $value ? $this->worksheet : null;
197 return $this;
201 * Get scope
203 * @return PHPExcel_Worksheet|null
205 public function getScope()
207 return $this->scope;
211 * Set scope
213 * @param PHPExcel_Worksheet|null $value
214 * @return PHPExcel_NamedRange
216 public function setScope(PHPExcel_Worksheet $value = null)
218 $this->scope = $value;
219 $this->localOnly = ($value == null) ? false : true;
220 return $this;
224 * Resolve a named range to a regular cell range
226 * @param string $pNamedRange Named range
227 * @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope
228 * @return PHPExcel_NamedRange
230 public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet)
232 return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet);
236 * Implement PHP __clone to create a deep clone, not just a shallow copy.
238 public function __clone()
240 $vars = get_object_vars($this);
241 foreach ($vars as $key => $value) {
242 if (is_object($value)) {
243 $this->$key = clone $value;
244 } else {
245 $this->$key = $value;