1 | <?php |
||
27 | class QueryGroupFacetParser extends AbstractFacetParser |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @param SearchResultSet $resultSet |
||
32 | * @param string $facetName |
||
33 | * @param array $facetConfiguration |
||
34 | * @return QueryGroupFacet|null |
||
35 | */ |
||
36 | 34 | public function parse(SearchResultSet $resultSet, $facetName, array $facetConfiguration) |
|
37 | { |
||
38 | 34 | $response = $resultSet->getResponse(); |
|
39 | 34 | $fieldName = $facetConfiguration['field']; |
|
40 | 34 | $label = $this->getPlainLabelOrApplyCObject($facetConfiguration); |
|
41 | |||
42 | 34 | $rawOptions = $this->getRawOptions($response, $fieldName); |
|
43 | 34 | $noOptionsInResponse = $rawOptions === []; |
|
44 | 34 | $hideEmpty = !$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchFacetingShowEmptyFacetsByName($facetName); |
|
45 | |||
46 | 34 | if ($noOptionsInResponse && $hideEmpty) { |
|
47 | 3 | return null; |
|
48 | } |
||
49 | |||
50 | /** @var QueryGroupFacet $facet */ |
||
51 | 31 | $facet = $this->objectManager->get( |
|
52 | 31 | QueryGroupFacet::class, |
|
53 | 31 | $resultSet, |
|
|
|||
54 | 31 | $facetName, |
|
55 | 31 | $fieldName, |
|
56 | 31 | $label, |
|
57 | 31 | $facetConfiguration |
|
58 | ); |
||
59 | |||
60 | 31 | $activeFacets = $resultSet->getUsedSearchRequest()->getActiveFacetNames(); |
|
61 | 31 | $facet->setIsUsed(in_array($facetName, $activeFacets, true)); |
|
62 | |||
63 | 31 | if (!$noOptionsInResponse) { |
|
64 | 31 | $facet->setIsAvailable(true); |
|
65 | 31 | foreach ($rawOptions as $query => $count) { |
|
66 | 31 | $value = $this->getValueByQuery($query, $facetConfiguration); |
|
67 | // Skip unknown queries |
||
68 | 31 | if ($value === null) { |
|
69 | continue; |
||
70 | } |
||
71 | |||
72 | 31 | if ($this->getIsExcludedFacetValue($query, $facetConfiguration)) { |
|
73 | continue; |
||
74 | } |
||
75 | |||
76 | 31 | $isOptionsActive = $resultSet->getUsedSearchRequest()->getHasFacetValue($facetName, $value); |
|
77 | 31 | $label = $this->getLabelFromRenderingInstructions( |
|
78 | 31 | $value, |
|
79 | 31 | $count, |
|
80 | 31 | $facetName, |
|
81 | 31 | $facetConfiguration |
|
82 | ); |
||
83 | 31 | $facet->addOption(new Option($facet, $label, $value, $count, $isOptionsActive)); |
|
84 | } |
||
85 | } |
||
86 | |||
87 | |||
88 | // after all options have been created we apply a manualSortOrder if configured |
||
89 | // the sortBy (lex,..) is done by the solr server and triggered by the query, therefore it does not |
||
90 | // need to be handled in the frontend. |
||
91 | 31 | $facet = $this->applyManualSortOrder($facet, $facetConfiguration); |
|
92 | |||
93 | 31 | $facet = $this->applyReverseOrder($facet, $facetConfiguration); |
|
94 | |||
95 | 31 | return $facet; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * Get raw query options |
||
100 | * |
||
101 | * @param \Apache_Solr_Response $response |
||
102 | * @param string $fieldName |
||
103 | * @return array |
||
104 | */ |
||
105 | 34 | protected function getRawOptions(\Apache_Solr_Response $response, $fieldName) |
|
127 | |||
128 | /** |
||
129 | * @param string $query |
||
130 | * @param array $facetConfiguration |
||
131 | * @return string|null |
||
132 | */ |
||
133 | 31 | protected function getValueByQuery($query, array $facetConfiguration) |
|
144 | } |
||
145 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.