5
* Copyright (c) 2006 - 2009 PHPExcel
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
* @package PHPExcel_Style
23
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
24
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25
* @version 1.4.5, 2007-08-23
29
/** PHPExcel root directory */
30
if (!defined('PHPEXCEL_ROOT')) {
34
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
37
/** PHPExcel_IComparable */
38
require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
42
* PHPExcel_Style_Protection
45
* @package PHPExcel_Style
46
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
48
class PHPExcel_Style_Protection implements PHPExcel_IComparable
50
/** Protection styles */
51
const PROTECTION_INHERIT = 'inherit';
52
const PROTECTION_PROTECTED = 'protected';
53
const PROTECTION_UNPROTECTED = 'unprotected';
72
* @var _parentPropertyName string
74
private $_parentPropertyName;
81
private $_isSupervisor;
84
* Parent. Only used for supervisor
91
* Create a new PHPExcel_Style_Protection
93
public function __construct($isSupervisor = false)
96
$this->_isSupervisor = $isSupervisor;
99
$this->_locked = self::PROTECTION_INHERIT;
100
$this->_hidden = self::PROTECTION_INHERIT;
104
* Bind parent. Only used for supervisor
106
* @param PHPExcel_Style $parent
107
* @return PHPExcel_Style_Protection
109
public function bindParent($parent)
111
$this->_parent = $parent;
116
* Is this a supervisor or a real style component?
120
public function getIsSupervisor()
122
return $this->_isSupervisor;
126
* Get the shared style component for the currently active cell in currently active sheet.
127
* Only used for style supervisor
129
* @return PHPExcel_Style_Protection
131
public function getSharedComponent()
133
return $this->_parent->getSharedComponent()->getProtection();
137
* Get the currently active sheet. Only used for supervisor
139
* @return PHPExcel_Worksheet
141
public function getActiveSheet()
143
return $this->_parent->getActiveSheet();
147
* Get the currently active cell coordinate in currently active sheet.
148
* Only used for supervisor
150
* @return string E.g. 'A1'
152
public function getXSelectedCells()
154
return $this->getActiveSheet()->getXSelectedCells();
158
* Get the currently active cell coordinate in currently active sheet.
159
* Only used for supervisor
161
* @return string E.g. 'A1'
163
public function getXActiveCell()
165
return $this->getActiveSheet()->getXActiveCell();
169
* Build style array from subcomponents
171
* @param array $array
174
public function getStyleArray($array)
176
return array('protection' => $array);
180
* Apply styles from array
183
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getLocked()->applyFromArray( array('locked' => true, 'hidden' => false) );
186
* @param array $pStyles Array containing style information
188
* @return PHPExcel_Style_Protection
190
public function applyFromArray($pStyles = null) {
191
if (is_array($pStyles)) {
192
if ($this->_isSupervisor) {
193
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
195
if (array_key_exists('locked', $pStyles)) {
196
$this->setLocked($pStyles['locked']);
198
if (array_key_exists('hidden', $pStyles)) {
199
$this->setHidden($pStyles['hidden']);
203
throw new Exception("Invalid style array passed.");
213
public function getLocked() {
214
if ($this->_isSupervisor) {
215
return $this->getSharedComponent()->getLocked();
217
return $this->_locked;
223
* @param string $pValue
224
* @return PHPExcel_Style_Protection
226
public function setLocked($pValue = self::PROTECTION_INHERIT) {
227
if ($this->_isSupervisor) {
228
$styleArray = $this->getStyleArray(array('locked' => $pValue));
229
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
231
$this->_locked = $pValue;
241
public function getHidden() {
242
if ($this->_isSupervisor) {
243
return $this->getSharedComponent()->getHidden();
245
return $this->_hidden;
251
* @param string $pValue
252
* @return PHPExcel_Style_Protection
254
public function setHidden($pValue = self::PROTECTION_INHERIT) {
255
if ($this->_isSupervisor) {
256
$styleArray = $this->getStyleArray(array('hidden' => $pValue));
257
$this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
259
$this->_hidden = $pValue;
267
* @return string Hash code
269
public function getHashCode() {
270
if ($this->_isSupervisor) {
271
return $this->getSharedComponent()->getHashCode();
290
* Note that this index may vary during script execution! Only reliable moment is
291
* while doing a write of a workbook and when changes are not allowed.
293
* @return string Hash index
295
public function getHashIndex() {
296
return $this->_hashIndex;
302
* Note that this index may vary during script execution! Only reliable moment is
303
* while doing a write of a workbook and when changes are not allowed.
305
* @param string $value Hash index
307
public function setHashIndex($value) {
308
$this->_hashIndex = $value;
312
* Implement PHP __clone to create a deep clone, not just a shallow copy.
314
public function __clone() {
315
$vars = get_object_vars($this);
316
foreach ($vars as $key => $value) {
317
if (is_object($value)) {
318
$this->$key = clone $value;
320
$this->$key = $value;