forked from kitodo/kitodo-presentation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigationController.php
More file actions
128 lines (117 loc) · 5.09 KB
/
NavigationController.php
File metadata and controls
128 lines (117 loc) · 5.09 KB
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
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <contact@kitodo.org>
*
* This file is part of the Kitodo and TYPO3 projects.
*
* @license GNU General Public License version 3 or later.
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Kitodo\Dlf\Controller;
use Kitodo\Dlf\Common\Helper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* Controller class for the plugin 'Navigation'.
*
* @author Sebastian Meyer <sebastian.meyer@slub-dresden.de>
* @package TYPO3
* @subpackage dlf
* @access public
*/
class NavigationController extends AbstractController
{
/**
* Method to get the page select values and use them with chash
* @param \Kitodo\Dlf\Domain\Model\PageSelectForm|NULL $pageSelectForm
* @return void
*/
public function pageSelectAction(\Kitodo\Dlf\Domain\Model\PageSelectForm $pageSelectForm = NULL) {
if ($pageSelectForm) {
$uriBuilder = $this->getControllerContext()->getUriBuilder();
$uri = $uriBuilder->reset()
->setArguments(
[
'tx_dlf' => [
'id' => $pageSelectForm->getId(),
'page' => $pageSelectForm->getPage(),
'double' => $pageSelectForm->getDouble()
]
]
)
->uriFor('main');
$this->redirectToUri($uri);
}
}
/**
* The main method of the plugin
*
* @return void
*/
public function mainAction()
{
// Load current document.
$this->loadDocument($this->requestData);
if ($this->isDocMissing()) {
// Quit without doing anything if required variables are not set.
return '';
} else {
// Set default values if not set.
if ($this->document->getDoc()->numPages > 0) {
if (!empty($this->requestData['logicalPage'])) {
$this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']);
// The logical page parameter should not appear
unset($this->requestData['logicalPage']);
}
// Set default values if not set.
// $this->requestData['page'] may be integer or string (physical structure @ID)
if (
(int) $this->requestData['page'] > 0
|| empty($this->requestData['page'])
) {
$this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1);
} else {
$this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure);
}
$this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0);
} else {
$this->requestData['page'] = 0;
$this->requestData['double'] = 0;
}
}
// Steps for X pages backward / forward. Double page view uses double steps.
$pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1);
$this->view->assign('pageSteps', $pageSteps);
$this->view->assign('numPages', $this->document->getDoc()->numPages);
$this->view->assign('viewData', $this->viewData);
if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'search')) {
$lastSearchArguments = [];
$searchSessionParameters = $GLOBALS['TSFE']->fe_user->getKey('ses', 'search');
$widgetPage = $GLOBALS['TSFE']->fe_user->getKey('ses', 'widgetPage');
if ($searchSessionParameters) {
$lastSearchArguments = [
'tx_dlf_listview' => [
'searchParameter' => $searchSessionParameters
]
];
}
if ($widgetPage) {
$lastSearchArguments['tx_dlf_listview']['@widget_0'] = $widgetPage;
}
// save last search parameter to generate a link back to the search list
$this->view->assign('lastSearchParams', $lastSearchArguments);
}
$pageOptions = [];
for ($i = 1; $i <= $this->document->getDoc()->numPages; $i++) {
$pageOptions[$i] = '[' . $i . ']' . ($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel']) : '');
}
$this->view->assign('pageOptions', $pageOptions);
// prepare feature array for fluid
$features = [];
foreach (explode(',', $this->settings['features']) as $feature) {
$features[$feature] = true;
}
$this->view->assign('features', $features);
}
}