Skip to content

Commit

Permalink
Merge pull request #5 from contao-estatemanager/develop
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
doishub authored Dec 15, 2020
2 parents 7ca72a1 + 25da4d5 commit fd8efa0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/Resources/contao/languages/de/tl_expose_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<target>Maximale Entfernung</target>
</trans-unit>
<trans-unit id="tl_expose_module.similarDistance.1">
<source>Here you can enter the radius in km in which similar real estate are considered.</source>
<target>Hier können Sie den Radius in km eingeben, in welchem ähnliche Immobilien berücksichtigt werden.</target>
<source>Here you can enter the radius in km in which similar real estate are considered. Enter 0 to not perform a proximity search.</source>
<target>Hier können Sie den Radius in km eingeben, in welchem ähnliche Immobilien berücksichtigt werden. Geben Sie 0 ein, um keine Radius-Abfrage durchzuführen.</target>
</trans-unit>
</body>
</file>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/languages/en/tl_expose_module.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<source>Maximum distance</source>
</trans-unit>
<trans-unit id="tl_expose_module.similarDistance.1">
<source>Here you can enter the radius in km in which similar real estate are considered.</source>
<source>Here you can enter the radius in km in which similar real estate are considered. Enter 0 to not perform a proximity search.</source>
</trans-unit>
</body>
</file>
Expand Down
77 changes: 51 additions & 26 deletions src/Resources/contao/modules/ExposeModuleSimilar.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function fetchItems($limit, $offset): ?object
*
* @return array
*/
protected function getFilterOptions(): array
protected function getFilterOptions(): ?array
{
$t = 'tl_real_estate';

Expand Down Expand Up @@ -171,75 +171,100 @@ protected function getFilterOptions(): array
{
$priceFrom = intval($_SESSION['FILTER_DATA']['price_from']);
}
else
elseif($this->realEstate->{$objType->price})
{
$priceFrom = $this->realEstate->{$objType->price};
}

$arrColumns[] = "$t.".$objType->price.">=?";
$arrValues[] = ($priceFrom - ($priceFrom * ($this->filterCoarse / 100))) > 0 ?: 0;
if($priceFrom)
{
$arrColumns[] = "$t.".$objType->price.">=?";
$arrValues[] = ($priceFrom - ($priceFrom * ($this->filterCoarse / 100))) > 0 ?: 0;
}

if ($_SESSION['FILTER_DATA']['price_to'])
{
$priceTo = intval($_SESSION['FILTER_DATA']['price_to']);
}
else
elseif($this->realEstate->{$objType->price})
{
$priceTo = $this->realEstate->{$objType->price};
}
$arrColumns[] = "$t.".$objType->price."<=?";
$arrValues[] = ($priceTo + ($priceTo * ($this->filterCoarse / 100)));

if($priceTo)
{
$arrColumns[] = "$t.".$objType->price."<=?";
$arrValues[] = ($priceTo + ($priceTo * ($this->filterCoarse / 100)));
}

if ($_SESSION['FILTER_DATA']['room_from'])
{
$roomFrom = intval($_SESSION['FILTER_DATA']['room_from']);
}
else
elseif($this->realEstate->anzahlZimmer)
{
$roomFrom = $this->realEstate->anzahlZimmer;
}

$arrColumns[] = "$t.anzahlZimmer>=?";
$arrValues[] = floor($roomFrom - ($roomFrom * ($this->filterCoarse / 100))) > 0 ?: 0;
if($roomFrom)
{
$arrColumns[] = "$t.anzahlZimmer>=?";
$arrValues[] = floor($roomFrom - ($roomFrom * ($this->filterCoarse / 100))) > 0 ?: 0;
}

if ($_SESSION['FILTER_DATA']['room_to'])
{
$roomTo = intval($_SESSION['FILTER_DATA']['room_to']);
}
else
elseif($this->realEstate->anzahlZimmer)
{
$roomTo = $this->realEstate->anzahlZimmer;
}
$arrColumns[] = "$t.anzahlZimmer<=?";
$arrValues[] = ceil($roomTo + ($roomTo * ($this->filterCoarse / 100)));

if($roomTo)
{
$arrColumns[] = "$t.anzahlZimmer<=?";
$arrValues[] = ceil($roomTo + ($roomTo * ($this->filterCoarse / 100)));
}

if ($_SESSION['FILTER_DATA']['area_from'])
{
$areaFrom = intval($_SESSION['FILTER_DATA']['area_from']);
}
else
elseif($this->realEstate->{$objType->area})
{
$areaFrom = $this->realEstate->{$objType->area};
$areaFrom = $this->realEstate->{$objType->area};
}

if($areaFrom)
{
$arrColumns[] = "$t.".$objType->area.">=?";
$arrValues[] = ($areaFrom - ($areaFrom * ($this->filterCoarse / 100))) > 0 ?: 0;
}
$arrColumns[] = "$t.".$objType->area.">=?";
$arrValues[] = ($areaFrom - ($areaFrom * ($this->filterCoarse / 100))) > 0 ?: 0;

if ($_SESSION['FILTER_DATA']['area_to'])
{
$areaTo = intval($_SESSION['FILTER_DATA']['area_to']);
}
else
elseif($this->realEstate->{$objType->area})
{
$areaTo = $this->realEstate->{$objType->area};
}
$arrColumns[] = "$t.".$objType->area."<=?";
$arrValues[] = floor($areaTo + ($areaTo * ($this->filterCoarse / 100)));

$arrColumns[] = "(6371*acos(cos(radians(?))*cos(radians($t.breitengrad))*cos(radians($t.laengengrad)-radians(?))+sin(radians(?))*sin(radians($t.breitengrad)))) <= ?";
$arrValues[] = $this->realEstate->breitengrad;
$arrValues[] = $this->realEstate->laengengrad;
$arrValues[] = $this->realEstate->breitengrad;
$arrValues[] = $this->similarDistance;

if($areaTo)
{
$arrColumns[] = "$t.".$objType->area."<=?";
$arrValues[] = floor($areaTo + ($areaTo * ($this->filterCoarse / 100)));
}

if($this->similarDistance > 0)
{
$arrColumns[] = "(6371*acos(cos(radians(?))*cos(radians($t.breitengrad))*cos(radians($t.laengengrad)-radians(?))+sin(radians(?))*sin(radians($t.breitengrad)))) <= ?";
$arrValues[] = $this->realEstate->breitengrad;
$arrValues[] = $this->realEstate->laengengrad;
$arrValues[] = $this->realEstate->breitengrad;
$arrValues[] = $this->similarDistance;
}

// HOOK: custom filter
if (isset($GLOBALS['TL_HOOKS']['getSimilarFilterOptions']) && \is_array($GLOBALS['TL_HOOKS']['getSimilarFilterOptions']))
Expand Down

0 comments on commit fd8efa0

Please sign in to comment.