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
|
|
|
* The main method of the plugin |
39
|
|
|
* |
40
|
|
|
* @return void |
41
|
|
|
*/ |
42
|
|
|
public function mainAction() |
43
|
|
|
{ |
44
|
|
|
// Load current document. |
45
|
|
|
$this->loadDocument(); |
46
|
|
|
if ($this->isDocMissing()) { |
47
|
|
|
// Quit without doing anything if required variables are not set. |
48
|
|
|
return; |
49
|
|
|
} else { |
50
|
|
|
$this->setPage(); |
51
|
|
|
|
52
|
|
|
$this->view->assign('toc', $this->makeMenuArray()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* This builds a menu array for HMENU |
58
|
|
|
* |
59
|
|
|
* @access protected |
60
|
|
|
* @return array HMENU array |
61
|
|
|
*/ |
62
|
|
|
protected function makeMenuArray() |
63
|
|
|
{ |
64
|
|
|
$this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); |
65
|
|
|
$menuArray = []; |
66
|
|
|
// Does the document have physical elements or is it an external file? |
67
|
|
|
if ( |
68
|
|
|
!empty($this->document->getDoc()->physicalStructure) |
69
|
|
|
|| !MathUtility::canBeInterpretedAsInteger($this->requestData['id']) |
70
|
|
|
) { |
71
|
|
|
// Get all logical units the current page or track is a part of. |
72
|
|
|
if ( |
73
|
|
|
!empty($this->requestData['page']) |
74
|
|
|
&& !empty($this->document->getDoc()->physicalStructure) |
75
|
|
|
) { |
76
|
|
|
$this->activeEntries = array_merge((array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[0]], |
77
|
|
|
(array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page']]]); |
78
|
|
|
if ( |
79
|
|
|
!empty($this->requestData['double']) |
80
|
|
|
&& $this->requestData['page'] < $this->document->getDoc()->numPages |
81
|
|
|
) { |
82
|
|
|
$this->activeEntries = array_merge($this->activeEntries, |
83
|
|
|
(array) $this->document->getDoc()->smLinks['p2l'][$this->document->getDoc()->physicalStructure[$this->requestData['page'] + 1]]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
// Go through table of contents and create all menu entries. |
87
|
|
|
foreach ($this->document->getDoc()->tableOfContents as $entry) { |
88
|
|
|
$menuArray[] = $this->getMenuEntry($entry, true); |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
// Go through table of contents and create top-level menu entries. |
92
|
|
|
foreach ($this->document->getDoc()->tableOfContents as $entry) { |
93
|
|
|
$menuArray[] = $this->getMenuEntry($entry, false); |
94
|
|
|
} |
95
|
|
|
// Build table of contents from database. |
96
|
|
|
$result = $this->documentRepository->getTableOfContentsFromDb($this->document->getUid(), $this->document->getPid(), $this->settings); |
97
|
|
|
|
98
|
|
|
$allResults = $result->fetchAll(); |
|
|
|
|
99
|
|
|
|
100
|
|
|
if (count($allResults) > 0) { |
101
|
|
|
$menuArray[0]['ITEM_STATE'] = 'CURIFSUB'; |
102
|
|
|
$menuArray[0]['_SUB_MENU'] = []; |
103
|
|
|
foreach ($allResults as $resArray) { |
104
|
|
|
$entry = [ |
105
|
|
|
'label' => !empty($resArray['mets_label']) ? $resArray['mets_label'] : $resArray['title'], |
106
|
|
|
'type' => $resArray['type'], |
107
|
|
|
'volume' => $resArray['volume'], |
108
|
|
|
'orderlabel' => $resArray['mets_orderlabel'], |
109
|
|
|
'pagination' => '', |
110
|
|
|
'targetUid' => $resArray['uid'] |
111
|
|
|
]; |
112
|
|
|
$menuArray[0]['_SUB_MENU'][] = $this->getMenuEntry($entry, false); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
$this->sortMenu($menuArray); |
117
|
|
|
return $menuArray; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* This builds an array for one menu entry |
122
|
|
|
* |
123
|
|
|
* @access protected |
124
|
|
|
* |
125
|
|
|
* @param array $entry : The entry's array from \Kitodo\Dlf\Common\Doc->getLogicalStructure |
126
|
|
|
* @param bool $recursive : Whether to include the child entries |
127
|
|
|
* |
128
|
|
|
* @return array HMENU array for menu entry |
129
|
|
|
*/ |
130
|
|
|
protected function getMenuEntry(array $entry, $recursive = false) |
131
|
|
|
{ |
132
|
|
|
$entry = $this->resolveMenuEntry($entry); |
133
|
|
|
|
134
|
|
|
$entryArray = []; |
135
|
|
|
// Set "title", "volume", "type" and "pagination" from $entry array. |
136
|
|
|
$entryArray['title'] = !empty($entry['label']) ? $entry['label'] : $entry['orderlabel']; |
137
|
|
|
$entryArray['volume'] = $entry['volume']; |
138
|
|
|
$entryArray['orderlabel'] = $entry['orderlabel']; |
139
|
|
|
$entryArray['type'] = $this->getTranslatedType($entry['type']); |
140
|
|
|
$entryArray['pagination'] = htmlspecialchars($entry['pagination']); |
141
|
|
|
$entryArray['_OVERRIDE_HREF'] = ''; |
142
|
|
|
$entryArray['doNotLinkIt'] = 1; |
143
|
|
|
$entryArray['ITEM_STATE'] = 'NO'; |
144
|
|
|
// Build menu links based on the $entry['points'] array. |
145
|
|
|
if ( |
146
|
|
|
!empty($entry['points']) |
147
|
|
|
&& MathUtility::canBeInterpretedAsInteger($entry['points']) |
148
|
|
|
) { |
149
|
|
|
$entryArray['page'] = $entry['points']; |
150
|
|
|
|
151
|
|
|
$entryArray['doNotLinkIt'] = 0; |
152
|
|
|
if ($this->settings['basketButton']) { |
153
|
|
|
$entryArray['basketButton'] = [ |
154
|
|
|
'logId' => $entry['id'], |
155
|
|
|
'startpage' => $entry['points'] |
156
|
|
|
]; |
157
|
|
|
} |
158
|
|
|
} elseif ( |
159
|
|
|
!empty($entry['points']) |
160
|
|
|
&& is_string($entry['points']) |
161
|
|
|
) { |
162
|
|
|
$entryArray['id'] = $entry['points']; |
163
|
|
|
$entryArray['page'] = 1; |
164
|
|
|
$entryArray['doNotLinkIt'] = 0; |
165
|
|
|
if ($this->settings['basketButton']) { |
166
|
|
|
$entryArray['basketButton'] = [ |
167
|
|
|
'logId' => $entry['id'], |
168
|
|
|
'startpage' => $entry['points'] |
169
|
|
|
]; |
170
|
|
|
} |
171
|
|
|
} elseif (!empty($entry['targetUid'])) { |
172
|
|
|
$entryArray['id'] = $entry['targetUid']; |
173
|
|
|
$entryArray['page'] = 1; |
174
|
|
|
$entryArray['doNotLinkIt'] = 0; |
175
|
|
|
if ($this->settings['basketButton']) { |
176
|
|
|
$entryArray['basketButton'] = [ |
177
|
|
|
'logId' => $entry['id'], |
178
|
|
|
'startpage' => $entry['targetUid'] |
179
|
|
|
]; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
// Set "ITEM_STATE" to "CUR" if this entry points to current page. |
183
|
|
|
if (in_array($entry['id'], $this->activeEntries)) { |
184
|
|
|
$entryArray['ITEM_STATE'] = 'CUR'; |
185
|
|
|
} |
186
|
|
|
// Build sub-menu if available and called recursively. |
187
|
|
|
if ( |
188
|
|
|
$recursive === true |
189
|
|
|
&& !empty($entry['children']) |
190
|
|
|
) { |
191
|
|
|
// Build sub-menu only if one of the following conditions apply: |
192
|
|
|
// 1. Current menu node is in rootline |
193
|
|
|
// 2. Current menu node points to another file |
194
|
|
|
// 3. Current menu node has no corresponding images |
195
|
|
|
if ( |
196
|
|
|
$entryArray['ITEM_STATE'] == 'CUR' |
197
|
|
|
|| is_string($entry['points']) |
198
|
|
|
|| empty($this->document->getDoc()->smLinks['l2p'][$entry['id']]) |
199
|
|
|
) { |
200
|
|
|
$entryArray['_SUB_MENU'] = []; |
201
|
|
|
foreach ($entry['children'] as $child) { |
202
|
|
|
// Set "ITEM_STATE" to "ACT" if this entry points to current page and has sub-entries pointing to the same page. |
203
|
|
|
if (in_array($child['id'], $this->activeEntries)) { |
204
|
|
|
$entryArray['ITEM_STATE'] = 'ACT'; |
205
|
|
|
} |
206
|
|
|
$entryArray['_SUB_MENU'][] = $this->getMenuEntry($child, true); |
207
|
|
|
} |
208
|
|
|
} |
209
|
|
|
// Append "IFSUB" to "ITEM_STATE" if this entry has sub-entries. |
210
|
|
|
$entryArray['ITEM_STATE'] = ($entryArray['ITEM_STATE'] == 'NO' ? 'IFSUB' : $entryArray['ITEM_STATE'] . 'IFSUB'); |
211
|
|
|
} |
212
|
|
|
return $entryArray; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* If $entry references an external METS file (as mptr), |
217
|
|
|
* try to resolve its database UID and return an updated $entry. |
218
|
|
|
* |
219
|
|
|
* This is so that when linking from a child document back to its parent, |
220
|
|
|
* that link is via UID, so that subsequently the parent's TOC is built from database. |
221
|
|
|
* |
222
|
|
|
* @param array $entry |
223
|
|
|
* @return array |
224
|
|
|
*/ |
225
|
|
|
protected function resolveMenuEntry($entry) |
226
|
|
|
{ |
227
|
|
|
// If the menu entry points to the parent document, |
228
|
|
|
// resolve to the parent UID set on indexation. |
229
|
|
|
$doc = $this->document->getDoc(); |
230
|
|
|
if ( |
231
|
|
|
$doc instanceof MetsDocument |
232
|
|
|
&& $entry['points'] === $doc->parentHref |
233
|
|
|
&& !empty($this->document->getPartof()) |
234
|
|
|
) { |
235
|
|
|
unset($entry['points']); |
236
|
|
|
$entry['targetUid'] = $this->document->getPartof(); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
return $entry; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get translated type of entry. |
244
|
|
|
* |
245
|
|
|
* @param array $type |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
private function getTranslatedType($type) { |
249
|
|
|
return Helper::translate($type, 'tx_dlf_structures', $this->settings['storagePid']); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Sort menu by orderlabel - currently implemented for newspaper. |
254
|
|
|
* //TODO: add for years |
255
|
|
|
* |
256
|
|
|
* @param array &$menu |
257
|
|
|
* @return void |
258
|
|
|
*/ |
259
|
|
|
private function sortMenu(&$menu) { |
260
|
|
|
if ($menu[0]['type'] == $this->getTranslatedType("newspaper")) { |
|
|
|
|
261
|
|
|
$this->sortMenuForNewspapers($menu); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Sort menu years of the newspaper by orderlabel. |
267
|
|
|
* |
268
|
|
|
* @param array &$menu |
269
|
|
|
* @return void |
270
|
|
|
*/ |
271
|
|
|
private function sortMenuForNewspapers(&$menu) { |
272
|
|
|
usort($menu[0]['_SUB_MENU'], function ($firstYear, $secondYear) { |
273
|
|
|
return $firstYear['orderlabel'] <=> $secondYear['orderlabel']; |
274
|
|
|
}); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
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.