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,68 +123,71 @@ 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 ' );
128-
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 ' );
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. ' );
133135 return ;
134136 }
135137
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 ;
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+ // Get current page from request data because the parameter is shared between plugins
147+ $ currentPage = $ this ->requestData ['page ' ] ?? 1 ;
148+
149+ if (!isset ($ collection )) {
150+ $ collection = $ this ->collectionRepository ->findByUid ($ this ->searchParams ['collection ' ]);
151+ } else {
152+ $ this ->searchParams ['collection ' ] = $ collection ->getUid ();
140153 }
141154
142- $ searchParams ['collection ' ] = $ collection ->getUid ();
143- // If a targetPid is given, the results will be shown by ListView on the target page.
155+ // If a targetPid is given, the results will be shown by Collection on the target page.
144156 if (!empty ($ this ->settings ['targetPid ' ])) {
145- $ this ->redirect ('main ' , 'ListView ' , null ,
157+ $ this ->redirect (
158+ 'show ' ,
159+ 'Collection ' ,
160+ null ,
146161 [
147- 'searchParameter ' => $ searchParams ,
148- ' page ' => $ currentPage
149- ], $ this ->settings ['targetPid ' ]
162+ 'collection ' => $ collection
163+ ],
164+ $ this ->settings ['targetPid ' ]
150165 );
151166 }
152167
153168 // get all metadata records to be shown in results
154169 $ listedMetadata = $ this ->metadataRepository ->findByIsListed (true );
155170
156- // get all indexed metadata fields
157- $ indexedMetadata = $ this ->metadataRepository ->findByIndexIndexed (true );
158-
159171 // get all sortable metadata records
160172 $ sortableMetadata = $ this ->metadataRepository ->findByIsSortable (true );
161173
162- // get all documents of given collection
163- $ solrResults = null ;
164- if (is_array ($ searchParams ) && !empty ($ searchParams )) {
165- $ solrResults = $ this ->documentRepository ->findSolrByCollection ($ collection , $ this ->settings , $ searchParams , $ listedMetadata , $ indexedMetadata );
174+ $ solrResults = $ this ->documentRepository ->findSolrByCollection ($ collection , $ this ->settings , $ this ->searchParams , $ listedMetadata );
175+ $ numResults = $ solrResults ->getNumFound ();
166176
167- $ itemsPerPage = $ this ->settings ['list ' ]['paginate ' ]['itemsPerPage ' ];
168- if (empty ($ itemsPerPage )) {
169- $ itemsPerPage = 25 ;
170- }
171- $ solrPaginator = new SolrPaginator ($ solrResults , $ currentPage , $ itemsPerPage );
172- $ simplePagination = new SimplePagination ($ solrPaginator );
177+ $ itemsPerPage = $ this ->settings ['list ' ]['paginate ' ]['itemsPerPage ' ] ?? 25 ;
173178
174- $ pagination = $ this ->buildSimplePagination ($ simplePagination , $ solrPaginator );
175- $ this ->view ->assignMultiple ([ 'pagination ' => $ pagination , 'paginator ' => $ solrPaginator ]);
176- }
179+ $ solrPaginator = new SolrPaginator ($ solrResults , $ currentPage , $ itemsPerPage );
180+ $ simplePagination = new SimplePagination ($ solrPaginator );
181+
182+ $ pagination = $ this ->buildSimplePagination ($ simplePagination , $ solrPaginator );
183+ $ this ->view ->assignMultiple ([ 'pagination ' => $ pagination , 'paginator ' => $ solrPaginator ]);
177184
178185 $ this ->view ->assign ('viewData ' , $ this ->viewData );
179- $ this ->view ->assign ('documents ' , $ solrResults );
186+ $ this ->view ->assign ('documents ' , !empty ($ solrResults ) ? $ solrResults : []);
187+ $ this ->view ->assign ('numResults ' , $ numResults );
180188 $ this ->view ->assign ('collection ' , $ collection );
181189 $ this ->view ->assign ('page ' , $ currentPage );
182- $ this ->view ->assign ('lastSearch ' , $ searchParams );
190+ $ this ->view ->assign ('lastSearch ' , $ this -> searchParams );
183191 $ this ->view ->assign ('sortableMetadata ' , $ sortableMetadata );
184192 $ this ->view ->assign ('listedMetadata ' , $ listedMetadata );
185193 }
@@ -202,7 +210,7 @@ public function showSortedAction(): void
202210 }
203211
204212 // output is done by show action
205- $ this ->forward ('show ' , null , null , ['searchParameter ' => $ searchParams , 'collection ' => $ collection ]);
213+ $ this ->forward ('show ' , null , null , ['collection ' => $ collection , 'searchParams ' => $ searchParams ]);
206214
207215 }
208216
@@ -212,12 +220,13 @@ public function showSortedAction(): void
212220 * @access private
213221 *
214222 * @param QueryResultInterface|array|object $collections to be processed
215- * @param Solr $solr for query
216223 *
217224 * @return array
218225 */
219- private function processCollections ($ collections, Solr $ solr ): array
226+ private function processCollections ($ collections ): array
220227 {
228+ $ solr = Solr::getInstance ($ this ->settings ['solrcore ' ]);
229+
221230 $ processedCollections = [];
222231
223232 // Process results.
0 commit comments