|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU General Public License version 3 or later. |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
15
|
|
|
use Kitodo\Dlf\Common\MetsDocument; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\MathUtility; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Controller class for plugin 'Table Of Contents'. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Sebastian Meyer <[email protected]> |
|
23
|
|
|
* @package TYPO3 |
|
24
|
|
|
* @subpackage dlf |
|
25
|
|
|
* @access public |
|
26
|
|
|
*/ |
|
27
|
|
|
class TableOfContentsController extends AbstractController |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* This holds the active entries according to the currently selected page |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
* @access protected |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $activeEntries = []; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* This builds an array for one menu entry |
|
39
|
|
|
* |
|
40
|
|
|
* @access protected |
|
41
|
|
|
* |
|
42
|
|
|
* @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
|
43
|
|
|
* @param bool $recursive : Whether to include the child entries |
|
44
|
|
|
* |
|
45
|
|
|
* @return array HMENU array for menu entry |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function getMenuEntry(array $entry, $recursive = false) |
|
48
|
|
|
{ |
|
49
|
|
|
$entry = $this->resolveMenuEntry($entry); |
|
50
|
|
|
|
|
51
|
|
|
$entryArray = []; |
|
52
|
|
|
// Set "title", "volume", "type" and "pagination" from $entry array. |
|
53
|
|
|
$entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
|
54
|
|
|
$entryArray['volume'] = $entry['volume']; |
|
55
|
|
|
$entryArray['orderlabel'] = $entry['orderlabel']; |
|
56
|
|
|
$entryArray['type'] = Helper::translate($entry['type'], 'tx_dlf_structures', $this->settings['storagePid']); |
|
57
|
|
|
$entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
|
58
|
|
|
$entryArray['_OVERRIDE_HREF'] = ''; |
|
59
|
|
|
$entryArray['doNotLinkIt'] = 1; |
|
60
|
|
|
$entryArray['ITEM_STATE'] = 'NO'; |
|
61
|
|
|
// Build menu links based on the $entry['points'] array. |
|
62
|
|
|
if ( |
|
63
|
|
|
!empty($entry['points']) |
|
64
|
|
|
&& MathUtility::canBeInterpretedAsInteger($entry['points']) |
|
65
|
|
|
) { |
|
66
|
|
|
$entryArray['page'] = $entry['points']; |
|
67
|
|
|
|
|
68
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
69
|
|
|
if ($this->settings['basketButton']) { |
|
70
|
|
|
$entryArray['basketButton'] = [ |
|
71
|
|
|
'logId' => $entry['id'], |
|
72
|
|
|
'startpage' => $entry['points'] |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
} elseif ( |
|
76
|
|
|
!empty($entry['points']) |
|
77
|
|
|
&& is_string($entry['points']) |
|
78
|
|
|
) { |
|
79
|
|
|
$entryArray['id'] = $entry['points']; |
|
80
|
|
|
$entryArray['page'] = 1; |
|
81
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
82
|
|
|
if ($this->settings['basketButton']) { |
|
83
|
|
|
$entryArray['basketButton'] = [ |
|
84
|
|
|
'logId' => $entry['id'], |
|
85
|
|
|
'startpage' => $entry['points'] |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
} elseif (!empty($entry['targetUid'])) { |
|
89
|
|
|
$entryArray['id'] = $entry['targetUid']; |
|
90
|
|
|
$entryArray['page'] = 1; |
|
91
|
|
|
$entryArray['doNotLinkIt'] = 0; |
|
92
|
|
|
if ($this->settings['basketButton']) { |
|
93
|
|
|
$entryArray['basketButton'] = [ |
|
94
|
|
|
'logId' => $entry['id'], |
|
95
|
|
|
'startpage' => $entry['targetUid'] |
|
96
|
|
|
]; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
// Set "ITEM_STATE" to "CUR" if this entry points to current page. |
|
100
|
|
|
if (in_array($entry['id'], $this->activeEntries)) { |
|
101
|
|
|
$entryArray['ITEM_STATE'] = 'CUR'; |
|
102
|
|
|
} |
|
103
|
|
|
// Build sub-menu if available and called recursively. |
|
104
|
|
|
if ( |
|
105
|
|
|
$recursive === true |
|
106
|
|
|
&& !empty($entry['children']) |
|
107
|
|
|
) { |
|
108
|
|
|
// Build sub-menu only if one of the following conditions apply: |
|
109
|
|
|
// 1. Current menu node is in rootline |
|
110
|
|
|
// 2. Current menu node points to another file |
|
111
|
|
|
// 3. Current menu node has no corresponding images |
|
112
|
|
|
if ( |
|
113
|
|
|
$entryArray['ITEM_STATE'] == 'CUR' |
|
114
|
|
|
|| is_string($entry['points']) |
|
115
|
|
|
|| empty($this->document->getDoc()->smLinks['l2p'][$entry['id']]) |
|
116
|
|
|
) { |
|
117
|
|
|
$entryArray['_SUB_MENU'] = []; |
|
118
|
|
|
foreach ($entry['children'] as $child) { |
|
119
|
|
|
// Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
|
120
|
|
|
if (in_array($child['id'], $this->activeEntries)) { |
|
121
|
|
|
$entryArray['ITEM_STATE'] = 'ACT'; |
|
122
|
|
|
} |
|
123
|
|
|
$entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
// Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
|
127
|
|
|
$entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
|
128
|
|
|
} |
|
129
|
|
|
return $entryArray; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* If $entry references an external METS file (as mptr), |
|
134
|
|
|
* try to resolve its database UID and return an updated $entry. |
|
135
|
|
|
* |
|
136
|
|
|
* This is so that when linking from a child document back to its parent, |
|
137
|
|
|
* that link is via UID, so that subsequently the parent's TOC is built from database. |
|
138
|
|
|
* |
|
139
|
|
|
* @param array $entry |
|
140
|
|
|
* @return array |
|
141
|
|
|
*/ |
|
142
|
|
|
protected function resolveMenuEntry($entry) |
|
143
|
|
|
{ |
|
144
|
|
|
// If the menu entry points to the parent document, |
|
145
|
|
|
// resolve to the parent UID set on indexation. |
|
146
|
|
|
$doc = $this->document->getDoc(); |
|
147
|
|
|
if ( |
|
148
|
|
|
$doc instanceof MetsDocument |
|
149
|
|
|
&& $entry['points'] === $doc->parentHref |
|
150
|
|
|
&& !empty($this->document->getPartof()) |
|
151
|
|
|
) { |
|
152
|
|
|
unset($entry['points']); |
|
153
|
|
|
$entry['targetUid'] = $this->document->getPartof(); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
return $entry; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* The main method of the plugin |
|
161
|
|
|
* |
|
162
|
|
|
* @return void |
|
163
|
|
|
*/ |
|
164
|
|
|
public function mainAction() |
|
165
|
|
|
{ |
|
166
|
|
|
$this->view->assign('toc', $this->makeMenuArray()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* This builds a menu array for HMENU |
|
171
|
|
|
* |
|
172
|
|
|
* @access public |
|
173
|
|
|
* @return array HMENU array |
|
174
|
|
|
*/ |
|
175
|
|
|
public function makeMenuArray() |
|
176
|
|
|
{ |
|
177
|
|
|
// Load current document. |
|
178
|
|
|
$this->loadDocument($this->requestData); |
|
179
|
|
|
if ( |
|
180
|
|
|
$this->document === null |
|
181
|
|
|
|| $this->document->getDoc() === null |
|
182
|
|
|
) { |
|
183
|
|
|
// Quit without doing anything if required variables are not set. |
|
184
|
|
|
return []; |
|
185
|
|
|
} else { |
|
186
|
|
|
if (!empty($this->requestData['logicalPage'])) { |
|
187
|
|
|
$this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); |
|
188
|
|
|
// The logical page parameter should not appear again |
|
189
|
|
|
unset($this->requestData['logicalPage']); |
|
190
|
|
|
} |
|
191
|
|
|
// Set default values for page if not set. |
|
192
|
|
|
// $this->piVars['page'] may be integer or string (physical structure @ID) |
|
193
|
|
|
if ( |
|
194
|
|
|
(int) $this->requestData['page'] > 0 |
|
195
|
|
|
|| empty($this->requestData['page']) |
|
196
|
|
|
) { |
|
197
|
|
|
$this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], |
|
198
|
|
|
1, $this->document->getDoc()->numPages, 1); |
|
199
|
|
|
} else { |
|
200
|
|
|
$this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); |
|
201
|
|
|
} |
|
202
|
|
|
$this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], |
|
203
|
|
|
0, 1, 0); |
|
204
|
|
|
} |
|
205
|
|
|
$menuArray = []; |
|
206
|
|
|
// Does the document have physical elements or is it an external file? |
|
207
|
|
|
if ( |
|
208
|
|
|
!empty($this->document->getDoc()->physicalStructure) |
|
209
|
|
|
|| !MathUtility::canBeInterpretedAsInteger($this->requestData['id']) |
|
210
|
|
|
) { |
|
211
|
|
|
// Get all logical units the current page or track is a part of. |
|
212
|
|
|
if ( |
|
213
|
|
|
!empty($this->requestData['page']) |
|
214
|
|
|
&& !empty($this->document->getDoc()->physicalStructure) |
|
215
|
|
|
) { |
|
216
|
|
|
$this->activeEntries = array_merge((array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[0]], |
|
217
|
|
|
(array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]]); |
|
218
|
|
|
if ( |
|
219
|
|
|
!empty($this->requestData['double']) |
|
220
|
|
|
&& $this->requestData['page'] < $this->document->getDoc()->numPages |
|
221
|
|
|
) { |
|
222
|
|
|
$this->activeEntries = array_merge($this->activeEntries, |
|
223
|
|
|
(array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page'] + 1]]); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
// Go through table of contents and create all menu entries. |
|
227
|
|
|
foreach ($this->document->getDoc()->tableOfContents as $entry) { |
|
228
|
|
|
$menuArray[] = $this->getMenuEntry($entry, true); |
|
229
|
|
|
} |
|
230
|
|
|
} else { |
|
231
|
|
|
// Go through table of contents and create top-level menu entries. |
|
232
|
|
|
foreach ($this->document->getDoc()->tableOfContents as $entry) { |
|
233
|
|
|
$menuArray[] = $this->getMenuEntry($entry, false); |
|
234
|
|
|
} |
|
235
|
|
|
// Build table of contents from database. |
|
236
|
|
|
$result = $this->documentRepository->getTableOfContentsFromDb($this->document->getUid(), $this->document->getPid(), $this->settings); |
|
237
|
|
|
|
|
238
|
|
|
$allResults = $result->fetchAll(); |
|
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
if (count($allResults) > 0) { |
|
241
|
|
|
$menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; |
|
242
|
|
|
$menuArray[0]['_SUB_MENU'] = []; |
|
243
|
|
|
foreach ($allResults as $resArray) { |
|
244
|
|
|
$entry = [ |
|
245
|
|
|
'label' => !empty($resArray['mets_label']) ? $resArray['mets_label'] : $resArray['title'], |
|
246
|
|
|
'type' => $resArray['type'], |
|
247
|
|
|
'volume' => $resArray['volume'], |
|
248
|
|
|
'orderlabel' => $resArray['mets_orderlabel'], |
|
249
|
|
|
'pagination' => '', |
|
250
|
|
|
'targetUid' => $resArray['uid'] |
|
251
|
|
|
]; |
|
252
|
|
|
$menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, false); |
|
253
|
|
|
} |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
return $menuArray; |
|
257
|
|
|
} |
|
258
|
|
|
} |
|
259
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.