We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 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\AbstractDocument; |
||||
| 15 | use Kitodo\Dlf\Common\Helper; |
||||
| 16 | use Kitodo\Dlf\Domain\Model\Document; |
||||
| 17 | use Kitodo\Dlf\Domain\Repository\DocumentRepository; |
||||
| 18 | use Psr\Http\Message\ResponseInterface; |
||||
| 19 | use Psr\Log\LoggerAwareInterface; |
||||
| 20 | use Psr\Log\LoggerAwareTrait; |
||||
| 21 | use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; |
||||
| 22 | use TYPO3\CMS\Core\Localization\LanguageService; |
||||
| 23 | use TYPO3\CMS\Core\Log\LogManager; |
||||
| 24 | use TYPO3\CMS\Core\Pagination\PaginationInterface; |
||||
| 25 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||||
| 26 | use TYPO3\CMS\Core\Utility\MathUtility; |
||||
| 27 | use TYPO3\CMS\Core\Pagination\PaginatorInterface; |
||||
| 28 | use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
||||
| 29 | use TYPO3\CMS\Extbase\Mvc\Request; |
||||
| 30 | use TYPO3\CMS\Extbase\Mvc\RequestInterface; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * Abstract controller class for most of the plugin controller. |
||||
| 34 | * |
||||
| 35 | * @package TYPO3 |
||||
| 36 | * @subpackage dlf |
||||
| 37 | * |
||||
| 38 | * @access public |
||||
| 39 | * |
||||
| 40 | * @abstract |
||||
| 41 | */ |
||||
| 42 | abstract class AbstractController extends ActionController implements LoggerAwareInterface |
||||
| 43 | { |
||||
| 44 | use LoggerAwareTrait; |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * @access protected |
||||
| 48 | * @var DocumentRepository |
||||
| 49 | */ |
||||
| 50 | protected DocumentRepository $documentRepository; |
||||
| 51 | |||||
| 52 | /** |
||||
| 53 | * @access public |
||||
| 54 | * |
||||
| 55 | * @param DocumentRepository $documentRepository |
||||
| 56 | * |
||||
| 57 | * @return void |
||||
| 58 | */ |
||||
| 59 | public function injectDocumentRepository(DocumentRepository $documentRepository): void |
||||
| 60 | { |
||||
| 61 | $this->documentRepository = $documentRepository; |
||||
| 62 | } |
||||
| 63 | |||||
| 64 | /** |
||||
| 65 | * @access protected |
||||
| 66 | * @var Document|null This holds the current document |
||||
| 67 | */ |
||||
| 68 | protected ?Document $document = null; |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * @access protected |
||||
| 72 | * @var array |
||||
| 73 | */ |
||||
| 74 | protected $documentArray; |
||||
| 75 | |||||
| 76 | /** |
||||
| 77 | * @access protected |
||||
| 78 | * @var array |
||||
| 79 | */ |
||||
| 80 | protected array $extConf; |
||||
| 81 | |||||
| 82 | /** |
||||
| 83 | * @access protected |
||||
| 84 | * @var array This holds the request parameter |
||||
| 85 | */ |
||||
| 86 | protected array $requestData; |
||||
| 87 | |||||
| 88 | /** |
||||
| 89 | * @access protected |
||||
| 90 | * @var array This holds some common data for the fluid view |
||||
| 91 | */ |
||||
| 92 | protected array $viewData; |
||||
| 93 | |||||
| 94 | /** |
||||
| 95 | * @access protected |
||||
| 96 | * @var int |
||||
| 97 | */ |
||||
| 98 | protected int $pageUid; |
||||
| 99 | |||||
| 100 | /** |
||||
| 101 | * Initialize the plugin controller |
||||
| 102 | * |
||||
| 103 | * @access protected |
||||
| 104 | * |
||||
| 105 | * @param RequestInterface $request the HTTP request |
||||
| 106 | * |
||||
| 107 | * @return void |
||||
| 108 | */ |
||||
| 109 | protected function initialize(RequestInterface $request): void |
||||
| 110 | { |
||||
| 111 | /** @var Request $request */ |
||||
| 112 | $this->requestData = $request->getQueryParams()['tx_dlf'] ?? []; |
||||
| 113 | $this->pageUid = (int) ($this->requestData['id'] ?? 0); |
||||
| 114 | $this->requestData['page'] = $this->requestData['page'] ?? 1; |
||||
| 115 | |||||
| 116 | // Sanitize user input to prevent XSS attacks. |
||||
| 117 | $this->sanitizeRequestData(); |
||||
| 118 | |||||
| 119 | // Get extension configuration. |
||||
| 120 | $this->extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf'); |
||||
| 121 | |||||
| 122 | $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); |
||||
| 123 | |||||
| 124 | $this->viewData = [ |
||||
| 125 | 'pageUid' => $this->pageUid, |
||||
| 126 | 'uniqueId' => uniqid(), |
||||
| 127 | 'requestData' => $this->requestData |
||||
| 128 | ]; |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | /** |
||||
| 132 | * Loads the current document into $this->document |
||||
| 133 | * |
||||
| 134 | * @access protected |
||||
| 135 | * |
||||
| 136 | * @param int $documentId The document's UID (fallback: $this->requestData[id]) |
||||
| 137 | * |
||||
| 138 | * @return void |
||||
| 139 | */ |
||||
| 140 | protected function loadDocument(int $documentId = 0): void |
||||
| 141 | { |
||||
| 142 | // Sanitize FlexForm settings to avoid later casting. |
||||
| 143 | $this->sanitizeSettings(); |
||||
| 144 | |||||
| 145 | // Get document ID from request data if not passed as parameter. |
||||
| 146 | if ($documentId === 0 && !empty($this->requestData['id'])) { |
||||
| 147 | $documentId = $this->requestData['id']; |
||||
| 148 | } |
||||
| 149 | |||||
| 150 | // Try to get document format from database |
||||
| 151 | if (!empty($documentId)) { |
||||
| 152 | |||||
| 153 | $doc = null; |
||||
| 154 | |||||
| 155 | if (MathUtility::canBeInterpretedAsInteger($documentId)) { |
||||
| 156 | $doc = $this->getDocumentByUid($documentId); |
||||
| 157 | } elseif (GeneralUtility::isValidUrl($documentId)) { |
||||
| 158 | $doc = $this->getDocumentByUrl($documentId); |
||||
| 159 | } |
||||
| 160 | |||||
| 161 | if ($this->document !== null && $doc !== null) { |
||||
| 162 | $this->document->setCurrentDocument($doc); |
||||
| 163 | } |
||||
| 164 | |||||
| 165 | } elseif (!empty($this->requestData['recordId'])) { |
||||
| 166 | |||||
| 167 | $this->document = $this->documentRepository->findOneByRecordId($this->requestData['recordId']); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 168 | |||||
| 169 | if ($this->document !== null) { |
||||
| 170 | $doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, true); |
||||
| 171 | if ($doc !== null) { |
||||
| 172 | $this->document->setCurrentDocument($doc); |
||||
| 173 | } else { |
||||
| 174 | $this->logger->error('Failed to load document with record ID "' . $this->requestData['recordId'] . '"'); |
||||
| 175 | } |
||||
| 176 | } |
||||
| 177 | } else { |
||||
| 178 | $this->logger->error('Invalid ID "' . $documentId . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||||
| 179 | } |
||||
| 180 | } |
||||
| 181 | |||||
| 182 | /** |
||||
| 183 | * Configure URL for proxy. |
||||
| 184 | * |
||||
| 185 | * @access protected |
||||
| 186 | * |
||||
| 187 | * @param string $url URL for proxy configuration |
||||
| 188 | * |
||||
| 189 | * @return void |
||||
| 190 | */ |
||||
| 191 | protected function configureProxyUrl(string &$url): void |
||||
| 192 | { |
||||
| 193 | $this->uriBuilder->reset() |
||||
| 194 | ->setTargetPageUid($this->pageUid) |
||||
| 195 | ->setCreateAbsoluteUri(!empty($this->extConf['general']['forceAbsoluteUrl'])) |
||||
| 196 | ->setArguments( |
||||
| 197 | [ |
||||
| 198 | 'eID' => 'tx_dlf_pageview_proxy', |
||||
| 199 | 'url' => $url, |
||||
| 200 | 'uHash' => GeneralUtility::hmac($url, 'PageViewProxy') |
||||
| 201 | ] |
||||
| 202 | ) |
||||
| 203 | ->build(); |
||||
| 204 | } |
||||
| 205 | |||||
| 206 | /** |
||||
| 207 | * Checks if doc is missing or is empty (no pages) |
||||
| 208 | * |
||||
| 209 | * @access protected |
||||
| 210 | * |
||||
| 211 | * @return bool |
||||
| 212 | */ |
||||
| 213 | protected function isDocMissingOrEmpty(): bool |
||||
| 214 | { |
||||
| 215 | $multiViewType = $this->settings['multiViewType'] ?? ''; |
||||
| 216 | return $this->isDocMissing() || ($this->document->getCurrentDocument()->numPages < 1 && $this->document->getCurrentDocument()->tableOfContents[0]['type'] !== $multiViewType); |
||||
| 217 | } |
||||
| 218 | |||||
| 219 | /** |
||||
| 220 | * Checks if doc is missing |
||||
| 221 | * |
||||
| 222 | * @access protected |
||||
| 223 | * |
||||
| 224 | * @return bool |
||||
| 225 | */ |
||||
| 226 | protected function isDocMissing(): bool |
||||
| 227 | { |
||||
| 228 | return $this->document === null || $this->document->getCurrentDocument() === null; |
||||
| 229 | } |
||||
| 230 | |||||
| 231 | /** |
||||
| 232 | * Returns the LanguageService |
||||
| 233 | * |
||||
| 234 | * @access protected |
||||
| 235 | * |
||||
| 236 | * @return LanguageService |
||||
| 237 | */ |
||||
| 238 | protected function getLanguageService(): LanguageService |
||||
| 239 | { |
||||
| 240 | return $GLOBALS['LANG']; |
||||
| 241 | } |
||||
| 242 | |||||
| 243 | /** |
||||
| 244 | * Safely gets Parameters from request if they exist |
||||
| 245 | * |
||||
| 246 | * @access protected |
||||
| 247 | * |
||||
| 248 | * @param string $parameterName |
||||
| 249 | * |
||||
| 250 | * @return null|string|array |
||||
| 251 | */ |
||||
| 252 | protected function getParametersSafely(string $parameterName) |
||||
| 253 | { |
||||
| 254 | if ($this->request->hasArgument($parameterName)) { |
||||
| 255 | return $this->request->getArgument($parameterName); |
||||
| 256 | } |
||||
| 257 | return null; |
||||
| 258 | } |
||||
| 259 | |||||
| 260 | /** |
||||
| 261 | * Sanitize input variables. |
||||
| 262 | * |
||||
| 263 | * @access protected |
||||
| 264 | * |
||||
| 265 | * @return void |
||||
| 266 | */ |
||||
| 267 | protected function sanitizeRequestData(): void |
||||
| 268 | { |
||||
| 269 | // tx_dlf[id] may only be an UID or URI. |
||||
| 270 | if ( |
||||
| 271 | !empty($this->requestData['id']) |
||||
| 272 | && !MathUtility::canBeInterpretedAsInteger($this->requestData['id']) |
||||
| 273 | && !GeneralUtility::isValidUrl($this->requestData['id']) |
||||
| 274 | ) { |
||||
| 275 | $this->logger->warning('Invalid ID or URI "' . $this->requestData['id'] . '" for document loading'); |
||||
| 276 | unset($this->requestData['id']); |
||||
| 277 | } |
||||
| 278 | |||||
| 279 | // tx_dlf[page] may only be a positive integer or valid XML ID. |
||||
| 280 | if ( |
||||
| 281 | !empty($this->requestData['page']) |
||||
| 282 | && !MathUtility::canBeInterpretedAsInteger($this->requestData['page']) |
||||
| 283 | && !Helper::isValidXmlId($this->requestData['page']) |
||||
| 284 | ) { |
||||
| 285 | $this->requestData['page'] = 1; |
||||
| 286 | } |
||||
| 287 | |||||
| 288 | // tx_dlf[double] may only be 0 or 1. |
||||
| 289 | $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'] ?? 0, 0, 1); |
||||
| 290 | } |
||||
| 291 | |||||
| 292 | /** |
||||
| 293 | * Sanitize settings from FlexForm. |
||||
| 294 | * |
||||
| 295 | * @access protected |
||||
| 296 | * |
||||
| 297 | * @return void |
||||
| 298 | */ |
||||
| 299 | protected function sanitizeSettings(): void |
||||
| 300 | { |
||||
| 301 | $this->setDefaultIntSetting('storagePid', 0); |
||||
| 302 | |||||
| 303 | if ($this instanceof MetadataController) { |
||||
| 304 | $this->setDefaultIntSetting('rootline', 0); |
||||
| 305 | $this->setDefaultIntSetting('originalIiifMetadata', 0); |
||||
| 306 | $this->setDefaultIntSetting('displayIiifDescription', 1); |
||||
| 307 | $this->setDefaultIntSetting('displayIiifRights', 1); |
||||
| 308 | $this->setDefaultIntSetting('displayIiifLinks', 1); |
||||
| 309 | } |
||||
| 310 | |||||
| 311 | if ($this instanceof NavigationController) { |
||||
| 312 | $this->setDefaultIntSetting('pageStep', 5); |
||||
| 313 | } |
||||
| 314 | |||||
| 315 | if ($this instanceof OaiPmhController) { |
||||
| 316 | $this->setDefaultIntSetting('limit', 5); |
||||
| 317 | $this->setDefaultIntSetting('solr_limit', 50000); |
||||
| 318 | } |
||||
| 319 | |||||
| 320 | if ($this instanceof PageViewController) { |
||||
| 321 | $this->setDefaultIntSetting('useInternalProxy', 0); |
||||
| 322 | } |
||||
| 323 | } |
||||
| 324 | |||||
| 325 | /** |
||||
| 326 | * Sets default value for setting if not yet set. |
||||
| 327 | * |
||||
| 328 | * @access protected |
||||
| 329 | * |
||||
| 330 | * @param string $setting name of setting |
||||
| 331 | * @param int $value for being set if empty |
||||
| 332 | * |
||||
| 333 | * @return void |
||||
| 334 | */ |
||||
| 335 | protected function setDefaultIntSetting(string $setting, int $value): void |
||||
| 336 | { |
||||
| 337 | if (!array_key_exists($setting, $this->settings) || empty($this->settings[$setting])) { |
||||
| 338 | $this->settings[$setting] = $value; |
||||
| 339 | $this->logger->warning('Setting "' . $setting . '" not set, using default value "' . $value . '". Probably FlexForm for controller "' . get_class($this) . '" is not read.'); |
||||
| 340 | } else { |
||||
| 341 | $this->settings[$setting] = (int) $this->settings[$setting]; |
||||
| 342 | } |
||||
| 343 | } |
||||
| 344 | |||||
| 345 | /** |
||||
| 346 | * Sets page value. |
||||
| 347 | * |
||||
| 348 | * @access protected |
||||
| 349 | * |
||||
| 350 | * @return void |
||||
| 351 | */ |
||||
| 352 | protected function setPage(): void |
||||
| 353 | { |
||||
| 354 | if (!empty($this->requestData['logicalPage'])) { |
||||
| 355 | $this->requestData['page'] = $this->document->getCurrentDocument()->getPhysicalPage($this->requestData['logicalPage']); |
||||
|
0 ignored issues
–
show
The method
getCurrentDocument() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
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. Loading history...
|
|||||
| 356 | // The logical page parameter should not appear again |
||||
| 357 | unset($this->requestData['logicalPage']); |
||||
| 358 | } |
||||
| 359 | |||||
| 360 | $this->setDefaultPage(); |
||||
| 361 | } |
||||
| 362 | |||||
| 363 | /** |
||||
| 364 | * Sets default page value. |
||||
| 365 | * |
||||
| 366 | * @access protected |
||||
| 367 | * |
||||
| 368 | * @return void |
||||
| 369 | */ |
||||
| 370 | protected function setDefaultPage(): void |
||||
| 371 | { |
||||
| 372 | // Set default values if not set. |
||||
| 373 | // $this->requestData['page'] may be integer or string (physical structure @ID) |
||||
| 374 | if ( |
||||
| 375 | isset($this->requestData['page']) |
||||
| 376 | && ( |
||||
| 377 | (int) $this->requestData['page'] > 0 |
||||
| 378 | || empty($this->requestData['page']) |
||||
| 379 | || is_array($this->requestData['docPage']) |
||||
| 380 | ) |
||||
| 381 | ) { |
||||
| 382 | if (isset($this->settings['multiViewType']) && $this->document->getCurrentDocument()->tableOfContents[0]['type'] === $this->settings['multiViewType']) { |
||||
| 383 | $i = 0; |
||||
| 384 | foreach ($this->documentArray as $document) { |
||||
| 385 | if ($document !== null) { |
||||
| 386 | $this->requestData['docPage'][$i] = MathUtility::forceIntegerInRange((int) $this->requestData['docPage'][$i], 1, $document->numPages, 1); |
||||
| 387 | $i++; |
||||
| 388 | } |
||||
| 389 | } |
||||
| 390 | } else { |
||||
| 391 | $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getCurrentDocument()->numPages, 1); |
||||
| 392 | } |
||||
| 393 | } |
||||
| 394 | // reassign viewData to get correct page |
||||
| 395 | $this->viewData['requestData'] = $this->requestData; |
||||
| 396 | } |
||||
| 397 | |||||
| 398 | /** |
||||
| 399 | * Wrapper for ActionController::processRequest in order to initialize things |
||||
| 400 | * without using a constructor. |
||||
| 401 | * |
||||
| 402 | * @access public |
||||
| 403 | * |
||||
| 404 | * @param RequestInterface $request the request |
||||
| 405 | * |
||||
| 406 | * @return ResponseInterface the response |
||||
| 407 | */ |
||||
| 408 | public function processRequest(RequestInterface $request): ResponseInterface |
||||
| 409 | { |
||||
| 410 | $this->initialize($request); |
||||
| 411 | return parent::processRequest($request); |
||||
| 412 | } |
||||
| 413 | |||||
| 414 | /** |
||||
| 415 | * build simple pagination |
||||
| 416 | * |
||||
| 417 | * @param PaginationInterface $pagination |
||||
| 418 | * @param PaginatorInterface $paginator |
||||
| 419 | * @return array |
||||
| 420 | */ |
||||
| 421 | //TODO: clean this function |
||||
| 422 | protected function buildSimplePagination(PaginationInterface $pagination, PaginatorInterface $paginator): array |
||||
| 423 | { |
||||
| 424 | $firstPage = $pagination->getFirstPageNumber(); |
||||
| 425 | $lastPage = $pagination->getLastPageNumber(); |
||||
| 426 | $currentPageNumber = $paginator->getCurrentPageNumber(); |
||||
| 427 | |||||
| 428 | $pages = []; |
||||
| 429 | $pagesSect = []; |
||||
| 430 | $aRange = []; |
||||
| 431 | $nRange = 5; // ToDo: should be made configurable |
||||
| 432 | |||||
| 433 | // lower limit of the range |
||||
| 434 | $nBottom = $currentPageNumber - $nRange; |
||||
| 435 | // upper limit of the range |
||||
| 436 | $nTop = $currentPageNumber + $nRange; |
||||
| 437 | // page range |
||||
| 438 | for ($i = $nBottom; $i <= $nTop; $i++) { |
||||
| 439 | if ($i > 0 and $i <= $lastPage) { |
||||
| 440 | array_push($aRange, $i); |
||||
| 441 | }; |
||||
| 442 | }; |
||||
| 443 | |||||
| 444 | // check whether the first screen page is > 1, if yes then points must be added |
||||
| 445 | if ($aRange[0] > 1) { |
||||
| 446 | array_push($pagesSect, ['label' => '...','startRecordNumber' => '...']); |
||||
| 447 | }; |
||||
| 448 | $lastStartRecordNumberGrid = 0; // due to validity outside the loop |
||||
| 449 | foreach (range($firstPage, $lastPage) as $i) { |
||||
| 450 | // detect which pagination is active: ListView or GridView |
||||
| 451 | if (get_class($pagination) == 'TYPO3\CMS\Core\Pagination\SimplePagination') { // ListView |
||||
| 452 | $lastStartRecordNumberGrid = $i; // save last $startRecordNumber for LastPage button |
||||
| 453 | |||||
| 454 | $pages[$i] = [ |
||||
| 455 | 'label' => $i, |
||||
| 456 | 'startRecordNumber' => $i |
||||
| 457 | ]; |
||||
| 458 | |||||
| 459 | // Check if screen page is in range |
||||
| 460 | // <f:for each="{pagination.pagesR}" as="page"> |
||||
| 461 | if (in_array($i, $aRange)) { |
||||
| 462 | array_push($pagesSect, ['label' => $i, 'startRecordNumber' => $i]); |
||||
| 463 | }; |
||||
| 464 | } else { // GridView |
||||
| 465 | // to calculate the values for generation the links for the pagination pages |
||||
| 466 | /** @var \Kitodo\Dlf\Pagination\PageGridPaginator $paginator */ |
||||
| 467 | $itemsPerPage = $paginator->getPublicItemsPerPage(); |
||||
| 468 | |||||
| 469 | $startRecordNumber = $itemsPerPage * $i; |
||||
| 470 | $startRecordNumber = $startRecordNumber + 1; |
||||
| 471 | $startRecordNumber = $startRecordNumber - $itemsPerPage; |
||||
| 472 | |||||
| 473 | $lastStartRecordNumberGrid = $startRecordNumber; // save last $startRecordNumber for LastPage button |
||||
| 474 | |||||
| 475 | // array with label as screen/pagination page number |
||||
| 476 | // and startRecordNumber for correct structure of the link |
||||
| 477 | //<f:link.action action="{action}" |
||||
| 478 | // addQueryString="untrusted" |
||||
| 479 | // argumentsToBeExcludedFromQueryString="{0: 'tx_dlf[page]'}" |
||||
| 480 | // additionalParams="{'tx_dlf[page]': page.startRecordNumber}" |
||||
| 481 | // arguments="{searchParameter: lastSearch}">{page.label}</f:link.action> |
||||
| 482 | $pages[$i] = [ |
||||
| 483 | 'label' => $i, |
||||
| 484 | 'startRecordNumber' => $startRecordNumber |
||||
| 485 | ]; |
||||
| 486 | |||||
| 487 | // Check if screen page is in range |
||||
| 488 | if (in_array($i, $aRange)) { |
||||
| 489 | array_push($pagesSect, ['label' => $i,'startRecordNumber' => $startRecordNumber]); |
||||
| 490 | }; |
||||
| 491 | }; |
||||
| 492 | }; |
||||
| 493 | |||||
| 494 | // check whether the last element from $aRange <= last screen page, if yes then points must be added |
||||
| 495 | if ($aRange[array_key_last($aRange)] < $lastPage) { |
||||
| 496 | array_push($pagesSect, ['label' => '...', 'startRecordNumber' => '...']); |
||||
| 497 | }; |
||||
| 498 | |||||
| 499 | // Safely get the next and previous page numbers |
||||
| 500 | $nextPageNumber = isset($pages[$currentPageNumber + 1]) ? $pages[$currentPageNumber + 1]['startRecordNumber'] : null; |
||||
| 501 | $previousPageNumber = isset($pages[$currentPageNumber - 1]) ? $pages[$currentPageNumber - 1]['startRecordNumber'] : null; |
||||
| 502 | |||||
| 503 | // 'startRecordNumber' is not required in GridView, only the variant for each loop is required |
||||
| 504 | // 'endRecordNumber' is not required in both views |
||||
| 505 | // |
||||
| 506 | // lastPageNumber => last screen page |
||||
| 507 | // lastPageNumber => Document page to build the last screen page. This is the first document |
||||
| 508 | // of the last block of 10 (or less) documents on the last screen page |
||||
| 509 | // firstPageNumber => always 1 |
||||
| 510 | // nextPageNumber => Document page to build the next screen page |
||||
| 511 | // nextPageNumberG => Number of the screen page for the next screen page |
||||
| 512 | // previousPageNumber => Document page to build up the previous screen page |
||||
| 513 | // previousPageNumberG => Number of the screen page for the previous screen page |
||||
| 514 | // currentPageNumber => Number of the current screen page |
||||
| 515 | // pagesG => Array with two keys |
||||
| 516 | // label => Number of the screen page |
||||
| 517 | // startRecordNumber => First document of this block of 10 documents on the same screen page |
||||
| 518 | return [ |
||||
| 519 | 'lastPageNumber' => $lastPage, |
||||
| 520 | 'lastPageNumberG' => $lastStartRecordNumberGrid, |
||||
| 521 | 'firstPageNumber' => $firstPage, |
||||
| 522 | 'nextPageNumber' => $nextPageNumber, |
||||
| 523 | 'nextPageNumberG' => $currentPageNumber + 1, |
||||
| 524 | 'previousPageNumber' => $previousPageNumber, |
||||
| 525 | 'previousPageNumberG' => $currentPageNumber - 1, |
||||
| 526 | 'startRecordNumber' => $pagination->getStartRecordNumber(), |
||||
| 527 | 'endRecordNumber' => $pagination->getEndRecordNumber(), |
||||
| 528 | 'currentPageNumber' => $currentPageNumber, |
||||
| 529 | 'pages' => range($firstPage, $lastPage), |
||||
| 530 | 'pagesG' => $pages, |
||||
| 531 | 'pagesR' => $pagesSect |
||||
| 532 | ]; |
||||
| 533 | } |
||||
| 534 | |||||
| 535 | /** |
||||
| 536 | * Get document from repository by uid. |
||||
| 537 | * |
||||
| 538 | * @access private |
||||
| 539 | * |
||||
| 540 | * @param int $documentId The document's UID |
||||
| 541 | * |
||||
| 542 | * @return AbstractDocument |
||||
| 543 | */ |
||||
| 544 | private function getDocumentByUid(int $documentId) |
||||
| 545 | { |
||||
| 546 | // TODO: implement multiView as it is in getDocumentByUrl |
||||
| 547 | $doc = null; |
||||
| 548 | $this->document = $this->documentRepository->findOneByIdAndSettings($documentId); |
||||
| 549 | |||||
| 550 | if ($this->document) { |
||||
| 551 | $doc = AbstractDocument::getInstance($this->document->getLocation(), $this->settings, true); |
||||
| 552 | // fix for count(): Argument #1 ($value) must be of type Countable|array, null given |
||||
| 553 | $this->documentArray[] = $doc; |
||||
| 554 | } else { |
||||
| 555 | $this->logger->error('Invalid UID "' . $documentId . '" or PID "' . $this->settings['storagePid'] . '" for document loading'); |
||||
| 556 | } |
||||
| 557 | |||||
| 558 | return $doc; |
||||
| 559 | } |
||||
| 560 | |||||
| 561 | /** |
||||
| 562 | * Get document by URL. |
||||
| 563 | * |
||||
| 564 | * @access protected |
||||
| 565 | * |
||||
| 566 | * @param string $documentId The document's URL |
||||
| 567 | * |
||||
| 568 | * @return AbstractDocument |
||||
| 569 | */ |
||||
| 570 | protected function getDocumentByUrl(string $documentId) |
||||
| 571 | { |
||||
| 572 | $doc = AbstractDocument::getInstance($documentId, $this->settings, true); |
||||
| 573 | |||||
| 574 | if (isset($this->settings['multiViewType']) && $doc->tableOfContents[0]['type'] === $this->settings['multiViewType']) { |
||||
| 575 | $childDocuments = $doc->tableOfContents[0]['children']; |
||||
| 576 | $i = 0; |
||||
| 577 | foreach ($childDocuments as $document) { |
||||
| 578 | $this->documentArray[] = AbstractDocument::getInstance($document['points'], $this->settings, true); |
||||
| 579 | if (!isset($this->requestData['docPage'][$i]) && isset(explode('#', $document['points'])[1])) { |
||||
| 580 | $initPage = explode('#', $document['points'])[1]; |
||||
| 581 | $this->requestData['docPage'][$i] = $initPage; |
||||
| 582 | } |
||||
| 583 | $i++; |
||||
| 584 | } |
||||
| 585 | } else { |
||||
| 586 | $this->documentArray[] = $doc; |
||||
| 587 | } |
||||
| 588 | if (isset($this->requestData['multipleSource']) && is_array($this->requestData['multipleSource'])) { |
||||
| 589 | $i = 0; |
||||
| 590 | foreach ($this->requestData['multipleSource'] as $location) { |
||||
| 591 | $document = AbstractDocument::getInstance($location, $this->settings, true); |
||||
| 592 | if ($document !== null) { |
||||
| 593 | $this->documentArray['extra_' . $i] = $document; |
||||
| 594 | } |
||||
| 595 | $i++; |
||||
| 596 | } |
||||
| 597 | } |
||||
| 598 | |||||
| 599 | if ($doc !== null) { |
||||
| 600 | $this->document = GeneralUtility::makeInstance(Document::class); |
||||
| 601 | |||||
| 602 | if ($doc->recordId) { |
||||
| 603 | // find document from repository by recordId |
||||
| 604 | $docFromRepository = $this->documentRepository->findOneByRecordId($doc->recordId); |
||||
| 605 | if ($docFromRepository !== null) { |
||||
| 606 | $this->document = $docFromRepository; |
||||
| 607 | } |
||||
| 608 | } |
||||
| 609 | |||||
| 610 | // Make sure configuration PID is set when applicable |
||||
| 611 | if ($doc->cPid == 0) { |
||||
| 612 | $doc->cPid = max($this->settings['storagePid'], 0); |
||||
| 613 | } |
||||
| 614 | |||||
| 615 | $this->document->setLocation($documentId); |
||||
| 616 | } else { |
||||
| 617 | $this->logger->error('Invalid location given "' . $documentId . '" for document loading'); |
||||
| 618 | } |
||||
| 619 | |||||
| 620 | return $doc; |
||||
| 621 | } |
||||
| 622 | } |
||||
| 623 |