From c4d63a897130fc07e0285c36925ed27ae7773c42 Mon Sep 17 00:00:00 2001 From: Diatrex Date: Fri, 20 Mar 2020 14:07:33 +0300 Subject: [PATCH] #1079 [Sahibinden-Theme] Edit ad url --- .../views/list/partials/list-filter.twig | 31 ++++++------ .../advs-module/src/Adv/AdvRepository.php | 17 +++---- .../Adv/Contract/AdvRepositoryInterface.php | 2 +- .../src/Http/Controller/advsController.php | 48 ++++++++++++------- .../views/ads-list/partials/breadcrumb.twig | 7 ++- .../views/ads-list/partials/list-filter.twig | 19 ++++---- .../resources/js/filterLocation.js | 8 ++-- .../ads-list/partials/location-fields.twig | 25 +++++++--- 8 files changed, 93 insertions(+), 64 deletions(-) diff --git a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig index 588db4357..0fbb72a18 100644 --- a/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig +++ b/addons/default/visiosoft/advs-module/resources/views/list/partials/list-filter.twig @@ -1,20 +1,19 @@ {% set formHtml %}
{% endset %} -{% if 'cat' in param|keys %} - {% if not param['cat'] is empty %} - {% set catId = entries('cats', 'category').find(param['cat']) %} - {% set cityId = null %} - {% if 'city' in param|keys %} - {% set citiesArray = param['city'][0]|split(',') %} - {% if count(citiesArray) is same as(1) %} - {% set cityId = entries('location', 'cities').find(param['city'][0]) %} - {% endif %} - {% endif %} - {% set formHtml %} - - {% endset %} - {% endif %} +{% set catSlug = null %} +{% set citySlug = null %} +{% set pathInfo = app.request.pathinfo|split('/') %} +{% if pathInfo[1] == 'c' %} + {% set catSlug = pathInfo[2] %} +{% endif %} +{% if pathInfo|length is same as(4) %} + {% set citySlug = pathInfo[3] %} +{% endif %} +{% if catSlug %} + {% set formHtml %} + + {% endset %} {% endif %} {{ formHtml }}
@@ -36,7 +35,9 @@ 'districts':districts, 'neighborhoods':neighborhoods, 'villages':villages, - 'param':param + 'param':param, + 'categoryId':categoryId, + 'cityId':cityId })|raw }} diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 50f7aac4c..5d50576d3 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -46,7 +46,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface return $this->model->orderBy('created_at', 'DESC')->where('advs_advs.id', $id)->first(); } - public function searchAdvs($type, $param = null, $customParameters = null, $limit = null) + public function searchAdvs($type, $param = null, $customParameters = null, $limit = null, $category = null, $city = null) { $isActiveDopings = new AdvModel(); $isActiveDopings = $isActiveDopings->is_enabled('dopings'); @@ -78,20 +78,21 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface if (!empty($param['country'])) { $query = $query->where('country_id', $param['country']); } - if (isset($param['city']) and !empty($param['city']) and !empty(array_filter($param['city']))) { + if ($city) { + $query = $query->where('city', $city->id); + } elseif (isset($param['city']) and !empty($param['city']) and !empty(array_filter($param['city']))) { $query = $query->whereIn('city', $param['city']); } - if (!empty($param['cat'])) { + if ($category) { $cat = new CategoryModel(); - $cat_d = $cat->find($param['cat']); - if ($cat_d) { - if ($cat_d->parent_category_id == null) { + if ($category) { + if ($category->parent_category_id == null) { $catLevel = 1; } else { - $catLevel = $cat->getCatLevel($param['cat']); + $catLevel = $cat->getCatLevel($category->id); } $catLevel = "cat" . $catLevel; - $query = $query->where($catLevel, $param['cat']); + $query = $query->where($catLevel, $category->id); } } if (!empty($param['user'])) { diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php index a3b32d0ad..5b4309af8 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -6,7 +6,7 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface { public function findById($id); - public function searchAdvs($type, $param = null, $customParameters = null, $limit = null); + public function searchAdvs($type, $param = null, $customParameters = null, $limit = null, $category = null, $city = null); public function softDeleteAdv($id); 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 4a4d018fe..59f07811a 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -151,29 +151,41 @@ class AdvsController extends PublicController $isActiveDopings = $this->adv_model->is_enabled('dopings'); // Search by category slug + $categoryId = null; if ($category) { $categoryId = $this->category_repository->findBy('slug', $category); - if ($categoryId) { - $param['cat'] = $categoryId->id; + if (!$categoryId) { + $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist')); + return redirect('/'); } - } elseif (isset($param['cat']) && !empty($param['cat'])) { - $categoryId = $this->category_repository->find($param['cat']); - if ($categoryId) { + if (isset($param['cat'])) { + unset($param['cat']); return redirect($this->fullLink( $param, route('adv_list_seo', [$categoryId->slug]), array() )); - } else { + } + } elseif (isset($param['cat']) && !empty($param['cat'])) { + $categoryId = $this->category_repository->find($param['cat']); + if (!$categoryId) { $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist')); return redirect('/'); } + unset($param['cat']); + return redirect($this->fullLink( + $param, + route('adv_list_seo', [$categoryId->slug]), + array() + )); } // Search by city slug + $cityId = null; if ($category) { if (is_null($city) && isset($param['city'][0]) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { $cityId = $this->cityRepository->find($param['city'][0]); + unset($param['city']); return redirect($this->fullLink( $param, route('adv_list_seo', [$categoryId->slug, $cityId->slug]), @@ -182,6 +194,7 @@ class AdvsController extends PublicController } elseif (isset($param['city']) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { $cityId = $this->cityRepository->find($param['city'][0]); if ($city !== $cityId->slug) { + unset($param['city']); return redirect($this->fullLink( $param, route('adv_list_seo', [$categoryId->slug, $cityId->slug]), @@ -196,6 +209,7 @@ class AdvsController extends PublicController )); } elseif ($city) { if (isset($param['city'][0]) && empty($param['city'][0])) { + unset($param['city']); return redirect($this->fullLink( $param, route('adv_list_seo', [$categoryId->slug]), @@ -203,14 +217,13 @@ class AdvsController extends PublicController )); } else { $cityId = $this->cityRepository->findBy('slug', $city); - $param['city'] = [$cityId->id]; } } } $isActiveCustomFields = $this->adv_model->is_enabled('customfields'); - $advs = $this->adv_repository->searchAdvs('list', $param, $customParameters); + $advs = $this->adv_repository->searchAdvs('list', $param, $customParameters, null, $categoryId, $cityId); $advs = $this->adv_repository->addAttributes($advs); @@ -231,25 +244,23 @@ class AdvsController extends PublicController } - if (isset($param['cat']) and $param['cat'] != "") { - $cat = $param['cat']; - $seo_keywords = $this->category_model->getMeta_keywords($param['cat']); - $seo_description = $this->category_model->getMeta_description($param['cat']); - $seo_title = $this->category_model->getMeta_title($param['cat']); + if ($categoryId) { + $seo_keywords = $this->category_model->getMeta_keywords($categoryId->id); + $seo_description = $this->category_model->getMeta_description($categoryId->id); + $seo_title = $this->category_model->getMeta_title($categoryId->id); $this->template->set('meta_keywords', implode(',', $seo_keywords)); $this->template->set('meta_description', $seo_description); $this->template->set('meta_title', $seo_title); - $mainCats = $this->category_model->getMains($cat); - $current_cat = $this->category_model->getCat($cat); + $mainCats = $this->category_model->getMains($categoryId->id); + $current_cat = $this->category_model->getCat($categoryId->id); $mainCats[] = [ 'id' => $current_cat->id, 'val' => $current_cat->name, ]; - $subCats = $this->category_repository->getSubCatById($cat); + $subCats = $this->category_repository->getSubCatById($categoryId->id); } else { - $cat = null; $mainCats = $this->category_repository->mainCats(); } @@ -270,7 +281,8 @@ class AdvsController extends PublicController $viewType = $this->requestHttp->cookie('viewType'); $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', 'param', - 'user', 'featured_advs', 'viewType', 'topfields', 'ranges', 'seenList', 'searchedCountry', 'radio'); + 'user', 'featured_advs', 'viewType', 'topfields', 'ranges', 'seenList', 'searchedCountry', 'radio', + 'categoryId', 'cityId'); return $this->viewTypeBasedRedirect($viewType, $compact); } diff --git a/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/breadcrumb.twig b/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/breadcrumb.twig index 2f40e67f9..99ade293e 100644 --- a/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/breadcrumb.twig +++ b/addons/default/visiosoft/cats-module/resources/views/ads-list/partials/breadcrumb.twig @@ -1,4 +1,9 @@ -{% if app.request.get('cat') %} +{% set catSlug = null %} +{% set pathInfo = app.request.pathinfo|split('/') %} +{% if pathInfo[1] == 'c' %} + {% set catSlug = pathInfo[2] %} +{% endif %} +{% if catSlug %} {% for category_breadcrumbs in params.mainCats %}
+ data-parent="#filter" style="max-height: 300px;">
{% for maincat in params.mainCats %} {% set name = maincat['val'] %} {% set id = maincat['id'] %} {% set parent_category = true %} {% if app.request.get('cat') is null or app.request.get('cat') == "" %} - {% if params.param['cat'] is null or params.param['cat'] == "" %} + {% if params.categoryId is null %} {% set name = maincat.name %} {% set id = maincat.id %} {% set parent_category = false %} {% endif %} {% endif %} {% set catId = entries('cats', 'category').find(id) %} - {% set cityId = null %} - {% if 'city' in params.param|keys %} - {% set citiesArray = params.param['city'][0]|split(',') %} - {% if count(citiesArray) is same as(1) %} - {% set cityId = entries('location', 'cities').find(params.param['city'][0]) %} - {% endif %} + {% set citySlug = null %} + {% set pathInfo = app.request.pathinfo|split('/') %} + {% if pathInfo|length is same as(4) %} + {% set citySlug = pathInfo[3] %} {% endif %} @@ -44,7 +41,7 @@ {% if subcat.parent_category_id == maincat['id'] %} {% set subCatId = entries('cats', 'category').find(subcat.id) %} diff --git a/addons/default/visiosoft/location-module/resources/js/filterLocation.js b/addons/default/visiosoft/location-module/resources/js/filterLocation.js index 543c27474..880aa297b 100644 --- a/addons/default/visiosoft/location-module/resources/js/filterLocation.js +++ b/addons/default/visiosoft/location-module/resources/js/filterLocation.js @@ -37,7 +37,7 @@ $('.filter-city-btn').on('click', function () { var countries_value = $('input[name="country"]').val(); var selected__city_request = $('input[name="city[]"]').val(); if (cities == undefined || $(this).attr('data-parent') != countries_value) { - $(this).attr('data-parent', countries_value) + $(this).attr('data-parent', countries_value); var promiseForCities = new Promise(function (resolve, reject) { locationCrud('id=' + countries_value, '/ajax/getCities', 'POST', beforeSend(), function (callback) { cities = callback; @@ -45,11 +45,11 @@ $('.filter-city-btn').on('click', function () { $.each(cities, function (index, value) { $('.filter-location-modal .cities').append(item('city', value.id, value.name)); }); - if (cities == "") + if (cities == "") { $('.filter-location-modal .cities').html(null_msg); - else if (selected__city_request != "") { + } else if (selected__city_request != "") { $.each(selected__city_request.split(','), function (index, value) { - $(".filter-location-body .cities li[data-id='" + value + "'] input[type='checkbox']").prop('checked', true); + $(".filter-location-body .cities li[data-id='" + value.trim() + "'] input[type='checkbox']").prop('checked', true); }); } resolve(); diff --git a/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig index 5f6910264..b93d6a2b9 100644 --- a/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig +++ b/addons/default/visiosoft/location-module/resources/views/ads-list/partials/location-fields.twig @@ -18,15 +18,28 @@ {{ trans("visiosoft.module.location::field.city.name") }} - {% set selected_cities = params.param['city'] %} - {% set selected_cities_name = [] %} - {% for selected_city in selected_cities[0]|split(',') %} - {% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %} - {% endfor %} + {% set citySlug = null %} + {% set pathInfo = app.request.pathinfo|split('/') %} + {% if pathInfo|length is same as(4) %} + {% set citySlug = entries('location', 'cities').findBy('slug', pathInfo[3]) %} + {% set selected_cities_name = [getCity(citySlug.id).name] %} + {% else %} + {% set selected_cities = params.param['city'] %} + {% set selected_cities_name = [] %} + {% for selected_city in selected_cities[0]|split(',') %} + {% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %} + {% endfor %} + {% endif %}
{{ selected_cities_name|join(',') }}
- +