@@ -11,11 +11,9 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | namespace StingerSoft\EntitySearchBundle\Form; |
| 13 | 13 | |
| 14 | -use StingerSoft\EntitySearchBundle\Model\Query; |
|
| 15 | 14 | use StingerSoft\EntitySearchBundle\Model\Result\FacetSet; |
| 16 | 15 | use StingerSoft\EntitySearchBundle\Model\ResultSet; |
| 17 | 16 | use Symfony\Component\Form\AbstractType; |
| 18 | -use Symfony\Component\Form\ChoiceList\LazyChoiceList; |
|
| 19 | 17 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
| 20 | 18 | use Symfony\Component\Form\FormBuilderInterface; |
| 21 | 19 | use Symfony\Component\Form\FormEvent; |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | $builder->resetModelTransformers(); |
| 37 | 37 | $builder->resetViewTransformers(); |
| 38 | 38 | |
| 39 | - if($options['multiple']) { |
|
| 40 | - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { |
|
| 39 | + if ($options['multiple']) { |
|
| 40 | + $builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) { |
|
| 41 | 41 | $event->stopPropagation(); |
| 42 | 42 | }, 1); |
| 43 | 43 | } |
| 44 | - $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event){ |
|
| 44 | + $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) { |
|
| 45 | 45 | $data = $event->getForm()->getExtraData(); |
| 46 | 46 | $event->setData(array_unique(array_merge($data, $event->getData()))); |
| 47 | 47 | }); |
@@ -69,13 +69,13 @@ discard block |
||
| 69 | 69 | * @param FacetSet $facets |
| 70 | 70 | */ |
| 71 | 71 | protected function createFacets(FormBuilderInterface $builder, FacetSet $facets) { |
| 72 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
| 73 | - $builder->add('facet_' . $facetType, ChoiceType::class, array( |
|
| 74 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
| 72 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
| 73 | + $builder->add('facet_'.$facetType, ChoiceType::class, array( |
|
| 74 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
| 75 | 75 | 'multiple' => true, |
| 76 | 76 | 'expanded' => true, |
| 77 | 77 | 'choices_as_values' => true, |
| 78 | - 'property_path' => 'facets[' . $facetType . ']', |
|
| 78 | + 'property_path' => 'facets['.$facetType.']', |
|
| 79 | 79 | 'choices' => $this->generateFacetChoices($facetType, $facetValues) |
| 80 | 80 | )); |
| 81 | 81 | } |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | protected function generateFacetChoices($facetType, array $facets) { |
| 90 | 90 | $choices = array(); |
| 91 | 91 | |
| 92 | - foreach($facets as $facet => $count) { |
|
| 93 | - if($count == 0) |
|
| 92 | + foreach ($facets as $facet => $count) { |
|
| 93 | + if ($count == 0) |
|
| 94 | 94 | break; |
| 95 | - $choices[$facet . ' (' . $count . ')'] = $facet; |
|
| 95 | + $choices[$facet.' ('.$count.')'] = $facet; |
|
| 96 | 96 | } |
| 97 | 97 | return $choices; |
| 98 | 98 | } |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
| 48 | - public function testWithNotExistingFacets(){ |
|
| 48 | + public function testWithNotExistingFacets() { |
|
| 49 | 49 | |
| 50 | 50 | $query = new Query('Hemelinger', array(), array( |
| 51 | 51 | Document::FIELD_TYPE |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | * @return \Pec\Bundle\MtuDvpBundle\Entity\TestRiskValue |
| 91 | 91 | */ |
| 92 | 92 | public function __get($name) { |
| 93 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 93 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 94 | 94 | $facetname = substr($name, 6); |
| 95 | 95 | |
| 96 | - if(isset($this->facets[$facetname])) { |
|
| 96 | + if (isset($this->facets[$facetname])) { |
|
| 97 | 97 | return $this->facets[$facetname]; |
| 98 | 98 | } |
| 99 | 99 | return array(); |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | * The value of the property |
| 109 | 109 | */ |
| 110 | 110 | public function __set($name, $value) { |
| 111 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 111 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 112 | 112 | $facetname = substr($name, 6); |
| 113 | 113 | |
| 114 | - if(isset($this->facets[$facetname])) { |
|
| 114 | + if (isset($this->facets[$facetname])) { |
|
| 115 | 115 | $this->facets[$facetname] = array(); |
| 116 | 116 | } |
| 117 | 117 | $this->facets[$facetname] = $value; |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @return boolean |
| 126 | 126 | */ |
| 127 | 127 | public function __isset($name) { |
| 128 | - if(strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 128 | + if (strrpos($name, 'facet_', -strlen($name)) !== false) { |
|
| 129 | 129 | return true; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | public function loadValuesForChoices(array $choices, $value = null) { |
| 40 | 40 | // is called on form creat with $choices containing the preset of the bound entity |
| 41 | 41 | $values = array(); |
| 42 | - foreach($choices as $key => $choice) { |
|
| 42 | + foreach ($choices as $key => $choice) { |
|
| 43 | 43 | // we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value |
| 44 | - if(is_callable($value)) { |
|
| 44 | + if (is_callable($value)) { |
|
| 45 | 45 | $values[$key] = (string)call_user_func($value, $choice, $key); |
| 46 | 46 | } else { |
| 47 | 47 | $values[$key] = $choice; |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | public function loadChoicesForValues(array $values, $value = null) { |
| 86 | 86 | // is called on form submit after loadValuesForChoices of form create and loadChoiceList of form view create |
| 87 | 87 | $choices = array(); |
| 88 | - foreach($values as $key => $val) { |
|
| 88 | + foreach ($values as $key => $val) { |
|
| 89 | 89 | // we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value |
| 90 | - if(is_callable($value)) { |
|
| 90 | + if (is_callable($value)) { |
|
| 91 | 91 | $choices[$key] = (string)call_user_func($value, $val, $key); |
| 92 | 92 | } else { |
| 93 | 93 | $choices[$key] = $val; |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | )); |
| 37 | 37 | |
| 38 | 38 | $usedFacets = $options['used_facets']; |
| 39 | - if($usedFacets){ |
|
| 40 | - foreach($usedFacets as $facetType) { |
|
| 41 | - $builder->add('facet_' . $facetType, FacetType::class, array( |
|
| 42 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
| 39 | + if ($usedFacets) { |
|
| 40 | + foreach ($usedFacets as $facetType) { |
|
| 41 | + $builder->add('facet_'.$facetType, FacetType::class, array( |
|
| 42 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
| 43 | 43 | 'multiple' => true, |
| 44 | 44 | 'expanded' => true, |
| 45 | 45 | )); |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | * @param FacetSet $facets |
| 76 | 76 | */ |
| 77 | 77 | protected function createFacets(FormBuilderInterface $builder, FacetSet $facets) { |
| 78 | - foreach($facets->getFacets() as $facetType => $facetValues) { |
|
| 79 | - $builder->add('facet_' . $facetType, ChoiceType::class, array( |
|
| 80 | - 'label' => 'stinger_soft_entity_search.forms.query.' . $facetType . '.label', |
|
| 78 | + foreach ($facets->getFacets() as $facetType => $facetValues) { |
|
| 79 | + $builder->add('facet_'.$facetType, ChoiceType::class, array( |
|
| 80 | + 'label' => 'stinger_soft_entity_search.forms.query.'.$facetType.'.label', |
|
| 81 | 81 | 'multiple' => true, |
| 82 | 82 | 'expanded' => true, |
| 83 | 83 | 'choices_as_values' => true, |
| 84 | - 'property_path' => 'facets[' . $facetType . ']', |
|
| 84 | + 'property_path' => 'facets['.$facetType.']', |
|
| 85 | 85 | 'choices' => $this->generateFacetChoices($facetType, $facetValues) |
| 86 | 86 | )); |
| 87 | 87 | } |
@@ -95,10 +95,10 @@ discard block |
||
| 95 | 95 | protected function generateFacetChoices($facetType, array $facets) { |
| 96 | 96 | $choices = array(); |
| 97 | 97 | |
| 98 | - foreach($facets as $facet => $count) { |
|
| 99 | - if($count == 0) |
|
| 98 | + foreach ($facets as $facet => $count) { |
|
| 99 | + if ($count == 0) |
|
| 100 | 100 | break; |
| 101 | - $choices[$facet . ' (' . $count . ')'] = $facet; |
|
| 101 | + $choices[$facet.' ('.$count.')'] = $facet; |
|
| 102 | 102 | } |
| 103 | 103 | return $choices; |
| 104 | 104 | } |