1414use Kitodo \Dlf \Common \SolrPaginator ;
1515use Kitodo \Dlf \Common \Solr \Solr ;
1616use Kitodo \Dlf \Domain \Model \Collection ;
17+ use Kitodo \Dlf \Domain \Repository \CollectionRepository ;
18+ use Kitodo \Dlf \Domain \Repository \MetadataRepository ;
1719use TYPO3 \CMS \Core \Pagination \SimplePagination ;
1820use TYPO3 \CMS \Core \Utility \GeneralUtility ;
1921use TYPO3 \CMS \Core \Utility \MathUtility ;
20- use Kitodo \Dlf \Domain \Repository \CollectionRepository ;
21- use Kitodo \Dlf \Domain \Repository \MetadataRepository ;
2222
2323/**
2424 * Controller class for the plugin 'Collection'.
@@ -66,6 +66,12 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
6666 $ this ->metadataRepository = $ metadataRepository ;
6767 }
6868
69+ /**
70+ * @access protected
71+ * @var array The current search parameter
72+ */
73+ protected $ searchParams = [];
74+
6975 /**
7076 * Show a list of collections
7177 *
@@ -75,10 +81,9 @@ public function injectMetadataRepository(MetadataRepository $metadataRepository)
7581 */
7682 public function listAction (): void
7783 {
78- $ solr = Solr::getInstance ($ this ->settings ['solrcore ' ]);
79-
80- if (!$ solr ->ready ) {
81- $ this ->logger ->error ('Apache Solr not available ' );
84+ // Quit without doing anything if required variables are not set.
85+ if (empty ($ this ->settings ['solrcore ' ])) {
86+ $ this ->logger ->warning ('Incomplete plugin configuration for SOLR. Please check the plugin settings for UID of SOLR core. ' );
8287 return ;
8388 }
8489
@@ -103,7 +108,7 @@ public function listAction(): void
103108 }
104109 }
105110
106- $ processedCollections = $ this ->processCollections ($ collections, $ solr );
111+ $ processedCollections = $ this ->processCollections ($ collections );
107112
108113 // Randomize sorting?
109114 if (!empty ($ this ->settings ['randomize ' ])) {
@@ -118,35 +123,50 @@ public function listAction(): void
118123 *
119124 * @access protected
120125 *
121- * @param Collection $collection The collection object
126+ * @param ? Collection $collection The collection object
122127 *
123128 * @return void
124129 */
125- public function showAction (Collection $ collection ): void
130+ public function showAction (? Collection $ collection = null ): void
126131 {
127- $ searchParams = $ this ->getParametersSafely ('searchParameter ' );
132+ // Quit without doing anything if required variables are not set.
133+ if (empty ($ this ->settings ['solrcore ' ])) {
134+ $ this ->logger ->warning ('Incomplete plugin configuration for SOLR. Please check the plugin settings for UID of SOLR core. ' );
135+ return ;
136+ }
128137
129- // Instantiate the Solr. Without Solr present, we can't do anything.
130- $ solr = Solr::getInstance ($ this ->settings ['solrcore ' ]);
131- if (!$ solr ->ready ) {
132- $ this ->logger ->error ('Apache Solr not available ' );
138+ $ this ->searchParams = $ this ->getParametersSafely ('searchParameter ' );
139+ $ searchRequestData = GeneralUtility::_GPmerged ('tx_dlf_search ' );
140+
141+ if (isset ($ searchRequestData ['searchParameter ' ]) && is_array ($ searchRequestData ['searchParameter ' ])) {
142+ $ this ->searchParams = array_merge ($ this ->searchParams ?: [], $ searchRequestData ['searchParameter ' ]);
143+ $ this ->request ->getAttribute ('frontend.user ' )->setKey ('ses ' , 'search ' , $ this ->searchParams );
144+ }
145+
146+ if (!isset ($ this ->searchParams ['collection ' ]) && !isset ($ collection )) {
147+ $ this ->logger ->warning ('Collection is not set. ' );
133148 return ;
134149 }
135150
136- // Pagination of Results: Pass the currentPage to the fluid template to calculate current index of search result.
137- $ currentPage = $ this ->getParametersSafely ('page ' );
138- if (empty ($ currentPage )) {
139- $ currentPage = 1 ;
151+ // Get current page from request data because the parameter is shared between plugins
152+ $ currentPage = $ this ->requestData ['page ' ] ?? 1 ;
153+
154+ if (!isset ($ collection )) {
155+ $ collection = $ this ->collectionRepository ->findByUid ($ this ->searchParams ['collection ' ]);
156+ } else {
157+ $ this ->searchParams ['collection ' ] = $ collection ->getUid ();
140158 }
141159
142- $ searchParams ['collection ' ] = $ collection ->getUid ();
143- // If a targetPid is given, the results will be shown by ListView on the target page.
160+ // If a targetPid is given, the results will be shown by Collection on the target page.
144161 if (!empty ($ this ->settings ['targetPid ' ])) {
145- $ this ->redirect ('main ' , 'ListView ' , null ,
162+ $ this ->redirect (
163+ 'show ' ,
164+ 'Collection ' ,
165+ null ,
146166 [
147- 'searchParameter ' => $ searchParams ,
148- ' page ' => $ currentPage
149- ], $ this ->settings ['targetPid ' ]
167+ 'collection ' => $ collection
168+ ],
169+ $ this ->settings ['targetPid ' ]
150170 );
151171 }
152172
@@ -156,27 +176,22 @@ public function showAction(Collection $collection): void
156176 // get all sortable metadata records
157177 $ sortableMetadata = $ this ->metadataRepository ->findByIsSortable (true );
158178
159- // get all documents of given collection
160- $ solrResults = null ;
161- if (is_array ($ searchParams ) && !empty ($ searchParams )) {
162- $ solrResults = $ this ->documentRepository ->findSolrByCollection ($ collection , $ this ->settings , $ searchParams , $ listedMetadata );
179+ $ solrResults = $ this ->documentRepository ->findSolrByCollection ($ collection , $ this ->settings , $ this ->searchParams , $ listedMetadata );
163180
164- $ itemsPerPage = $ this ->settings ['list ' ]['paginate ' ]['itemsPerPage ' ];
165- if (empty ($ itemsPerPage )) {
166- $ itemsPerPage = 25 ;
167- }
168- $ solrPaginator = new SolrPaginator ($ solrResults , $ currentPage , $ itemsPerPage );
169- $ simplePagination = new SimplePagination ($ solrPaginator );
181+ $ itemsPerPage = $ this ->settings ['list ' ]['paginate ' ]['itemsPerPage ' ] ?? 25 ;
170182
171- $ pagination = $ this ->buildSimplePagination ($ simplePagination , $ solrPaginator );
172- $ this ->view ->assignMultiple ([ 'pagination ' => $ pagination , 'paginator ' => $ solrPaginator ]);
173- }
183+ $ solrPaginator = new SolrPaginator ($ solrResults , $ currentPage , $ itemsPerPage );
184+ $ simplePagination = new SimplePagination ($ solrPaginator );
185+
186+ $ pagination = $ this ->buildSimplePagination ($ simplePagination , $ solrPaginator );
187+ $ this ->view ->assignMultiple ([ 'pagination ' => $ pagination , 'paginator ' => $ solrPaginator ]);
174188
175189 $ this ->view ->assign ('viewData ' , $ this ->viewData );
176- $ this ->view ->assign ('documents ' , $ solrResults );
190+ $ this ->view ->assign ('countDocuments ' , $ solrResults ->count ());
191+ $ this ->view ->assign ('countResults ' , $ solrResults ->getNumFound ());
177192 $ this ->view ->assign ('collection ' , $ collection );
178193 $ this ->view ->assign ('page ' , $ currentPage );
179- $ this ->view ->assign ('lastSearch ' , $ searchParams );
194+ $ this ->view ->assign ('lastSearch ' , $ this -> searchParams );
180195 $ this ->view ->assign ('sortableMetadata ' , $ sortableMetadata );
181196 $ this ->view ->assign ('listedMetadata ' , $ listedMetadata );
182197 }
@@ -194,12 +209,12 @@ public function showSortedAction(): void
194209 $ searchParams = $ this ->getParametersSafely ('searchParameter ' );
195210
196211 $ collection = null ;
197- if ($ searchParams ['collection ' ][ ' __identity ' ] && MathUtility::canBeInterpretedAsInteger ($ searchParams ['collection ' ][ ' __identity ' ])) {
198- $ collection = $ this ->collectionRepository ->findByUid ($ searchParams ['collection ' ][ ' __identity ' ] );
212+ if ($ searchParams ['collection ' ] && MathUtility::canBeInterpretedAsInteger ($ searchParams ['collection ' ])) {
213+ $ collection = $ this ->collectionRepository ->findByUid ($ searchParams ['collection ' ]);
199214 }
200215
201216 // output is done by show action
202- $ this ->forward ('show ' , null , null , ['searchParameter ' => $ searchParams , 'collection ' => $ collection ]);
217+ $ this ->forward ('show ' , null , null , ['collection ' => $ collection , 'searchParams ' => $ searchParams ]);
203218
204219 }
205220
@@ -209,12 +224,13 @@ public function showSortedAction(): void
209224 * @access private
210225 *
211226 * @param QueryResultInterface|array|object $collections to be processed
212- * @param Solr $solr for query
213227 *
214228 * @return array
215229 */
216- private function processCollections ($ collections, Solr $ solr ): array
230+ private function processCollections ($ collections ): array
217231 {
232+ $ solr = Solr::getInstance ($ this ->settings ['solrcore ' ]);
233+
218234 $ processedCollections = [];
219235
220236 // Process results.
0 commit comments