1 | <?php |
||
16 | class SheetIterator implements IteratorInterface |
||
17 | { |
||
18 | const CONTENT_XML_FILE_PATH = 'content.xml'; |
||
19 | |||
20 | const XML_STYLE_NAMESPACE = 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'; |
||
21 | |||
22 | /** Definition of XML nodes name and attribute used to parse sheet data */ |
||
23 | const XML_NODE_AUTOMATIC_STYLES = 'office:automatic-styles'; |
||
24 | const XML_NODE_STYLE = 'style'; |
||
25 | const XML_NODE_STYLE_TABLE_PROPERTIES = 'table-properties'; |
||
26 | const XML_NODE_TABLE = 'table:table'; |
||
27 | const XML_ATTRIBUTE_STYLE_NAME = 'style:name'; |
||
28 | const XML_ATTRIBUTE_TABLE_NAME = 'table:name'; |
||
29 | const XML_ATTRIBUTE_TABLE_STYLE_NAME = 'table:style-name'; |
||
30 | const XML_ATTRIBUTE_TABLE_DISPLAY = 'table:display'; |
||
31 | |||
32 | /** @var string $filePath Path of the file to be read */ |
||
33 | protected $filePath; |
||
34 | |||
35 | /** @var \Box\Spout\Common\Manager\OptionsManagerInterface Reader's options manager */ |
||
36 | protected $optionsManager; |
||
37 | |||
38 | /** @var EntityFactory $entityFactory Factory to create entities */ |
||
39 | protected $entityFactory; |
||
40 | |||
41 | /** @var XMLReader The XMLReader object that will help read sheet's XML data */ |
||
42 | protected $xmlReader; |
||
43 | |||
44 | /** @var \Box\Spout\Common\Helper\Escaper\ODS Used to unescape XML data */ |
||
45 | protected $escaper; |
||
46 | |||
47 | /** @var bool Whether there are still at least a sheet to be read */ |
||
48 | protected $hasFoundSheet; |
||
49 | |||
50 | /** @var int The index of the sheet being read (zero-based) */ |
||
51 | protected $currentSheetIndex; |
||
52 | |||
53 | /** @var string The name of the sheet that was defined as active */ |
||
54 | protected $activeSheetName; |
||
55 | |||
56 | /** @var array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] */ |
||
57 | protected $sheetsVisibility; |
||
58 | |||
59 | /** |
||
60 | * @param string $filePath Path of the file to be read |
||
61 | * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager |
||
62 | * @param \Box\Spout\Common\Helper\Escaper\ODS $escaper Used to unescape XML data |
||
63 | * @param SettingsHelper $settingsHelper Helper to get data from "settings.xml" |
||
64 | * @param EntityFactory $entityFactory Factory to create entities |
||
65 | */ |
||
66 | 31 | public function __construct($filePath, $optionsManager, $escaper, $settingsHelper, $entityFactory) |
|
75 | |||
76 | /** |
||
77 | * Rewind the Iterator to the first element |
||
78 | * @see http://php.net/manual/en/iterator.rewind.php |
||
79 | * |
||
80 | * @throws \Box\Spout\Common\Exception\IOException If unable to open the XML file containing sheets' data |
||
81 | * @return void |
||
82 | */ |
||
83 | 31 | public function rewind() |
|
101 | |||
102 | /** |
||
103 | * Extracts the visibility of the sheets |
||
104 | * |
||
105 | * @return array Associative array [STYLE_NAME] => [IS_SHEET_VISIBLE] |
||
106 | */ |
||
107 | 30 | private function readSheetsVisibility() |
|
129 | |||
130 | /** |
||
131 | * Checks if current position is valid |
||
132 | * @see http://php.net/manual/en/iterator.valid.php |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | 29 | public function valid() |
|
140 | |||
141 | /** |
||
142 | * Move forward to next element |
||
143 | * @see http://php.net/manual/en/iterator.next.php |
||
144 | * |
||
145 | * @return void |
||
146 | */ |
||
147 | 28 | public function next() |
|
155 | |||
156 | /** |
||
157 | * Return the current element |
||
158 | * @see http://php.net/manual/en/iterator.current.php |
||
159 | * |
||
160 | * @return \Box\Spout\Reader\ODS\Sheet |
||
161 | */ |
||
162 | 29 | public function current() |
|
181 | |||
182 | /** |
||
183 | * Returns whether the current sheet was defined as the active one |
||
184 | * |
||
185 | * @param string $sheetName Name of the current sheet |
||
186 | * @param int $sheetIndex Index of the current sheet |
||
187 | * @param string|null $activeSheetName Name of the sheet that was defined as active or NULL if none defined |
||
188 | * @return bool Whether the current sheet was defined as the active one |
||
189 | */ |
||
190 | 29 | private function isSheetActive($sheetName, $sheetIndex, $activeSheetName) |
|
199 | |||
200 | /** |
||
201 | * Returns whether the current sheet is visible |
||
202 | * |
||
203 | * @param string $sheetStyleName Name of the sheet style |
||
204 | * @return bool Whether the current sheet is visible |
||
205 | */ |
||
206 | 29 | private function isSheetVisible($sheetStyleName) |
|
212 | |||
213 | /** |
||
214 | * Return the key of the current element |
||
215 | * @see http://php.net/manual/en/iterator.key.php |
||
216 | * |
||
217 | * @return int |
||
218 | */ |
||
219 | 24 | public function key() |
|
223 | |||
224 | /** |
||
225 | * Cleans up what was created to iterate over the object. |
||
226 | * |
||
227 | * @return void |
||
228 | */ |
||
229 | 28 | public function end() |
|
233 | } |
||
234 |