@@ -53,25 +53,25 @@ discard block |
||
53 | 53 | $maxChoiceGroupCount = $options['max_choice_group_count']; |
54 | 54 | $data = array(); |
55 | 55 | |
56 | - if($usedFacets && !$result) { |
|
56 | + if ($usedFacets && !$result) { |
|
57 | 57 | $data = array(); |
58 | - foreach($usedFacets as $facetType => $facetTypeOptions) { |
|
58 | + foreach ($usedFacets as $facetType => $facetTypeOptions) { |
|
59 | 59 | $preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array(); |
60 | 60 | $i = 0; |
61 | - $builder->add('facet_' . $facetType, FacetType::class, array_merge(array( |
|
62 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
61 | + $builder->add('facet_'.$facetType, FacetType::class, array_merge(array( |
|
62 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
63 | 63 | 'multiple' => true, |
64 | 64 | 'expanded' => true, |
65 | 65 | 'allow_extra_fields' => true, |
66 | - 'preferred_choices' => function ($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) { |
|
67 | - return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_' . $facetType]) && in_array($val, $data['facet_' . $facetType])); |
|
66 | + 'preferred_choices' => function($val) use ($preferredChoices, $data, $facetType, $maxChoiceGroupCount, &$i) { |
|
67 | + return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($data['facet_'.$facetType]) && in_array($val, $data['facet_'.$facetType])); |
|
68 | 68 | } |
69 | 69 | ), $facetTypeOptions)); |
70 | 70 | unset($i); |
71 | 71 | } |
72 | 72 | } |
73 | - if($result) { |
|
74 | - $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($options, $result) { |
|
73 | + if ($result) { |
|
74 | + $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options, $result) { |
|
75 | 75 | $this->createFacets($event->getForm(), $result->getFacets(), $options, $event->getData()); |
76 | 76 | }); |
77 | 77 | } |
@@ -110,18 +110,18 @@ discard block |
||
110 | 110 | $selectedFacets = $data->getFacets(); |
111 | 111 | $usedFacets = $options['used_facets']; |
112 | 112 | |
113 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
113 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
114 | 114 | $preferredChoices = isset($preferredFilterChoices[$facetType]) ? $preferredFilterChoices[$facetType] : array(); |
115 | 115 | |
116 | 116 | $i = 0; |
117 | 117 | $facetTypeOptions = $usedFacets[$facetType]; |
118 | - $builder->add('facet_' . $facetType, FacetType::class, array_merge(array( |
|
119 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
118 | + $builder->add('facet_'.$facetType, FacetType::class, array_merge(array( |
|
119 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
120 | 120 | 'multiple' => true, |
121 | 121 | 'expanded' => true, |
122 | 122 | 'allow_extra_fields' => true, |
123 | 123 | 'choices' => $this->generateFacetChoices($facetType, $facetValues, isset($selectedFacets[$facetType]) ? $selectedFacets[$facetType] : array(), $options['facet_formatter']), |
124 | - 'preferred_choices' => function ($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) { |
|
124 | + 'preferred_choices' => function($val) use ($preferredChoices, $selectedFacets, $facetType, $maxChoiceGroupCount, &$i) { |
|
125 | 125 | return $i++ < $maxChoiceGroupCount || $maxChoiceGroupCount == 0 || in_array($val, $preferredChoices) || (isset($selectedFacets[$facetType]) && in_array($val, $selectedFacets[$facetType])); |
126 | 126 | } |
127 | 127 | ), $facetTypeOptions)); |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | */ |
137 | 137 | protected function generateFacetChoices($facetType, array $facets, array $selectedFacets = array(), $formatter) { |
138 | 138 | $choices = array(); |
139 | - foreach($facets as $facet => $count) { |
|
140 | - if($count == 0 && !in_array($facet, $selectedFacets)) |
|
139 | + foreach ($facets as $facet => $count) { |
|
140 | + if ($count == 0 && !in_array($facet, $selectedFacets)) |
|
141 | 141 | continue; |
142 | 142 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
143 | 143 | } |
144 | - foreach($selectedFacets as $facet) { |
|
145 | - if(isset($facets[$facet])) continue; |
|
144 | + foreach ($selectedFacets as $facet) { |
|
145 | + if (isset($facets[$facet])) continue; |
|
146 | 146 | $count = 0; |
147 | 147 | $choices[$this->formatFacet($formatter, $facetType, $facet, $count)] = $facet; |
148 | 148 | } |
@@ -150,8 +150,8 @@ discard block |
||
150 | 150 | } |
151 | 151 | |
152 | 152 | protected function formatFacet($formatter, $facetType, $facet, $count) { |
153 | - $default = $facet . ' (' . $count . ')'; |
|
154 | - if(!$formatter) { |
|
153 | + $default = $facet.' ('.$count.')'; |
|
154 | + if (!$formatter) { |
|
155 | 155 | return $default; |
156 | 156 | } |
157 | 157 | return call_user_func($formatter, $facetType, $facet, $count, $default); |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function execute(InputInterface $input, OutputInterface $output) { |
71 | 71 | // Detect upload path |
72 | - if(!self::$defaultUploadPath) { |
|
72 | + if (!self::$defaultUploadPath) { |
|
73 | 73 | $root = $this->getContainer()->get('kernel')->getRootDir(); |
74 | - self::$defaultUploadPath = $root . '/../web/uploads'; |
|
74 | + self::$defaultUploadPath = $root.'/../web/uploads'; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | // Get the entity argument |
78 | 78 | $entity = $input->getArgument('entity'); |
79 | 79 | |
80 | - if($entity == 'all') { |
|
80 | + if ($entity == 'all') { |
|
81 | 81 | /** |
82 | 82 | * @var EntityManager $entityManager |
83 | 83 | */ |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * @var ClassMetadata $m |
95 | 95 | */ |
96 | - foreach($meta as $m) { |
|
96 | + foreach ($meta as $m) { |
|
97 | 97 | |
98 | - if($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
98 | + if ($m->getReflectionClass()->isAbstract() || $m->getReflectionClass()->isInterface()) { |
|
99 | 99 | continue; |
100 | 100 | } |
101 | - if(!$mapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
101 | + if (!$mapper->isClassIndexable($m->getReflectionClass()->getName())) { |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | $this->indexEntity($input, $output, $m->getReflectionClass()->getName()); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | try { |
120 | 120 | // Get repository for the given entity type |
121 | 121 | $repository = $entityManager->getRepository($entity); |
122 | - } catch(\Exception $e) { |
|
122 | + } catch (\Exception $e) { |
|
123 | 123 | $output->writeln(sprintf('<error>No repository found for "%s", check your input</error>', $entity)); |
124 | 124 | return; |
125 | 125 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $useBatch = !($entityManager->getConnection()->getDatabasePlatform() instanceof SQLServerPlatform); |
133 | 133 | |
134 | 134 | $iterableResult = $useBatch ? $queryBuilder->getQuery()->iterate() : $queryBuilder->getQuery()->getResult(); |
135 | - if($entityCount == 0) { |
|
135 | + if ($entityCount == 0) { |
|
136 | 136 | $output->writeln('<comment>No entities found for indexing</comment>'); |
137 | 137 | return; |
138 | 138 | } |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | $entitiesIndexed = 0; |
141 | 141 | |
142 | 142 | // Index each entity separate |
143 | - foreach($iterableResult as $row) { |
|
143 | + foreach ($iterableResult as $row) { |
|
144 | 144 | $entity = $useBatch ? $row[0] : $row; |
145 | - if($this->getEntityToDocumentMapper()->isIndexable($entity)) { |
|
145 | + if ($this->getEntityToDocumentMapper()->isIndexable($entity)) { |
|
146 | 146 | $document = $this->getEntityToDocumentMapper()->createDocument($entityManager, $entity); |
147 | - if($document === false) continue; |
|
147 | + if ($document === false) continue; |
|
148 | 148 | $this->getSearchService($entityManager)->saveDocument($document); |
149 | 149 | $entitiesIndexed++; |
150 | - if($entitiesIndexed % 50 == 0) { |
|
150 | + if ($entitiesIndexed % 50 == 0) { |
|
151 | 151 | $entityManager->flush(); |
152 | 152 | } |
153 | 153 | } |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | $entityManager->flush(); |
157 | 157 | $entityManager->clear(); |
158 | - $output->writeln('<comment>Indexed ' . $entitiesIndexed . ' entities</comment>'); |
|
158 | + $output->writeln('<comment>Indexed '.$entitiesIndexed.' entities</comment>'); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return EntityToDocumentMapperInterface |
164 | 164 | */ |
165 | 165 | protected function getEntityToDocumentMapper() { |
166 | - if(!$this->entityToDocumentMapper) { |
|
166 | + if (!$this->entityToDocumentMapper) { |
|
167 | 167 | $this->entityToDocumentMapper = $this->getContainer()->get(EntityToDocumentMapperInterface::SERVICE_ID); |
168 | 168 | } |
169 | 169 | return $this->entityToDocumentMapper; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @return SearchService |
175 | 175 | */ |
176 | 176 | protected function getSearchService(ObjectManager $manager) { |
177 | - if(!$this->searchService) { |
|
177 | + if (!$this->searchService) { |
|
178 | 178 | $this->searchService = $this->getContainer()->get(SearchService::SERVICE_ID); |
179 | 179 | } |
180 | 180 | $this->searchService->setObjectManager($manager); |