@@ -53,7 +53,7 @@ |
||
53 | 53 | * @required |
54 | 54 | */ |
55 | 55 | public function setObjectManager(EntityManagerInterface $om): void { |
56 | - if($this->objectManager) { |
|
56 | + if ($this->objectManager) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | $this->objectManager = $om; |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | * @param ContainerBuilder $container |
17 | 17 | */ |
18 | 18 | public function process(ContainerBuilder $container): void { |
19 | - if(!$container->hasAlias(SearchService::class)) { |
|
19 | + if (!$container->hasAlias(SearchService::class)) { |
|
20 | 20 | return; |
21 | 21 | } |
22 | 22 | |
23 | 23 | $serviceId = (string)$container->getAlias(SearchService::class); |
24 | 24 | |
25 | - if(!$container->hasDefinition($serviceId)) { |
|
25 | + if (!$container->hasDefinition($serviceId)) { |
|
26 | 26 | return; |
27 | 27 | } |
28 | 28 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | $servicesMap = array(); |
32 | 32 | // Builds an array with fully-qualified type class names as keys and service IDs as values |
33 | - foreach($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) { |
|
33 | + foreach ($container->findTaggedServiceIds(FacetServiceInterface::TAG_NAME, true) as $serviceId => $tag) { |
|
34 | 34 | // Add form type service to the service locator |
35 | 35 | $serviceDefinition = $container->getDefinition($serviceId); |
36 | 36 | $servicesMap[$serviceDefinition->getClass()] = new Reference($serviceId); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getFieldValue(string $fieldName) { |
86 | 86 | $value = $this->fields[$fieldName] ?? null; |
87 | - if(\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
87 | + if (\in_array($fieldName, self::$forceSingleValueFields) && \is_array($value)) { |
|
88 | 88 | return current($value); |
89 | 89 | } |
90 | 90 | return $value; |
@@ -97,15 +97,15 @@ discard block |
||
97 | 97 | * @see \StingerSoft\EntitySearchBundle\Model\Document::addMultiValueField() |
98 | 98 | */ |
99 | 99 | public function addMultiValueField(string $fieldName, $value): void { |
100 | - if(!array_key_exists($fieldName, $this->fields)) { |
|
100 | + if (!array_key_exists($fieldName, $this->fields)) { |
|
101 | 101 | $this->fields[$fieldName] = array( |
102 | 102 | $value |
103 | 103 | ); |
104 | - } else if(!\is_array($this->fields[$fieldName])) { |
|
104 | + } else if (!\is_array($this->fields[$fieldName])) { |
|
105 | 105 | $this->fields[$fieldName] = array( |
106 | 106 | $value, $this->fields[$fieldName] |
107 | 107 | ); |
108 | - } else if(!\in_array($value, $this->fields[$fieldName])) { |
|
108 | + } else if (!\in_array($value, $this->fields[$fieldName])) { |
|
109 | 109 | $this->fields[$fieldName][] = $value; |
110 | 110 | } |
111 | 111 | } |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function setEntityClass(string $clazz): void { |
130 | 130 | $this->entityClass = $clazz; |
131 | - if(!$this->entityType) { |
|
131 | + if (!$this->entityType) { |
|
132 | 132 | $this->entityType = $clazz; |
133 | 133 | } |
134 | 134 | } |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | * @return array |
93 | 93 | */ |
94 | 94 | public function __get($name) { |
95 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
95 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
96 | 96 | $facetname = substr($name, 6); |
97 | 97 | |
98 | - if(isset($this->facets[$facetname])) { |
|
98 | + if (isset($this->facets[$facetname])) { |
|
99 | 99 | return $this->facets[$facetname]; |
100 | 100 | } |
101 | 101 | return []; |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * The value of the property |
112 | 112 | */ |
113 | 113 | public function __set($name, $value): void { |
114 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
114 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
115 | 115 | $facetname = substr($name, 6); |
116 | 116 | $this->facets[$facetname] = $value; |
117 | 117 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | private ?array $facetFormatter = null; |
34 | 34 | |
35 | 35 | public function searchAction(Request $request, DocumentToEntityMapperInterface $mapper): Response { |
36 | - if($request->query->get('term', false) !== false) { |
|
36 | + if ($request->query->get('term', false) !== false) { |
|
37 | 37 | $this->setSearchTerm($request->getSession(), $request->query->get('term')); |
38 | 38 | $this->removeFilterOptions($request->getSession()); |
39 | 39 | return $this->redirectToRoute('stinger_soft_entity_search_search'); |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | )); |
51 | 51 | |
52 | 52 | $facetForm->handleRequest($request); |
53 | - if($facetForm->isSubmitted()) { |
|
54 | - if($facetForm->get('clear')->isClicked()) { |
|
53 | + if ($facetForm->isSubmitted()) { |
|
54 | + if ($facetForm->get('clear')->isClicked()) { |
|
55 | 55 | $query->setFacets($this->getDefaultFacets()); |
56 | 56 | } |
57 | 57 | $this->setSearchTerm($request->getSession(), $query->getSearchTerm()); |
58 | 58 | $this->setSearchFacets($request->getSession(), $query->getFacets()); |
59 | - } elseif($this->getUnsetFilterOptions($request->getSession())) { |
|
59 | + } elseif ($this->getUnsetFilterOptions($request->getSession())) { |
|
60 | 60 | $query->setFacets($this->getDefaultFacets()); |
61 | 61 | } |
62 | 62 | |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | |
72 | 72 | $page = (int)$request->query->get('page', 1); |
73 | 73 | $results = null; |
74 | - if($result instanceof PaginatableResultSet) { |
|
74 | + if ($result instanceof PaginatableResultSet) { |
|
75 | 75 | $results = $result->paginate($page, $this->getResultsPerPage()); |
76 | - } elseif($result !== null) { |
|
76 | + } elseif ($result !== null) { |
|
77 | 77 | $results = $result->getResults(($page - 1) * $this->getResultsPerPage(), $this->getResultsPerPage()); |
78 | 78 | } |
79 | 79 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | 'mapper' => $mapper, |
85 | 85 | 'facetForm' => $facetForm->createView() |
86 | 86 | )); |
87 | - } catch(\Exception $exception) { |
|
87 | + } catch (\Exception $exception) { |
|
88 | 88 | $response = $this->render($this->getErrorTemplate(), array( |
89 | 89 | 'error' => $exception->getMessage(), |
90 | 90 | 'term' => $query->getSearchTerm() |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | protected function getConfiguredUsedFacets(array $queryUsedFacets): array { |
129 | 129 | $availableFacets = $this->getAvailableFacets(); |
130 | 130 | $usedFacets = array(); |
131 | - foreach($queryUsedFacets as $queryUsedFacet) { |
|
131 | + foreach ($queryUsedFacets as $queryUsedFacet) { |
|
132 | 132 | $usedFacets[$queryUsedFacet] = $availableFacets[$queryUsedFacet]; |
133 | 133 | } |
134 | 134 | return $usedFacets; |
@@ -195,15 +195,15 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | protected function initFacets(): void { |
198 | - if(!$this->availableFacets) { |
|
198 | + if (!$this->availableFacets) { |
|
199 | 199 | $this->availableFacets = array(); |
200 | 200 | $this->facetFormatter = array(); |
201 | 201 | |
202 | 202 | $facetServices = $this->getParameter('stinger_soft.entity_search.available_facets'); |
203 | - foreach($facetServices as $facetServiceId) { |
|
203 | + foreach ($facetServices as $facetServiceId) { |
|
204 | 204 | $facetService = $this->searchService->getFacet($facetServiceId); |
205 | 205 | $this->availableFacets[$facetService->getField()] = $facetService->getFormOptions(); |
206 | - if($facetService->getFacetFormatter()) { |
|
206 | + if ($facetService->getFacetFormatter()) { |
|
207 | 207 | $this->facetFormatter[$facetService->getField()] = $facetService->getFacetFormatter(); |
208 | 208 | } |
209 | 209 | } |
@@ -217,16 +217,16 @@ discard block |
||
217 | 217 | * @return string[string][] |
218 | 218 | */ |
219 | 219 | protected function getSearchFacets(SessionInterface $session): array { |
220 | - $facets = $session->get($this->getSessionPrefix() . '_facets', false); |
|
220 | + $facets = $session->get($this->getSessionPrefix().'_facets', false); |
|
221 | 221 | return $facets ? \json_decode($facets, true) : $this->getDefaultFacets(); |
222 | 222 | } |
223 | 223 | |
224 | 224 | protected function removeFilterOptions(SessionInterface $session): void { |
225 | - $session->remove($this->getSessionPrefix() . '_filter_options'); |
|
225 | + $session->remove($this->getSessionPrefix().'_filter_options'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | protected function getUnsetFilterOptions(SessionInterface $session): bool { |
229 | - return $session->get($this->getSessionPrefix() . '_filter_options', true); |
|
229 | + return $session->get($this->getSessionPrefix().'_filter_options', true); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,8 +236,8 @@ discard block |
||
236 | 236 | * @param string[string][] $facets |
237 | 237 | */ |
238 | 238 | protected function setSearchFacets(SessionInterface $session, array $facets): void { |
239 | - $session->set($this->getSessionPrefix() . '_facets', \json_encode($facets)); |
|
240 | - $session->set($this->getSessionPrefix() . '_filter_options', false); |
|
239 | + $session->set($this->getSessionPrefix().'_facets', \json_encode($facets)); |
|
240 | + $session->set($this->getSessionPrefix().'_filter_options', false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * @return string|boolean |
248 | 248 | */ |
249 | 249 | protected function getSearchTerm(SessionInterface $session) { |
250 | - return $session->get($this->getSessionPrefix() . '_term', false); |
|
250 | + return $session->get($this->getSessionPrefix().'_term', false); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param string $term |
258 | 258 | */ |
259 | 259 | protected function setSearchTerm(SessionInterface $session, string $term): void { |
260 | - $session->set($this->getSessionPrefix() . '_term', $term); |
|
260 | + $session->set($this->getSessionPrefix().'_term', $term); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
@@ -55,25 +55,25 @@ discard block |
||
55 | 55 | $preferredFilterChoices = $options['preferred_filter_choices']; |
56 | 56 | $maxChoiceGroupCount = (int)$options['max_choice_group_count']; |
57 | 57 | |
58 | - if($usedFacets && !$result) { |
|
58 | + if ($usedFacets && !$result) { |
|
59 | 59 | $data = []; |
60 | - foreach($usedFacets as $facetType => $facetTypeOptions) { |
|
60 | + foreach ($usedFacets as $facetType => $facetTypeOptions) { |
|
61 | 61 | $facetTypeOptions = is_array($facetTypeOptions) ? $facetTypeOptions : []; |
62 | 62 | $preferredChoices = $preferredFilterChoices[$facetType] ?? []; |
63 | 63 | $i = 0; |
64 | - $builder->add('facet_' . $facetType, FacetType::class, array_merge(array( |
|
65 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
64 | + $builder->add('facet_'.$facetType, FacetType::class, array_merge(array( |
|
65 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
66 | 66 | 'multiple' => true, |
67 | 67 | 'expanded' => true, |
68 | 68 | 'preferred_choices' => function($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) { |
69 | - $facetKey = 'facet_' . $facetType; |
|
69 | + $facetKey = 'facet_'.$facetType; |
|
70 | 70 | return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount === 0 || \in_array($val, $preferredChoices) || (isset($data[$facetKey]) && \in_array($val, $data[$facetKey])); |
71 | 71 | } |
72 | 72 | ), $facetTypeOptions)); |
73 | 73 | unset($i); |
74 | 74 | } |
75 | 75 | } |
76 | - if($result) { |
|
76 | + if ($result) { |
|
77 | 77 | $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options, $result) { |
78 | 78 | $this->createFacets($event->getForm(), $result->getFacets(), $options, $event->getData()); |
79 | 79 | }); |
@@ -137,14 +137,14 @@ discard block |
||
137 | 137 | $selectedFacets = $data->getFacets(); |
138 | 138 | $usedFacets = $options['used_facets']; |
139 | 139 | |
140 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
140 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
141 | 141 | $preferredChoices = $preferredFilterChoices[$facetType] ?? []; |
142 | 142 | |
143 | 143 | $i = 0; |
144 | 144 | $facetTypeOptions = $usedFacets[$facetType] ?? []; |
145 | 145 | $formatter = $options['facet_formatter'][$facetType] ?? null; |
146 | - $builder->add('facet_' . $facetType, FacetType::class, array_merge(array( |
|
147 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
146 | + $builder->add('facet_'.$facetType, FacetType::class, array_merge(array( |
|
147 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
148 | 148 | 'multiple' => true, |
149 | 149 | 'expanded' => true, |
150 | 150 | 'choices' => $this->generateFacetChoices($facetType, $facetValues, $selectedFacets[$facetType] ?? [], $formatter), |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | protected function generateFacetChoices(string $facetType, array $facets, array $selectedFacets = [], callable $formatter = null): array { |
168 | 168 | $choices = []; |
169 | 169 | $handledFacets = []; |
170 | - foreach($facets as $facet => $data) { |
|
170 | + foreach ($facets as $facet => $data) { |
|
171 | 171 | $value = $data['value']; |
172 | 172 | $count = $data['count']; |
173 | - if($count === 0 && !\in_array($facet, $selectedFacets)) { |
|
173 | + if ($count === 0 && !\in_array($facet, $selectedFacets)) { |
|
174 | 174 | continue; |
175 | 175 | } |
176 | 176 | $handledFacets[$facet] = true; |
177 | 177 | $choices[$this->formatFacet($formatter, $facetType, $facet, $value, $count)] = $facet; |
178 | 178 | } |
179 | - foreach($selectedFacets as $facet) { |
|
180 | - if(!isset($facets[$facet]) || isset($handledFacets[$facet])) { |
|
179 | + foreach ($selectedFacets as $facet) { |
|
180 | + if (!isset($facets[$facet]) || isset($handledFacets[$facet])) { |
|
181 | 181 | continue; |
182 | 182 | } |
183 | 183 | $value = $facets[$facet]['value']; |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | * @return string |
197 | 197 | */ |
198 | 198 | protected function formatFacet(?callable $formatter, string $facetType, string $facet, $value, int $count): string { |
199 | - $default = $facet . ' (' . $count . ')'; |
|
200 | - if(!$formatter) { |
|
199 | + $default = $facet.' ('.$count.')'; |
|
200 | + if (!$formatter) { |
|
201 | 201 | return $default; |
202 | 202 | } |
203 | 203 | return $formatter($facetType, $value, $count, $default); |