1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
4
|
|
|
*/ |
5
|
|
|
namespace eZ\Publish\Core\MVC\Symfony\Controller\Content; |
6
|
|
|
|
7
|
|
|
use eZ\Publish\API\Repository\SearchService; |
8
|
|
|
use eZ\Publish\Core\MVC\Symfony\View\ContentView; |
9
|
|
|
use eZ\Publish\Core\QueryType\ContentViewQueryTypeMapper; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A content view controller that runs queries based on the matched view configuration. |
13
|
|
|
* |
14
|
|
|
* The action used depends on which type of search is needed: location, content or contentInfo. |
15
|
|
|
*/ |
16
|
|
|
class QueryController |
17
|
|
|
{ |
18
|
|
|
/** @var \eZ\Publish\API\Repository\SearchService */ |
19
|
|
|
private $searchService; |
20
|
|
|
|
21
|
|
|
/** @var \eZ\Publish\Core\QueryType\ContentViewQueryTypeMapper */ |
22
|
|
|
private $contentViewQueryTypeMapper; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
ContentViewQueryTypeMapper $contentViewQueryTypeMapper, |
26
|
|
|
SearchService $searchService |
27
|
|
|
) { |
28
|
|
|
$this->contentViewQueryTypeMapper = $contentViewQueryTypeMapper; |
29
|
|
|
$this->searchService = $searchService; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Runs a content search. |
34
|
|
|
* |
35
|
|
|
* @param ContentView $view |
36
|
|
|
* @return ContentView |
37
|
|
|
*/ |
38
|
|
|
public function contentQueryAction(ContentView $view) |
39
|
|
|
{ |
40
|
|
|
$this->runQuery($view, 'findContent'); |
41
|
|
|
|
42
|
|
|
return $view; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Runs a location search. |
47
|
|
|
* |
48
|
|
|
* @param ContentView $view |
49
|
|
|
* @return ContentView |
50
|
|
|
*/ |
51
|
|
|
public function locationQueryAction(ContentView $view) |
52
|
|
|
{ |
53
|
|
|
$this->runQuery($view, 'findLocations'); |
54
|
|
|
|
55
|
|
|
return $view; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Runs a contentInfo search. |
60
|
|
|
* |
61
|
|
|
* @param ContentView $view |
62
|
|
|
* @return ContentView |
63
|
|
|
*/ |
64
|
|
|
public function contentInfoQueryAction(ContentView $view) |
65
|
|
|
{ |
66
|
|
|
$this->runQuery($view, 'findContentInfo'); |
67
|
|
|
|
68
|
|
|
return $view; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Runs the Query defined in $view using $method on SearchService. |
73
|
|
|
* |
74
|
|
|
* @param ContentView $view |
75
|
|
|
* @param string $method Name of the SearchService method to run. |
76
|
|
|
*/ |
77
|
|
|
private function runQuery(ContentView $view, $method) |
78
|
|
|
{ |
79
|
|
|
$searchResults = $this->searchService->$method( |
80
|
|
|
$this->contentViewQueryTypeMapper->map($view) |
81
|
|
|
); |
82
|
|
|
$view->addParameters([$view->getParameter('query')['assign_results_to'] => $searchResults]); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|