Merge pull request #440 from openclassify/dia

#1079 #1111 #929
This commit is contained in:
Fatih Alp 2020-03-20 19:47:20 +03:00 committed by GitHub
commit c27840b066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 126 additions and 80 deletions

View File

@ -1,20 +1,19 @@
{% set formHtml %} {% set formHtml %}
<form action="{{ url_route('visiosoft.module.advs::list') }}" method="get"> <form action="{{ url_route('visiosoft.module.advs::list') }}" method="get">
{% endset %} {% endset %}
{% if 'cat' in param|keys %} {% set catSlug = null %}
{% if not param['cat'] is empty %} {% set citySlug = null %}
{% set catId = entries('cats', 'category').find(param['cat']) %} {% set pathInfo = app.request.pathinfo|split('/') %}
{% set cityId = null %} {% if pathInfo[1] == 'c' %}
{% if 'city' in param|keys %} {% set catSlug = pathInfo[2] %}
{% set citiesArray = param['city'][0]|split(',') %} {% endif %}
{% if count(citiesArray) is same as(1) %} {% if pathInfo|length is same as(4) %}
{% set cityId = entries('location', 'cities').find(param['city'][0]) %} {% set citySlug = pathInfo[3] %}
{% endif %} {% endif %}
{% endif %} {% if catSlug %}
{% set formHtml %} {% set formHtml %}
<form action="{{ url_route('adv_list_seo', [catId.slug, cityId.slug]) }}" method="get"> <form action="{{ url_route('adv_list_seo', [catSlug, citySlug]) }}" method="get">
{% endset %} {% endset %}
{% endif %}
{% endif %} {% endif %}
{{ formHtml }} {{ formHtml }}
<div class="row"> <div class="row">
@ -36,7 +35,9 @@
'districts':districts, 'districts':districts,
'neighborhoods':neighborhoods, 'neighborhoods':neighborhoods,
'villages':villages, 'villages':villages,
'param':param 'param':param,
'categoryId':categoryId,
'cityId':cityId
})|raw }} })|raw }}
<!-- Price Filter Start --> <!-- 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(); 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 = new AdvModel();
$isActiveDopings = $isActiveDopings->is_enabled('dopings'); $isActiveDopings = $isActiveDopings->is_enabled('dopings');
@ -78,20 +78,21 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
if (!empty($param['country'])) { if (!empty($param['country'])) {
$query = $query->where('country_id', $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']); $query = $query->whereIn('city', $param['city']);
} }
if (!empty($param['cat'])) { if ($category) {
$cat = new CategoryModel(); $cat = new CategoryModel();
$cat_d = $cat->find($param['cat']); if ($category) {
if ($cat_d) { if ($category->parent_category_id == null) {
if ($cat_d->parent_category_id == null) {
$catLevel = 1; $catLevel = 1;
} else { } else {
$catLevel = $cat->getCatLevel($param['cat']); $catLevel = $cat->getCatLevel($category->id);
} }
$catLevel = "cat" . $catLevel; $catLevel = "cat" . $catLevel;
$query = $query->where($catLevel, $param['cat']); $query = $query->where($catLevel, $category->id);
} }
} }
if (!empty($param['user'])) { if (!empty($param['user'])) {

View File

@ -6,7 +6,7 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
{ {
public function findById($id); 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); public function softDeleteAdv($id);

View File

@ -207,7 +207,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
], ],
'ajax/getAds' => [ 'ajax/getAdvs' => [
'as' => 'ajax::getAds', 'as' => 'ajax::getAds',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AjaxController@getMyAds' 'uses' => 'Visiosoft\AdvsModule\Http\Controller\AjaxController@getMyAds'
], ],

View File

@ -151,69 +151,87 @@ class AdvsController extends PublicController
$isActiveDopings = $this->adv_model->is_enabled('dopings'); $isActiveDopings = $this->adv_model->is_enabled('dopings');
// Search by category slug // Search by category slug
if ($category) { $categoryId = null;
if ($category) { // Slug
$categoryId = $this->category_repository->findBy('slug', $category); $categoryId = $this->category_repository->findBy('slug', $category);
if ($categoryId) { if (!$categoryId) {
$param['cat'] = $categoryId->id; $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/');
} }
} elseif (isset($param['cat']) && !empty($param['cat'])) { if (isset($param['cat'])) {
$categoryId = $this->category_repository->find($param['cat']); unset($param['cat']);
if ($categoryId) {
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$categoryId->slug]),
array() array()
)); ));
} else { }
} elseif (isset($param['cat']) && !empty($param['cat'])) { // Only Param
$categoryId = $this->category_repository->find($param['cat']);
if (!$categoryId) {
$this->messages->error(trans('visiosoft.module.advs::message.category_not_exist')); $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/'); return redirect('/');
} }
unset($param['cat']);
return redirect($this->fullLink(
$param,
route('adv_list_seo', [$categoryId->slug]),
array()
));
} }
// Search by city slug // Search by city slug
$cityId = null;
if ($category) { if ($category) {
if (is_null($city) && isset($param['city'][0]) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { $isOneCity = isset($param['city'][0])
&& !empty($param['city'][0])
&& strpos($param['city'][0], ',') === false;
$isMultipleCity = isset($param['city'][0])
&& !empty($param['city'][0])
&& strpos($param['city'][0], ',') !== false;
if (is_null($city) && $isOneCity) { // Param and no slug
$cityId = $this->cityRepository->find($param['city'][0]); $cityId = $this->cityRepository->find($param['city'][0]);
unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug]), route('adv_list_seo', [$categoryId->slug, $cityId->slug]),
array() array()
)); ));
} elseif (isset($param['city']) && !empty($param['city'][0]) && strpos($param['city'][0], ',') === false) { } elseif ($isOneCity) { // Param and slug
$cityId = $this->cityRepository->find($param['city'][0]); $cityId = $this->cityRepository->find($param['city'][0]);
if ($city !== $cityId->slug) { if ($city !== $cityId->slug) {
unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug]), route('adv_list_seo', [$categoryId->slug, $cityId->slug]),
array() array()
)); ));
} }
} elseif ($city && isset($param['city'][0]) && !empty($param['city'][0]) && strpos($param['city'][0], ',') !== false) { } elseif ($city && $isMultipleCity) { // Slug and multiple param cities
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$categoryId->slug]),
array() array()
)); ));
} elseif ($city) { } elseif ($city) {
if (isset($param['city'][0]) && empty($param['city'][0])) { if (isset($param['city'][0]) && empty($param['city'][0])) { // Slug and empty param
unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$categoryId->slug]),
array() array()
)); ));
} else { } else { // Only slug
$cityId = $this->cityRepository->findBy('slug', $city); $cityId = $this->cityRepository->findBy('slug', $city);
$param['city'] = [$cityId->id];
} }
} }
} }
$isActiveCustomFields = $this->adv_model->is_enabled('customfields'); $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); $advs = $this->adv_repository->addAttributes($advs);
if ($isActiveDopings and $param != null) { if ($isActiveDopings and $param != null) {
$featured_advs = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->listFeatures($advs); $featured_advs = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->listFeatures($advs);
} }
@ -231,25 +249,23 @@ class AdvsController extends PublicController
} }
if (isset($param['cat']) and $param['cat'] != "") { if ($categoryId) {
$cat = $param['cat']; $seo_keywords = $this->category_model->getMeta_keywords($categoryId->id);
$seo_keywords = $this->category_model->getMeta_keywords($param['cat']); $seo_description = $this->category_model->getMeta_description($categoryId->id);
$seo_description = $this->category_model->getMeta_description($param['cat']); $seo_title = $this->category_model->getMeta_title($categoryId->id);
$seo_title = $this->category_model->getMeta_title($param['cat']);
$this->template->set('meta_keywords', implode(',', $seo_keywords)); $this->template->set('meta_keywords', implode(',', $seo_keywords));
$this->template->set('meta_description', $seo_description); $this->template->set('meta_description', $seo_description);
$this->template->set('meta_title', $seo_title); $this->template->set('meta_title', $seo_title);
$mainCats = $this->category_model->getMains($cat); $mainCats = $this->category_model->getMains($categoryId->id);
$current_cat = $this->category_model->getCat($cat); $current_cat = $this->category_model->getCat($categoryId->id);
$mainCats[] = [ $mainCats[] = [
'id' => $current_cat->id, 'id' => $current_cat->id,
'val' => $current_cat->name, 'val' => $current_cat->name,
]; ];
$subCats = $this->category_repository->getSubCatById($cat); $subCats = $this->category_repository->getSubCatById($categoryId->id);
} else { } else {
$cat = null;
$mainCats = $this->category_repository->mainCats(); $mainCats = $this->category_repository->mainCats();
} }
@ -270,7 +286,8 @@ class AdvsController extends PublicController
$viewType = $this->requestHttp->cookie('viewType'); $viewType = $this->requestHttp->cookie('viewType');
$compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', 'param', $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); 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 %} {% for category_breadcrumbs in params.mainCats %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="{{ url_route('visiosoft.module.advs::list_cat', [category_breadcrumbs['id']]) }}" <a href="{{ url_route('visiosoft.module.advs::list_cat', [category_breadcrumbs['id']]) }}"

