summaryrefslogtreecommitdiffstats
path: root/admin/exportclases/PHPPowerPoint.php
blob: 486a5a67efe8e0c20ed318f4adaef7291c03c4ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
 * PHPPowerPoint
 *
 * Copyright (c) 2009 - 2010 PHPPowerPoint
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPPowerPoint
 * @package    PHPPowerPoint
 * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt	LGPL
 * @version    0.1.0, 2009-04-27
 */


/** PHPPowerPoint_Slide */
require_once 'PHPPowerPoint/Slide.php';

/** PHPPowerPoint_DocumentProperties */
require_once 'PHPPowerPoint/DocumentProperties.php';

/** PHPPowerPoint_Shared_ZipStreamWrapper */
require_once 'PHPPowerPoint/Shared/ZipStreamWrapper.php';

/** PHPPowerPoint_SlideIterator */
require_once 'PHPPowerPoint/SlideIterator.php';


/**
 * PHPPowerPoint
 *
 * @category   PHPPowerPoint
 * @package    PHPPowerPoint
 * @copyright  Copyright (c) 2009 - 2010 PHPPowerPoint (http://www.codeplex.com/PHPPowerPoint)
 */
class PHPPowerPoint
{
	/**
	 * Document properties
	 *
	 * @var PHPPowerPoint_DocumentProperties
	 */
	private $_properties;

	/**
	 * Collection of Slide objects
	 *
	 * @var PHPPowerPoint_Slide[]
	 */
	private $_slideCollection = array();

	/**
	 * Active slide index
	 *
	 * @var int
	 */
	private $_activeSlideIndex = 0;

	/**
	 * Create a new PHPPowerPoint with one Slide
	 */
	public function __construct()
	{
		// Initialise slide collection and add one slide
		$this->_slideCollection = array();
		$this->_slideCollection[] = new PHPPowerPoint_Slide($this);
		$this->_activeSlideIndex = 0;

		// Create document properties
		$this->_properties = new PHPPowerPoint_DocumentProperties();
	}

	/**
	 * Get properties
	 *
	 * @return PHPPowerPoint_DocumentProperties
	 */
	public function getProperties()
	{
		return $this->_properties;
	}

	/**
	 * Set properties
	 *
	 * @param PHPPowerPoint_DocumentProperties	$value
	 */
	public function setProperties(PHPPowerPoint_DocumentProperties $value)
	{
		$this->_properties = $value;
	}

	/**
	 * Get active slide
	 *
	 * @return PHPPowerPoint_Slide
	 */
	public function getActiveSlide()
	{
		return $this->_slideCollection[$this->_activeSlideIndex];
	}

	/**
	 * Create slide and add it to this presentation
	 *
	 * @return PHPPowerPoint_Slide
	 */
	public function createSlide()
	{
		$newSlide = new PHPPowerPoint_Slide($this);

		$this->addSlide($newSlide);

		return $newSlide;
	}

	/**
	 * Add slide
	 *
	 * @param PHPPowerPoint_Slide $slide
	 * @throws Exception
	 */
	public function addSlide(PHPPowerPoint_Slide $slide = null)
	{
		$this->_slideCollection[] = $slide;
	}

	/**
	 * Remove slide by index
	 *
	 * @param int $index Slide index
	 * @throws Exception
	 */
	public function removeSlideByIndex($index = 0)
	{
		if ($index > count($this->_slideCollection) - 1) {
			throw new Exception("Slide index is out of bounds.");
		} else {
			array_splice($this->_slideCollection, $index, 1);
		}
	}

	/**
	 * Get slide by index
	 *
	 * @param int $index Slide index
	 * @return PHPPowerPoint_Slide
	 * @throws Exception
	 */
	public function getSlide($index = 0)
	{
		if ($index > count($this->_slideCollection) - 1) {
			throw new Exception("Slide index is out of bounds.");
		} else {
			return $this->_slideCollection[$index];
		}
	}

	/**
	 * Get all slides
	 *
	 * @return PHPPowerPoint_Slide[]
	 */
	public function getAllSlides()
	{
		return $this->_slideCollection;
	}

	/**
	 * Get index for slide
	 *
	 * @param PHPPowerPoint_Slide $slide
	 * @return Slide index
	 * @throws Exception
	 */
	public function getIndex(PHPPowerPoint_Slide $slide)
	{
		foreach ($this->_slideCollection as $key => $value) {
			if ($value->getHashCode() == $slide->getHashCode()) {
				return $key;
			}
		}
	}

	/**
	 * Get slide count
	 *
	 * @return int
	 */
	public function getSlideCount()
	{
		return count($this->_slideCollection);
	}

	/**
	 * Get active slide index
	 *
	 * @return int Active slide index
	 */
	public function getActiveSlideIndex()
	{
		return $this->_activeSlideIndex;
	}

	/**
	 * Set active slide index
	 *
	 * @param int $index Active slide index
	 * @throws Exception
	 */
	public function setActiveSlideIndex($index = 0)
	{
		if ($index > count($this->_slideCollection) - 1) {
			throw new Exception("Active slide index is out of bounds.");
		} else {
			$this->_activeSlideIndex = $index;
		}
	}

	/**
	 * Add external slide
	 *
	 * @param PHPPowerPoint_Slide $slide External slide to add
	 * @throws Exception
	 */
	public function addExternalSheet(PHPPowerPoint_Slide $slide) {
		$slide->rebindParent($this);
		$this->addSheet($slide);
	}

	/**
	 * Get slide iterator
	 *
	 * @return PHPPowerPoint_SlideIterator
	 */
	public function getSlideIterator() {
		return new PHPPowerPoint_SlideIterator($this);
	}

	/**
	 * Copy presentation (!= clone!)
	 *
	 * @return PHPPowerPoint
	 */
	public function copy() {
		$copied = clone $this;

		$slideCount = count($this->_slideCollection);
		for ($i = 0; $i < $slideCount; ++$i) {
			$this->_slideCollection[$i] = $this->_slideCollection[$i]->copy();
			$this->_slideCollection[$i]->rebindParent($this);
		}

		return $copied;
	}

	/**
	 * Implement PHP __clone to create a deep clone, not just a shallow copy.
	 */
	public function __clone() {
		$vars = get_object_vars($this);
		foreach ($vars as $key => $value) {
			if (is_object($value)) {
				$this->$key = clone $value;
			} else {
				$this->$key = $value;
			}
		}
	}
}