|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Codappix\SearchCore\Controller; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright (C) 2016 Daniel Siepmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software; you can redistribute it and/or |
|
9
|
|
|
* modify it under the terms of the GNU General Public License |
|
10
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
11
|
|
|
* of the License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU General Public License |
|
19
|
|
|
* along with this program; if not, write to the Free Software |
|
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21
|
|
|
* 02110-1301, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use Codappix\SearchCore\Domain\Model\SearchRequest; |
|
25
|
|
|
use Codappix\SearchCore\Domain\Search\SearchServiceInterface; |
|
26
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Handling search logic in TYPO3 Frontend. |
|
30
|
|
|
*/ |
|
31
|
|
|
class SearchController extends ActionController |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var SearchServiceInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $searchService; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param SearchServiceInterface $searchService |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(SearchServiceInterface $searchService) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->searchService = $searchService; |
|
44
|
|
|
|
|
45
|
|
|
parent::__construct(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Allow dynamic properties in search request |
|
50
|
|
|
*/ |
|
51
|
|
|
public function initializeResultsAction() |
|
52
|
|
|
{ |
|
53
|
|
|
if (isset($this->settings['searching']['mode']) |
|
54
|
|
|
&& $this->settings['searching']['mode'] === 'filter' |
|
55
|
|
|
&& $this->request->hasArgument('searchRequest') === false |
|
56
|
|
|
) { |
|
57
|
|
|
$this->request->setArguments(array_merge( |
|
58
|
|
|
$this->request->getArguments(), |
|
59
|
|
|
['searchRequest' => $this->objectManager->get(SearchRequest::class)] |
|
60
|
|
|
)); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($this->arguments->hasArgument('searchRequest')) { |
|
64
|
|
|
$this->arguments->getArgument('searchRequest')->getPropertyMappingConfiguration() |
|
65
|
|
|
->allowAllProperties(); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Display results and deliver original request and result to view. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function resultsAction(SearchRequest $searchRequest = null) |
|
73
|
|
|
{ |
|
74
|
|
|
$searchResult = null; |
|
75
|
|
|
if ($searchRequest !== null) { |
|
76
|
|
|
$searchResult = $this->searchService->search($searchRequest); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->view->assignMultiple([ |
|
80
|
|
|
'searchRequest' => $searchRequest, |
|
81
|
|
|
'searchResult' => $searchResult, |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|