Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
32 / 32 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
Note | |
100.00% |
32 / 32 |
|
100.00% |
11 / 11 |
15 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
createRichTextShape | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getParent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setParent | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getOffsetX | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getOffsetY | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getExtentX | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getExtentY | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
getHashCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getHashIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setHashIndex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation\Slide; |
21 | |
22 | use PhpOffice\PhpPresentation\ComparableInterface; |
23 | use PhpOffice\PhpPresentation\GeometryCalculator; |
24 | use PhpOffice\PhpPresentation\Shape\RichText; |
25 | use PhpOffice\PhpPresentation\ShapeContainerInterface; |
26 | use PhpOffice\PhpPresentation\Slide; |
27 | use PhpOffice\PhpPresentation\Traits\ShapeCollection; |
28 | |
29 | class Note implements ComparableInterface, ShapeContainerInterface |
30 | { |
31 | use ShapeCollection; |
32 | |
33 | /** |
34 | * Parent slide. |
35 | * |
36 | * @var Slide |
37 | */ |
38 | private $parent; |
39 | |
40 | /** |
41 | * Note identifier. |
42 | * |
43 | * @var string |
44 | */ |
45 | private $identifier; |
46 | |
47 | /** |
48 | * Hash index. |
49 | * |
50 | * @var int |
51 | */ |
52 | private $hashIndex; |
53 | |
54 | /** |
55 | * Offset X. |
56 | * |
57 | * @var int |
58 | */ |
59 | protected $offsetX; |
60 | |
61 | /** |
62 | * Offset Y. |
63 | * |
64 | * @var int |
65 | */ |
66 | protected $offsetY; |
67 | |
68 | /** |
69 | * Extent X. |
70 | * |
71 | * @var int |
72 | */ |
73 | protected $extentX; |
74 | |
75 | /** |
76 | * Extent Y. |
77 | * |
78 | * @var int |
79 | */ |
80 | protected $extentY; |
81 | |
82 | /** |
83 | * Create a new note. |
84 | */ |
85 | public function __construct(?Slide $pParent = null) |
86 | { |
87 | // Set parent |
88 | $this->parent = $pParent; |
89 | |
90 | // Set identifier |
91 | $this->identifier = md5(mt_rand(0, 9999) . time()); |
92 | } |
93 | |
94 | /** |
95 | * Create rich text shape. |
96 | */ |
97 | public function createRichTextShape(): RichText |
98 | { |
99 | $shape = new RichText(); |
100 | $this->addShape($shape); |
101 | |
102 | return $shape; |
103 | } |
104 | |
105 | /** |
106 | * Get parent. |
107 | * |
108 | * @return Slide |
109 | */ |
110 | public function getParent() |
111 | { |
112 | return $this->parent; |
113 | } |
114 | |
115 | /** |
116 | * Set parent. |
117 | * |
118 | * @return Note |
119 | */ |
120 | public function setParent(Slide $parent) |
121 | { |
122 | $this->parent = $parent; |
123 | |
124 | return $this; |
125 | } |
126 | |
127 | /** |
128 | * Get X Offset. |
129 | */ |
130 | public function getOffsetX(): int |
131 | { |
132 | if (null === $this->offsetX) { |
133 | $offsets = GeometryCalculator::calculateOffsets($this); |
134 | $this->offsetX = $offsets[GeometryCalculator::X]; |
135 | $this->offsetY = $offsets[GeometryCalculator::Y]; |
136 | } |
137 | |
138 | return $this->offsetX; |
139 | } |
140 | |
141 | /** |
142 | * Get Y Offset. |
143 | */ |
144 | public function getOffsetY(): int |
145 | { |
146 | if (null === $this->offsetY) { |
147 | $offsets = GeometryCalculator::calculateOffsets($this); |
148 | $this->offsetX = $offsets[GeometryCalculator::X]; |
149 | $this->offsetY = $offsets[GeometryCalculator::Y]; |
150 | } |
151 | |
152 | return $this->offsetY; |
153 | } |
154 | |
155 | /** |
156 | * Get X Extent. |
157 | */ |
158 | public function getExtentX(): int |
159 | { |
160 | if (null === $this->extentX) { |
161 | $extents = GeometryCalculator::calculateExtents($this); |
162 | $this->extentX = $extents[GeometryCalculator::X]; |
163 | $this->extentY = $extents[GeometryCalculator::Y]; |
164 | } |
165 | |
166 | return $this->extentX; |
167 | } |
168 | |
169 | /** |
170 | * Get Y Extent. |
171 | */ |
172 | public function getExtentY(): int |
173 | { |
174 | if (null === $this->extentY) { |
175 | $extents = GeometryCalculator::calculateExtents($this); |
176 | $this->extentX = $extents[GeometryCalculator::X]; |
177 | $this->extentY = $extents[GeometryCalculator::Y]; |
178 | } |
179 | |
180 | return $this->extentY; |
181 | } |
182 | |
183 | /** |
184 | * Get hash code. |
185 | * |
186 | * @return string Hash code |
187 | */ |
188 | public function getHashCode(): string |
189 | { |
190 | return md5($this->identifier . __CLASS__); |
191 | } |
192 | |
193 | /** |
194 | * Get hash index. |
195 | * |
196 | * Note that this index may vary during script execution! Only reliable moment is |
197 | * while doing a write of a workbook and when changes are not allowed. |
198 | * |
199 | * @return null|int Hash index |
200 | */ |
201 | public function getHashIndex(): ?int |
202 | { |
203 | return $this->hashIndex; |
204 | } |
205 | |
206 | /** |
207 | * Set hash index. |
208 | * |
209 | * Note that this index may vary during script execution! Only reliable moment is |
210 | * while doing a write of a workbook and when changes are not allowed. |
211 | * |
212 | * @param int $value Hash index |
213 | * |
214 | * @return $this |
215 | */ |
216 | public function setHashIndex(int $value) |
217 | { |
218 | $this->hashIndex = $value; |
219 | |
220 | return $this; |
221 | } |
222 | } |