From e6eea8088d86593e4bc18be1b4b672ea0ec25641 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Wed, 30 Sep 2020 18:57:36 +0300 Subject: [PATCH] #1760 [core] Listing show parameters --- .../visiosoft/advs-module/composer.json | 3 + .../advs-module/resources/css/list.css | 4 + .../advs-module/resources/lang/en/field.php | 9 +- .../advs-module/src/Adv/AdvRepository.php | 40 ++-- .../src/Http/Controller/advsController.php | 201 ++++++++---------- .../visiosoft/advs-module/src/helpers.php | 8 + 6 files changed, 127 insertions(+), 138 deletions(-) create mode 100644 addons/default/visiosoft/advs-module/src/helpers.php diff --git a/addons/default/visiosoft/advs-module/composer.json b/addons/default/visiosoft/advs-module/composer.json index 53cd02315..4f132dd3e 100644 --- a/addons/default/visiosoft/advs-module/composer.json +++ b/addons/default/visiosoft/advs-module/composer.json @@ -2,6 +2,9 @@ "name": "visiosoft/advs-module", "type": "streams-addon", "autoload": { + "files": [ + "src/helpers.php" + ], "psr-4": { "Visiosoft\\AdvsModule\\": "src/" } diff --git a/addons/default/visiosoft/advs-module/resources/css/list.css b/addons/default/visiosoft/advs-module/resources/css/list.css index e7df1d293..106d931be 100644 --- a/addons/default/visiosoft/advs-module/resources/css/list.css +++ b/addons/default/visiosoft/advs-module/resources/css/list.css @@ -164,6 +164,10 @@ border-radius: 2px; } +.result-text .filter-tabs a button:focus { + outline: none; +} + .result-text .filter-tabs a svg { flex-shrink: 0; height: 6px; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/field.php b/addons/default/visiosoft/advs-module/resources/lang/en/field.php index 2d09d304e..6fde4408d 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/field.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/field.php @@ -248,6 +248,9 @@ return [ 'in_the_last_24_hours' => [ 'name' => 'In The Last 24 Hours' ], + 'in_the_last_day' => [ + 'name' => 'In The Last 24 Hours' + ], 'in_the_last_week' => [ 'name' => 'In The Last Week' ], @@ -297,5 +300,9 @@ return [ // New create page 'options' => 'Options', - 'free' => 'Free' + 'free' => 'Free', + 'ad_date' => 'Ad Date', + 'photo_video' => 'Photo, Video', + 'and_above' => 'and above', + 'and_below' => 'and below', ]; diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 93afdb38f..e39e5580a 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -100,17 +100,19 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface if (!empty($param['user'])) { $query = $query->where('advs_advs.created_by_id', $param['user']); } - if (!empty($param['min_price'])) { - $num = $param['min_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') >=" . $int; - $query = $query->whereRaw($column); - } - if (!empty($param['max_price'])) { - $num = $param['max_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') <=" . $int; - $query = $query->whereRaw($column); + if (!empty($param['currency'])) { + if (!empty($param['min_price'])) { + $num = $param['min_price']; + $int = (int)$num; + $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') >=" . $int; + $query = $query->whereRaw($column); + } + if (!empty($param['max_price'])) { + $num = $param['max_price']; + $int = (int)$num; + $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') <=" . $int; + $query = $query->whereRaw($column); + } } if (!empty($param['date'])) { if ($param['date'] === 'day') { @@ -147,22 +149,6 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface $query = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->filterSearch($customParameters, $param, $query); } - - if (!empty($param['max_price'])) { - $num = $param['max_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') <=" . $int; - $query = $query->whereRaw($column); - } - - if (!empty($param['max_price'])) { - $num = $param['max_price']; - $int = (int)$num; - $column = "JSON_EXTRACT(foreign_currencies, '$." . $param['currency'] . "') <=" . $int; - $query = $query->whereRaw($column); - } - - // //UPDATE `default_advs_advs` SET `coor` = (PointFromText('POINT(41.085022 28.804754)')) WHERE `default_advs_advs`.`id` = 8 // //SELECT * FROM `default_advs_advs` WHERE ST_DISTANCE(ST_GeomFromText('POINT(41.0709052 28.829627)'), coor) < 20 diff --git a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php index 47efea43c..e153a7e91 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -11,7 +11,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cookie; use Visiosoft\AdvsModule\Adv\AdvModel; -use Visiosoft\AdvsModule\Adv\Command\appendRequestURL; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd; use Visiosoft\AdvsModule\Adv\Event\CreatedAd; @@ -24,8 +23,6 @@ use Visiosoft\AlgoliaModule\Search\SearchModel; use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CloudinaryModule\Video\VideoModel; -use Visiosoft\CustomfieldsModule\CustomField\Contract\CustomFieldRepositoryInterface; -use Visiosoft\CustomfieldsModule\CustomField\CustomFieldModel; use Visiosoft\FavsModule\Http\Controller\FavsController; use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityRepository; @@ -63,11 +60,6 @@ class AdvsController extends PublicController private $optionRepository; - - - - private $customFieldRepository; - public function __construct( UserRepositoryInterface $userRepository, @@ -94,10 +86,7 @@ class AdvsController extends PublicController Dispatcher $events, - Request $request, - - - CustomFieldRepositoryInterface $customFieldRepository + Request $request ) { $this->userRepository = $userRepository; @@ -125,9 +114,8 @@ class AdvsController extends PublicController $this->requestHttp = $request; - parent::__construct(); $this->optionRepository = $optionRepository; - $this->customFieldRepository = $customFieldRepository; + parent::__construct(); } @@ -156,10 +144,9 @@ class AdvsController extends PublicController } if (isset($param['cat'])) { unset($param['cat']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug]), - array() + route('adv_list_seo', [$categoryId->slug]) )); } } elseif (isset($param['cat']) && !empty($param['cat'])) { // Only Param @@ -169,10 +156,9 @@ class AdvsController extends PublicController return redirect('/'); } unset($param['cat']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug]), - array() + route('adv_list_seo', [$categoryId->slug]) )); } @@ -189,23 +175,21 @@ class AdvsController extends PublicController if (is_null($city) && $isOneCity) { // Param and no slug $cityId = $this->cityRepository->find($param['city'][0]); unset($param['city']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug, $cityId->slug]), - array() + route('adv_list_seo', [$categoryId->slug, $cityId->slug]) )); } elseif ($isOneCity) { // Param and slug $cityId = $this->cityRepository->find($param['city'][0]); if ($city !== $cityId->slug) { unset($param['city']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug, $cityId->slug]), - array() + route('adv_list_seo', [$categoryId->slug, $cityId->slug]) )); } } elseif ($city && $isMultipleCity) { // Slug and multiple param cities - return redirect($this->fullLink( + return redirect(fullLink( $param, route('adv_list_seo', [$categoryId->slug]), array() @@ -213,18 +197,16 @@ class AdvsController extends PublicController } elseif ($city) { if (isset($param['city'][0]) && empty($param['city'][0])) { // Slug and empty param unset($param['city']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug]), - array() + route('adv_list_seo', [$categoryId->slug]) )); } else { // Only slug $cityId = $this->cityRepository->findBy('slug', $city); if (!$cityId) { - return redirect($this->fullLink( + return redirect(fullLink( $param, - route('adv_list_seo', [$categoryId->slug]), - array() + route('adv_list_seo', [$categoryId->slug]) ), 301); } } @@ -247,10 +229,9 @@ class AdvsController extends PublicController if ($advs->currentPage() > $advs->lastPage()) { unset($param['page']); - return redirect($this->fullLink( + return redirect(fullLink( $param, - \request()->url(), - array() + \request()->url() ), 301); } @@ -292,6 +273,7 @@ class AdvsController extends PublicController $allCats = true; } + $cFArray = array(); if ($isActiveCustomFields) { $returnvalues = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->index($mainCats, $subCats); $checkboxes = $returnvalues['checkboxes']; @@ -302,75 +284,81 @@ class AdvsController extends PublicController $ranges = $returnvalues['ranges']; $radio = $returnvalues['radio']; - $customFieldParameters = array_filter($param, function ($var) { - return strpos($var, 'cf_') === 0 - || strpos($var, 'min_cf_') === 0 - || strpos($var, 'max_cf_') === 0; - }, ARRAY_FILTER_USE_KEY); + $cFArray = app('Visiosoft\CustomfieldsModule\CustomField\Contract\CustomFieldRepositoryInterface') + ->getCFParamValues($param); + } - $cFArray = array(); - foreach ($customFieldParameters as $id => $value) { - if (strpos($id, 'min_cf_') === 0 || strpos($id, 'max_cf_') === 0) { - $cFId = substr($id, 7); - $cF = $this->customFieldRepository->newQuery()->find($cFId); - $keyExists = array_key_exists($cFId, $cFArray); - if (strpos($id, 'min_cf_') === 0) { - if ($keyExists) { - $cFArray[$cFId] = [ - 'name' => $cFArray[$cFId]['name'], - 'value' => [ - 'min' => $value, - 'max' => $cFArray[$cFId]['value']['max'], - ] - ]; - } else { - $cFArray[$cFId] = [ - 'name' => $cF->name, - 'value' => [ - 'min' => $value, - ] - ]; - } - } else { - if ($keyExists) { - $cFArray[$cFId] = [ - 'name' => $cFArray[$cFId]['name'], - 'value' => [ - 'min' => $cFArray[$cFId]['value']['min'], - 'max' => $value, - ] - ]; - } else { - $cFArray[$cFId] = [ - 'name' => $cF->name, - 'value' => [ - 'max' => $value, - ] - ]; - } - } - } elseif (strpos($id, 'cf_') === 0) { - $cFId = substr($id, 3); - $cF = $this->customFieldRepository->newQuery()->find($cFId); - if ($cF->type === 'radio' || $cF->type === 'selecttop') { - $cFArray[$cFId] = [ - 'name' => $cF->name, - 'value' => reset($value) - ]; - } elseif ($cF->type === 'selectdropdown') { - $cFArray[$cFId] = [ - 'name' => $cF->name, - 'value' => $value - ]; - } elseif ($cF->type === 'select') { - $cFArray[$cFId] = [ - 'name' => $cF->name, - 'value' => $value - ]; - } + $photoVideoParams = ['photo', 'video']; + $photoExists = false; + foreach ($photoVideoParams as $pV) { + if (\request()->{$pV} === 'true') { + $removalLink = array_filter($param, function ($singleParam) use ($pV) { + return $singleParam !== $pV; + }, ARRAY_FILTER_USE_KEY); + $removalLink = fullLink($removalLink, \request()->url()); + + if ($photoExists) { + $cFArray['photoVideo']['value'][] = [ + 'name' => trans('visiosoft.module.advs::field.ads_with_' . $pV . '.name'), + 'removalLink' => $removalLink + ]; + } else { + $cFArray['photoVideo'] = [ + 'name' => trans('visiosoft.module.advs::field.photo_video'), + 'value' => [ + [ + 'name' => trans('visiosoft.module.advs::field.ads_with_' . $pV . '.name'), + 'removalLink' => $removalLink + ] + ] + ]; + $photoExists = true; } } - dd($cFArray); + } + + if ($dateParam = \request()->date) { + $removalLink = array_filter($param, function ($singleParam) { + return $singleParam !== 'date'; + }, ARRAY_FILTER_USE_KEY); + $removalLink = fullLink($removalLink, \request()->url()); + + $cFArray[] = [ + 'name' => trans('visiosoft.module.advs::field.ad_date'), + 'value' => [ + [ + 'name' => trans('visiosoft.module.advs::field.in_the_last_' . $dateParam . '.name'), + 'removalLink' => $removalLink + ] + ] + ]; + } + + $minPrice = \request()->min_price; + $maxPrice = \request()->max_price; + if ($minPrice || $maxPrice) { + $removalLink = array_filter($param, function ($singleParam) { + return $singleParam !== 'min_price' && $singleParam !== 'max_price' && $singleParam !== 'currency'; + }, ARRAY_FILTER_USE_KEY); + $removalLink = fullLink($removalLink, \request()->url()); + + if ($minPrice && $maxPrice) { + $name = "$minPrice - $maxPrice"; + } elseif ($minPrice) { + $name = "$minPrice " . trans('visiosoft.module.advs::field.and_above'); + } elseif ($maxPrice) { + $name = "$maxPrice " . trans('visiosoft.module.advs::field.and_below'); + } + + $cFArray[] = [ + 'name' => trans('visiosoft.module.advs::field.price.name'), + 'value' => [ + [ + 'name' => $name, + 'removalLink' => $removalLink + ] + ] + ]; } Cookie::queue(Cookie::make('last_search', $this->requestHttp->getRequestUri(), 84000)); @@ -408,18 +396,11 @@ class AdvsController extends PublicController $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'param', 'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges', - 'seenList', 'radio', 'categoryId', 'cityId', 'allCats', 'catText'); - -// dd($checkboxes, $radio, $param, $returnvalues , $topfields , $selectDropdown , $selectRange , $selectImage , $ranges); + 'seenList', 'radio', 'categoryId', 'cityId', 'allCats', 'catText', 'cFArray'); return $this->viewTypeBasedRedirect($viewType, $compact); } - public function fullLink($request, $url, $newParameters) - { - return $this->dispatch(new appendRequestURL($request, $url, $newParameters)); - } - public function viewTypeBasedRedirect($viewType, $compact) { if (!$viewType) { diff --git a/addons/default/visiosoft/advs-module/src/helpers.php b/addons/default/visiosoft/advs-module/src/helpers.php new file mode 100644 index 000000000..05ca84938 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/helpers.php @@ -0,0 +1,8 @@ +dispatch(new appendRequestURL($request, $url, $newParameters)); +} \ No newline at end of file