@@ -14,7 +14,6 @@ |
||
| 14 | 14 | |
| 15 | 15 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
| 16 | 16 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
| 17 | -use Symfony\Component\HttpKernel\Kernel; |
|
| 18 | 17 | |
| 19 | 18 | |
| 20 | 19 | /** |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private $facetFormatter; |
| 33 | 33 | |
| 34 | 34 | public function searchAction(Request $request, DocumentToEntityMapperInterface $mapper) { |
| 35 | - if($request->query->get('term', false) !== false) { |
|
| 35 | + if ($request->query->get('term', false) !== false) { |
|
| 36 | 36 | $this->setSearchTerm($request->getSession(), $request->query->get('term')); |
| 37 | 37 | return $this->redirectToRoute('stinger_soft_entity_search_search'); |
| 38 | 38 | } |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | )); |
| 49 | 49 | |
| 50 | 50 | $facetForm->handleRequest($request); |
| 51 | - if($facetForm->isSubmitted()) { |
|
| 52 | - if($facetForm->get('clear')->isClicked()) { |
|
| 51 | + if ($facetForm->isSubmitted()) { |
|
| 52 | + if ($facetForm->get('clear')->isClicked()) { |
|
| 53 | 53 | $query->setFacets($this->getDefaultFacets()); |
| 54 | 54 | } |
| 55 | 55 | $this->setSearchTerm($request->getSession(), $query->getSearchTerm()); |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $page = (int)$request->query->get('page', 1); |
| 71 | 71 | $results = null; |
| 72 | - if($result instanceof PaginatableResultSet) { |
|
| 72 | + if ($result instanceof PaginatableResultSet) { |
|
| 73 | 73 | $results = $result->paginate($page, $this->getResultsPerPage()); |
| 74 | - } elseif($result !== null) { |
|
| 74 | + } elseif ($result !== null) { |
|
| 75 | 75 | $results = $result->getResults(($page - 1) * $this->getResultsPerPage(), $this->getResultsPerPage()); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | 'mapper' => $mapper, |
| 83 | 83 | 'facetForm' => $facetForm->createView() |
| 84 | 84 | )); |
| 85 | - } catch(\Exception $exception) { |
|
| 85 | + } catch (\Exception $exception) { |
|
| 86 | 86 | $response = $this->render($this->getErrorTemplate(), array( |
| 87 | 87 | 'error' => $exception->getMessage(), |
| 88 | 88 | 'term' => $query->getSearchTerm() |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | protected function getConfiguredUsedFacets(array $queryUsedFacets) { |
| 127 | 127 | $availableFacets = $this->getAvailableFacets(); |
| 128 | 128 | $usedFacets = array(); |
| 129 | - foreach($queryUsedFacets as $queryUsedFacet) { |
|
| 129 | + foreach ($queryUsedFacets as $queryUsedFacet) { |
|
| 130 | 130 | $usedFacets[$queryUsedFacet] = $availableFacets[$queryUsedFacet]; |
| 131 | 131 | } |
| 132 | 132 | return $usedFacets; |
@@ -193,15 +193,15 @@ discard block |
||
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | protected function initFacets() { |
| 196 | - if(!$this->availableFacets) { |
|
| 196 | + if (!$this->availableFacets) { |
|
| 197 | 197 | $this->availableFacets = array(); |
| 198 | 198 | $this->facetFormatter = array(); |
| 199 | 199 | |
| 200 | 200 | $facetServices = $this->getParameter('stinger_soft.entity_search.available_facets'); |
| 201 | - foreach($facetServices as $facetServiceId) { |
|
| 201 | + foreach ($facetServices as $facetServiceId) { |
|
| 202 | 202 | $facetService = $this->searchService->getFacet($facetServiceId); |
| 203 | 203 | $this->availableFacets[$facetService->getField()] = $facetService->getFormOptions(); |
| 204 | - if($facetService->getFacetFormatter()) { |
|
| 204 | + if ($facetService->getFacetFormatter()) { |
|
| 205 | 205 | $this->facetFormatter[$facetService->getField()] = $facetService->getFacetFormatter(); |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return string[string][] |
| 216 | 216 | */ |
| 217 | 217 | protected function getSearchFacets(SessionInterface $session) { |
| 218 | - $facets = $session->get($this->getSessionPrefix() . '_facets', false); |
|
| 218 | + $facets = $session->get($this->getSessionPrefix().'_facets', false); |
|
| 219 | 219 | return $facets ? \json_decode($facets, true) : $this->getDefaultFacets(); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @param string[string][] $facets |
| 227 | 227 | */ |
| 228 | 228 | protected function setSearchFacets(SessionInterface $session, $facets) { |
| 229 | - $session->set($this->getSessionPrefix() . '_facets', \json_encode($facets)); |
|
| 229 | + $session->set($this->getSessionPrefix().'_facets', \json_encode($facets)); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @return mixed |
| 237 | 237 | */ |
| 238 | 238 | protected function getSearchTerm(SessionInterface $session) { |
| 239 | - return $session->get($this->getSessionPrefix() . '_term', false); |
|
| 239 | + return $session->get($this->getSessionPrefix().'_term', false); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @param string $term |
| 247 | 247 | */ |
| 248 | 248 | protected function setSearchTerm(SessionInterface $session, $term) { |
| 249 | - $session->set($this->getSessionPrefix() . '_term', $term); |
|
| 249 | + $session->set($this->getSessionPrefix().'_term', $term); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | } |
| 253 | 253 | \ No newline at end of file |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param LifecycleEventArgs $args |
| 119 | 119 | */ |
| 120 | 120 | public function postPersist(LifecycleEventArgs $args): void { |
| 121 | - if(!$this->enableIndexing) { |
|
| 121 | + if (!$this->enableIndexing) { |
|
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | 124 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @throws \Doctrine\ORM\OptimisticLockException |
| 131 | 131 | */ |
| 132 | 132 | public function postFlush(PostFlushEventArgs $eventArgs): void { |
| 133 | - if($this->needsFlush) { |
|
| 133 | + if ($this->needsFlush) { |
|
| 134 | 134 | $this->needsFlush = false; |
| 135 | 135 | $eventArgs->getEntityManager()->flush(); |
| 136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param LifecycleEventArgs $args |
| 143 | 143 | */ |
| 144 | 144 | public function preRemove(LifecycleEventArgs $args): void { |
| 145 | - if(!$this->enableIndexing) { |
|
| 145 | + if (!$this->enableIndexing) { |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | $this->removeEntity($args->getObject(), $args->getObjectManager()); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param LifecycleEventArgs $args |
| 155 | 155 | */ |
| 156 | 156 | public function postUpdate(LifecycleEventArgs $args): void { |
| 157 | - if(!$this->enableIndexing) return; |
|
| 157 | + if (!$this->enableIndexing) return; |
|
| 158 | 158 | $this->updateEntity($args->getObject(), $args->getObjectManager()); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -179,12 +179,12 @@ discard block |
||
| 179 | 179 | * @param object $entity |
| 180 | 180 | */ |
| 181 | 181 | protected function updateEntity(object $entity, ObjectManager $manager): void { |
| 182 | - if($entity instanceof SearchableAlias) { |
|
| 182 | + if ($entity instanceof SearchableAlias) { |
|
| 183 | 183 | $entity = $entity->getEntityToIndex(); |
| 184 | 184 | } |
| 185 | 185 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
| 186 | - if($document !== null) { |
|
| 187 | - if($this->getEventDispatcher()) { |
|
| 186 | + if ($document !== null) { |
|
| 187 | + if ($this->getEventDispatcher()) { |
|
| 188 | 188 | $event = new DocumentPreSaveEvent($document); |
| 189 | 189 | $this->getEventDispatcher()->dispatch($event, DocumentPreSaveEvent::NAME); |
| 190 | 190 | } |
@@ -198,11 +198,11 @@ discard block |
||
| 198 | 198 | * @param object $entity |
| 199 | 199 | */ |
| 200 | 200 | protected function removeEntity(object $entity, ObjectManager $manager): void { |
| 201 | - if($entity instanceof SearchableAlias) { |
|
| 201 | + if ($entity instanceof SearchableAlias) { |
|
| 202 | 202 | $entity = $entity->getEntityToIndex(); |
| 203 | 203 | } |
| 204 | 204 | $document = $this->getEntityToDocumentMapper()->createDocument($manager, $entity); |
| 205 | - if($document !== null) { |
|
| 205 | + if ($document !== null) { |
|
| 206 | 206 | $this->getSearchService()->removeDocument($document); |
| 207 | 207 | $this->needsFlush = true; |
| 208 | 208 | } |
@@ -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()); |
@@ -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 | $this->objectManager = $om; |
| 59 | 59 | } |
@@ -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 | |
@@ -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($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($formatter, $facetType, $facet, $value, $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); |