| 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 TYPO3\CMS\Core\Utility\GeneralUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use TYPO3\CMS\Core\Utility\MathUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * Controller class for the plugin 'Navigation'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @author Sebastian Meyer <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @package TYPO3 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @subpackage dlf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | class NavigationController extends AbstractController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * Method to get the page select values and use them with chash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param \Kitodo\Dlf\Domain\Model\PageSelectForm|NULL $pageSelectForm | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @return void | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     public function pageSelectAction(\Kitodo\Dlf\Domain\Model\PageSelectForm $pageSelectForm = NULL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         if ($pageSelectForm) { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             $uriBuilder = $this->getControllerContext()->getUriBuilder(); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             $uri = $uriBuilder->reset() | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |                 ->setArguments( | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |                     [ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |                         'tx_dlf' => [ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |                             'id' => $pageSelectForm->getId(), | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |                             'page' => $pageSelectForm->getPage(), | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |                             'double' => $pageSelectForm->getDouble() | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |                         ] | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                     ] | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                 ) | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                 ->uriFor('main'); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |             $this->redirectToUri($uri); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * The main method of the plugin | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function mainAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         // Load current document. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->loadDocument($this->requestData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         if ($this->isDocMissing()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             // Quit without doing anything if required variables are not set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             return ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             // Set default values if not set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             if ($this->document->getDoc()->numPages > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 if (!empty($this->requestData['logicalPage'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                     $this->requestData['page'] = $this->document->getDoc()->getPhysicalPage($this->requestData['logicalPage']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                     // The logical page parameter should not appear | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     unset($this->requestData['logicalPage']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                 // Set default values if not set. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                 // $this->requestData['page'] may be integer or string (physical structure @ID) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                 if ( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                     (int) $this->requestData['page'] > 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     || empty($this->requestData['page']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |                     $this->requestData['page'] = MathUtility::forceIntegerInRange((int) $this->requestData['page'], 1, $this->document->getDoc()->numPages, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                     $this->requestData['page'] = array_search($this->requestData['page'], $this->document->getDoc()->physicalStructure); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                 $this->requestData['double'] = MathUtility::forceIntegerInRange($this->requestData['double'], 0, 1, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 $this->requestData['page'] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                 $this->requestData['double'] = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         // Steps for X pages backward / forward. Double page view uses double steps. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $pageSteps = $this->settings['pageStep'] * ($this->requestData['double'] + 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->view->assign('pageSteps', $pageSteps); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         $this->view->assign('numPages', $this->document->getDoc()->numPages); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $this->view->assign('viewData', $this->viewData); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         if ($GLOBALS['TSFE']->fe_user->getKey('ses', 'search')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             $lastSearchArguments = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             $searchSessionParameters = $GLOBALS['TSFE']->fe_user->getKey('ses', 'search'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             $widgetPage = $GLOBALS['TSFE']->fe_user->getKey('ses', 'widgetPage'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             if ($searchSessionParameters) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 $lastSearchArguments = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                     'tx_dlf_listview' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                         'searchParameter' => $searchSessionParameters | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             if ($widgetPage) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 $lastSearchArguments['tx_dlf_listview']['@widget_0'] = $widgetPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             // save last search parameter to generate a link back to the search list | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             $this->view->assign('lastSearchParams', $lastSearchArguments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $pageOptions = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         for ($i = 1; $i <= $this->document->getDoc()->numPages; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $pageOptions[$i] = '[' . $i . ']' . ($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel'] ? ' - ' . htmlspecialchars($this->document->getDoc()->physicalStructureInfo[$this->document->getDoc()->physicalStructure[$i]]['orderlabel']) : ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->view->assign('pageOptions', $pageOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         // prepare feature array for fluid | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $features = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         foreach (explode(',', $this->settings['features']) as $feature) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             $features[$feature] = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         $this->view->assign('features', $features); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 128 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 129 |  |  |  |