View File

@ -9,30 +9,27 @@
</h5> </h5>
</div> </div>
<div id="category" class="collapse show overflow-auto" aria-labelledby="categoryHeading" <div id="category" class="collapse show overflow-auto" aria-labelledby="categoryHeading"
data-parent="#filter" data-parent="#filter" style="max-height: 300px;">
style="max-height: 300px;">
<div class="list-group"> <div class="list-group">
{% for maincat in params.mainCats %} {% for maincat in params.mainCats %}
{% set name = maincat['val'] %} {% set name = maincat['val'] %}
{% set id = maincat['id'] %} {% set id = maincat['id'] %}
{% set parent_category = true %} {% set parent_category = true %}
{% if app.request.get('cat') is null or app.request.get('cat') == "" %} {% 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 name = maincat.name %}
{% set id = maincat.id %} {% set id = maincat.id %}
{% set parent_category = false %} {% set parent_category = false %}
{% endif %} {% endif %}
{% endif %} {% endif %}
{% set catId = entries('cats', 'category').find(id) %} {% set catId = entries('cats', 'category').find(id) %}
{% set cityId = null %} {% set citySlug = null %}
{% if 'city' in params.param|keys %} {% set pathInfo = app.request.pathinfo|split('/') %}
{% set citiesArray = params.param['city'][0]|split(',') %} {% if pathInfo|length is same as(4) %}
{% if count(citiesArray) is same as(1) %} {% set citySlug = pathInfo[3] %}
{% set cityId = entries('location', 'cities').find(params.param['city'][0]) %}
{% endif %}
{% endif %} {% endif %}
<a href="{% if(viewType != "map") %} <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 %} {% else %}
{{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':id}) }} {{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':id}) }}
{% endif %}" class="list-group-item list-group-item-action text-truncate"> {% endif %}" class="list-group-item list-group-item-action text-truncate">
@ -44,7 +41,7 @@
{% if subcat.parent_category_id == maincat['id'] %} {% if subcat.parent_category_id == maincat['id'] %}
{% set subCatId = entries('cats', 'category').find(subcat.id) %} {% set subCatId = entries('cats', 'category').find(subcat.id) %}
<a href="{% if(viewType != "map") %} <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 %} {% else %}
{{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':subcat.id}) }} {{ appendRequestURL(request_query(),url_route('advs_map_list'),{'cat':subcat.id}) }}
{% endif %}" class="list-group-item list-group-item-action text-truncate"> {% 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 countries_value = $('input[name="country"]').val();
var selected__city_request = $('input[name="city[]"]').val(); var selected__city_request = $('input[name="city[]"]').val();
if (cities == undefined || $(this).attr('data-parent') != countries_value) { 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) { var promiseForCities = new Promise(function (resolve, reject) {
locationCrud('id=' + countries_value, '/ajax/getCities', 'POST', beforeSend(), function (callback) { locationCrud('id=' + countries_value, '/ajax/getCities', 'POST', beforeSend(), function (callback) {
cities = callback; cities = callback;
@ -45,11 +45,11 @@ $('.filter-city-btn').on('click', function () {
$.each(cities, function (index, value) { $.each(cities, function (index, value) {
$('.filter-location-modal .cities').append(item('city', value.id, value.name)); $('.filter-location-modal .cities').append(item('city', value.id, value.name));
}); });
if (cities == "") if (cities == "") {
$('.filter-location-modal .cities').html(null_msg); $('.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) { $.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(); resolve();

View File

@ -18,15 +18,23 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.city.name") }}</span> <span class="float-left">{{ trans("visiosoft.module.location::field.city.name") }}</span>
<i class="fas fa-sort-down float-right"></i> <i class="fas fa-sort-down float-right"></i>
</button> </button>
{% set selected_cities = params.param['city'] %} {% set citySlug = null %}
{% set selected_cities_name = [] %} {% set pathInfo = app.request.pathinfo|split('/') %}
{% for selected_city in selected_cities[0]|split(',') %} {% if pathInfo|length is same as(4) %}
{% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %} {% set citySlug = entries('location', 'cities').findBy('slug', pathInfo[3]) %}
{% endfor %} {% 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"> <div class="text-muted selected-city">
<small>{{ selected_cities_name|join(',') }}</small> <small>{{ selected_cities_name|join(',') }}</small>
</div> </div>
<input name="city[]" value="{{ params.param['city']|join(',') }}" type="hidden"> <input name="city[]" type="hidden"
value="{% if citySlug %}{{ citySlug.id }}{% else %}{{ params.param['city']|join(',') }}{% endif %}">
</div> </div>
<div class="col-12 px-0 py-1"> <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" <button type="button" class="btn btn-default border border-1 w-100 filter-district-btn" data-toggle="modal"

View File

@ -81,8 +81,8 @@ function crud(params, url, type, callback) {
}); });
} }
function getMyAds(type) { function getMyAdvs(type) {
crud({'type': type}, '/ajax/getAds', 'GET', function (callback) { crud({'type': type}, '/ajax/getAdvs', 'GET', function (callback) {
ads_type = type; ads_type = type;
current_page = 1; current_page = 1;
objJson = callback.content; objJson = callback.content;
@ -90,11 +90,11 @@ function getMyAds(type) {
}) })
} }
$('.profile-ads-tab a').on('click', function () { $('.profile-advs-tab a').on('click', function () {
getMyAds($(this).attr('data-type')) getMyAdvs($(this).attr('data-type'))
}); });
getMyAds('approved'); getMyAdvs('approved');
function addAdsRow(id, href, image, name, price, city, country, cat1, cat2, status) { function addAdsRow(id, href, image, name, price, city, country, cat1, cat2, status) {

View File

@ -8,8 +8,8 @@
<h3>{{ trans('visiosoft.module.advs::field.my_ads.name') }}</h3> <h3>{{ trans('visiosoft.module.advs::field.my_ads.name') }}</h3>
</div> </div>
<div class="col-md-12 bg-light ads-section"> <div class="col-md-12 bg-light advs-section">
<nav class="profile-ads-tab"> <nav class="profile-advs-tab">
<div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist"> <div class="nav nav-tabs nav-fill" id="nav-tab" role="tablist">
<a class="nav-item nav-link active text-dark" data-type="approved" id="nav-approved-tab" <a class="nav-item nav-link active text-dark" data-type="approved" id="nav-approved-tab"
data-toggle="tab" data-toggle="tab"

View File

@ -0,0 +1,15 @@
<?php namespace Visiosoft\ProfileModule\Http\Controller;
use Anomaly\Streams\Platform\Http\Controller\PublicController;
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
use Illuminate\Http\Request;
class CacheController extends PublicController
{
public function getUserInfo(Request $request, UserRepositoryInterface $userRepository)
{
$user = $userRepository->find($request->userId);
return ['userName' => $user->first_name . ' ' . $user->last_name];
}
}

View File

@ -125,6 +125,8 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@notification', 'uses' => 'Visiosoft\ProfileModule\Http\Controller\MyProfileController@notification',
], ],
// Cache links
'ajax/get-user-info' => 'Visiosoft\ProfileModule\Http\Controller\CacheController@getUserInfo'
]; ];
/** /**