@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | |
34 | 34 | public function addFacetValue(string $key, string $label, $value = null, int $increaseCounterBy = 1) : void { |
35 | 35 | $value = $value ?? $label; |
36 | - if(!isset($this->facets[$key])) { |
|
36 | + if (!isset($this->facets[$key])) { |
|
37 | 37 | $this->facets[$key] = array(); |
38 | 38 | } |
39 | - if(!isset($this->facets[$key][$label])) { |
|
39 | + if (!isset($this->facets[$key][$label])) { |
|
40 | 40 | $this->facets[$key][$label] = array( |
41 | 41 | 'value' => $value, |
42 | 42 | 'count' => 0, |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @see \StingerSoft\EntitySearchBundle\Model\Result\FacetSet::getFacet() |
53 | 53 | */ |
54 | 54 | public function getFacet(string $key): ?array { |
55 | - if(isset($this->facets[$key])) { |
|
55 | + if (isset($this->facets[$key])) { |
|
56 | 56 | return $this->facets[$key]; |
57 | 57 | } |
58 | 58 | return null; |
@@ -36,14 +36,14 @@ |
||
36 | 36 | public function getEntity(Document $document): ?object { |
37 | 37 | $clazz = $document->getEntityClass(); |
38 | 38 | |
39 | - if($clazz === null) { |
|
39 | + if ($clazz === null) { |
|
40 | 40 | return null; |
41 | 41 | } |
42 | - if(!$document->getEntityId()) { |
|
42 | + if (!$document->getEntityId()) { |
|
43 | 43 | return null; |
44 | 44 | } |
45 | 45 | $manager = $this->managerRegistry->getManagerForClass($clazz); |
46 | - if($manager === null) { |
|
46 | + if ($manager === null) { |
|
47 | 47 | return null; |
48 | 48 | } |
49 | 49 | return $manager->getRepository($clazz)->find($document->getEntityId()); |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | public static function getRequiredBundles(string $env, array &$requiredBundles = []): array { |
26 | 26 | |
27 | - if(isset($requiredBundles['StingerSoftEntitySearchBundle'])) { |
|
27 | + if (isset($requiredBundles['StingerSoftEntitySearchBundle'])) { |
|
28 | 28 | return $requiredBundles; |
29 | 29 | } |
30 | 30 |
@@ -71,9 +71,9 @@ discard block |
||
71 | 71 | $this->searchService = $searchService; |
72 | 72 | $this->entityToDocumentMapper = $mapper; |
73 | 73 | // Detect upload path |
74 | - if(!self::$defaultUploadPath) { |
|
74 | + if (!self::$defaultUploadPath) { |
|
75 | 75 | $root = $kernel->getProjectDir(); |
76 | - self::$defaultUploadPath = $root . '/../web/uploads'; |
|
76 | + self::$defaultUploadPath = $root.'/../web/uploads'; |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | // Get the entity argument |
114 | 114 | $entity = $input->getArgument('entity'); |
115 | 115 | |
116 | - if($entity === 'all') { |
|
116 | + if ($entity === 'all') { |
|
117 | 117 | /** |
118 | 118 | * @var EntityManager $entityManager |
119 | 119 | */ |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | /** |
125 | 125 | * @var ClassMetadata $m |
126 | 126 | */ |
127 | - foreach($meta as $m) { |
|
127 | + foreach ($meta as $m) { |
|
128 | 128 | |
129 | - if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
129 | + if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
130 | 130 | continue; |
131 | 131 | } |
132 | - if(!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
132 | + if (!$this->entityToDocumentMapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
133 | 133 | continue; |
134 | 134 | } |
135 | 135 | $this->indexEntity($input, $output, $m->getReflectionClass()->getName()); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | try { |
164 | 164 | // Get repository for the given entity type |
165 | 165 | $repository = $entityManager->getRepository($entity); |
166 | - } catch(Exception $e) { |
|
166 | + } catch (Exception $e) { |
|
167 | 167 | $output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); |
168 | 168 | return; |
169 | 169 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | |
176 | 176 | $useBatch = !($entityManager->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform); |
177 | 177 | $iterableResult = $useBatch ? $queryBuilder->getQuery()->iterate() : $queryBuilder->getQuery()->getResult(); |
178 | - if($entityCount === 0) { |
|
178 | + if ($entityCount === 0) { |
|
179 | 179 | $output->writeln('<comment>No entities found for indexing</comment>'); |
180 | 180 | return; |
181 | 181 | } |
@@ -185,25 +185,25 @@ discard block |
||
185 | 185 | $entitiesIndexed = 0; |
186 | 186 | |
187 | 187 | // Index each entity separate |
188 | - foreach($iterableResult as $row) { |
|
188 | + foreach ($iterableResult as $row) { |
|
189 | 189 | $entity = $useBatch ? $row[0] : $row; |
190 | 190 | $progressBar->advance(); |
191 | - if($this->entityToDocumentMapper->isIndexable($entity)) { |
|
191 | + if ($this->entityToDocumentMapper->isIndexable($entity)) { |
|
192 | 192 | $document = $this->entityToDocumentMapper->createDocument($entityManager, $entity); |
193 | - if($document === null) { |
|
193 | + if ($document === null) { |
|
194 | 194 | continue; |
195 | 195 | } |
196 | 196 | try { |
197 | - if($this->getEventDispatcher()) { |
|
197 | + if ($this->getEventDispatcher()) { |
|
198 | 198 | $event = new DocumentPreSaveEvent($document); |
199 | 199 | $this->getEventDispatcher()->dispatch($event, DocumentPreSaveEvent::NAME); |
200 | 200 | } |
201 | 201 | $this->searchService->saveDocument($document); |
202 | 202 | $entitiesIndexed++; |
203 | - } catch(Exception $e) { |
|
204 | - $output->writeln('<error>Failed to index entity with ID ' . $document->getEntityId() . '</error>'); |
|
203 | + } catch (Exception $e) { |
|
204 | + $output->writeln('<error>Failed to index entity with ID '.$document->getEntityId().'</error>'); |
|
205 | 205 | } |
206 | - if($entitiesIndexed % 50 === 0) { |
|
206 | + if ($entitiesIndexed % 50 === 0) { |
|
207 | 207 | $entityManager->flush(); |
208 | 208 | } |
209 | 209 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $entityManager->clear(); |
214 | 214 | $progressBar->finish(); |
215 | 215 | $output->writeln(''); |
216 | - $output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); |
|
216 | + $output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -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 | } |