#1079 [Sahibinden-Theme] Edit ad url

This commit is contained in:
Diatrex 2020-03-20 14:07:33 +03:00
parent 7bfa132604
commit c4d63a8971
8 changed files with 93 additions and 64 deletions

View File

@ -1,20 +1,19 @@
{% set formHtml %}
<form action="{{ url_route('visiosoft.module.advs::list') }}" method="get">
{% 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 %}
<form action="{{ url_route('adv_list_seo', [catId.slug, cityId.slug]) }}" method="get">
{% 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 %}
<form action="{{ url_route('adv_list_seo', [catSlug, citySlug]) }}" method="get">
{% endset %}
{% endif %}
{{ formHtml }}
<div class="row">
@ -36,7 +35,9 @@
'districts':districts,
'neighborhoods':neighborhoods,
'villages':villages,
'param':param
'param':param,
'categoryId':categoryId,
'cityId':cityId
})|raw }}
<!-- Price Filter Start -->

View File

@ -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'])) {

View File

@ -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);

View File

@ -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);
}

View File

@ -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 %}
<li class="breadcrumb-item">
<a href="{{ url_route('visiosoft.module.advs::list_cat', [category_breadcrumbs['id']]) }}"

View File

@ -9,30 +9,27 @@
</h5>
</div>
<div id="category" class="collapse show overflow-auto" aria-labelledby="categoryHeading"
data-parent="#filter"
style="max-height: 300px;">
data-parent="#filter" style="max-height: 300px;">
<div class="list-group">
{% 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 %}
<a href="{% if(viewType != "map") %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [catId.slug, cityId.slug]),{}) }}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [catId.slug, citySlug]),{}) }}
{% else %}
{{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':id}) }}
{% endif %}" class="list-group-item list-group-item-action text-truncate">
@ -44,7 +41,7 @@
{% if subcat.parent_category_id == maincat['id'] %}
{% set subCatId = entries('cats', 'category').find(subcat.id) %}
<a href="{% if(viewType != "map") %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [subCatId.slug, cityId.slug]),{}) }}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [subCatId.slug, citySlug]),{}) }}
{% else %}
{{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':subcat.id}) }}
{% endif %}" class="list-group-item list-group-item-action text-truncate">

View File

@ -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();

View File

@ -18,15 +18,28 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.city.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
{% 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 %}
<div class="text-muted selected-city">
<small>{{ selected_cities_name|join(',') }}</small>
</div>
<input name="city[]" value="{{ params.param['city']|join(',') }}" type="hidden">
<input name="city[]" value="
{% if citySlug %}
{{ citySlug.id }}
{% else %}
{{ params.param['city']|join(',') }}
{% endif %}
" type="hidden">
</div>
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-district-btn" data-toggle="modal"