From b46d2bd1cd09169111ceb3af21033dbe3236fc57 Mon Sep 17 00:00:00 2001 From: vedatakd Date: Fri, 25 Oct 2019 10:12:45 +0300 Subject: [PATCH] #490 create edit category page && edited controller function --- .../resources/css/edit_category.css | 34 +++ .../advs-module/resources/js/edit_cats.js | 52 ++++ .../advs-module/resources/lang/en/button.php | 3 + .../advs-module/resources/lang/en/field.php | 3 +- .../advs-module/resources/lang/en/message.php | 4 +- .../advs-module/resources/lang/tr/button.php | 5 +- .../advs-module/resources/lang/tr/field.php | 1 + .../advs-module/resources/lang/tr/message.php | 5 +- .../resources/views/advs/edit-cat.twig | 113 +++++++ .../resources/views/advs/new-create.twig | 1 + .../resources/views/advs/post-cat.twig | 170 +++++------ .../src/AdvsModuleServiceProvider.php | 10 +- .../src/Http/Controller/advsController.php | 280 +++++++++++++----- .../advs-module/src/Seed/BlockSeeder.php | 31 ++ 14 files changed, 543 insertions(+), 169 deletions(-) create mode 100644 addons/default/visiosoft/advs-module/resources/css/edit_category.css create mode 100644 addons/default/visiosoft/advs-module/resources/js/edit_cats.js create mode 100644 addons/default/visiosoft/advs-module/resources/views/advs/edit-cat.twig diff --git a/addons/default/visiosoft/advs-module/resources/css/edit_category.css b/addons/default/visiosoft/advs-module/resources/css/edit_category.css new file mode 100644 index 000000000..2186c271b --- /dev/null +++ b/addons/default/visiosoft/advs-module/resources/css/edit_category.css @@ -0,0 +1,34 @@ +.cat-select { + width: 100%; + border: none; + overflow-y: auto +} + +.cat-select option { + border-top: 1px solid #f2f2f2; + padding: 15px 0 20px; + position: relative; + padding-left: 10px; + font-size: 16px; + color: #505050; +} + +.cat-item-2 { + display: none; +} + +.cat-item-3 { + display: none; +} + +.cat-item-3 .section { + min-height: 320px; +} + +.btn-1 { + background-color: #00a651; + padding: 5px 50px 7px; + color: #fff; + border: 1px solid #dadada; + margin-right: 5px; +} \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/resources/js/edit_cats.js b/addons/default/visiosoft/advs-module/resources/js/edit_cats.js new file mode 100644 index 000000000..f93b3f139 --- /dev/null +++ b/addons/default/visiosoft/advs-module/resources/js/edit_cats.js @@ -0,0 +1,52 @@ +$(document).ready(function () { + $('select[name="cat1"], select[name="cat2"], select[name="cat3"], ' + + 'select[name="cat4"], select[name="cat5"], select[name="cat6"], select[name="cat7"]').on('change', function () { + var all = $(this).val(); + $(this).val(all[all.length-1]) + }) + + const filter = {}; + filter.getCats = (catId, divId) => { + $.ajax({ + type: 'get', + url: '/ajax/getcats/'+ divId, + success: function (response) { + if(response.length <= 0){ + $('.cat-item-3').show(); + stop(); + } + else { + response.forEach(function(options){ + $(catId).append("").closest('.cat-item-2').show(); + }); + } + } + }) + }; + + filter.hideCats = (num) => { + var startNo = num; + var endNo = 6; + + while (startNo <= endNo) { + $('#cat'+ startNo).html("").closest('.cat-item-2').hide(); + $('.cat-item-3').hide(); + startNo++; + } + }; + + for (var i = 1; i <= 6; i++) { + (function(){ + var ii = i; + $('#cat'+i).on('change', function (i,e) { + divId = $(this).find('option:selected').val(); + if (divId == 0) { + filter.hideCats(ii+1); + } + filter.hideCats(ii+1); + filter.getCats("#cat"+(ii+1), divId); + }); + })(); + } + +}); \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/button.php b/addons/default/visiosoft/advs-module/resources/lang/en/button.php index 092684e6e..ddd3d433d 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/button.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/button.php @@ -21,4 +21,7 @@ return [ 'sub_neighborhoods' => 'Sub Neighborhoods', 'sub_village' => 'Sub Village', 'general_settings' => 'General Settings', + 'update_category' => [ + 'name' => 'Update Category' + ], ]; 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 3e77fdbfb..af1425b79 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/field.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/field.php @@ -140,7 +140,7 @@ return [ 'share' => 'Share this ad', 'report' => 'Report this ad', 'features' => 'Features', - "streetview" =>"Street View", + "streetview" => "Street View", 'recommended_ads' => 'Recommended Ads for You', 'new' => 'New', 'short_info' => 'Short Info', @@ -216,4 +216,5 @@ return [ 'sold_out' => [ 'name' => 'Sold out', ], + 'edit_category' => 'Edit Category', ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/en/message.php b/addons/default/visiosoft/advs-module/resources/lang/en/message.php index 7f0da6967..656aa5f8e 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/en/message.php +++ b/addons/default/visiosoft/advs-module/resources/lang/en/message.php @@ -5,6 +5,8 @@ return [ 'please_buy_package' => 'Please buy package', 'please_payment' => 'Please Pay', 'bank_account_info' => 'Bank account information', - 'agreement' =>'By clicking Post, you agree to our Terms of Use and Privacy Policy acknowledge that you are the rightful owner of this item.' + 'agreement' => 'By clicking Post, you agree to our Terms of Use and Privacy Policy acknowledge that you are the rightful owner of this item.', + 'update_category_msg' => 'The classified category will be updated.', + 'updated_category_msg' => 'Category successfully edited.', ]; diff --git a/addons/default/visiosoft/advs-module/resources/lang/tr/button.php b/addons/default/visiosoft/advs-module/resources/lang/tr/button.php index b85cc6c21..d88628ac0 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/tr/button.php +++ b/addons/default/visiosoft/advs-module/resources/lang/tr/button.php @@ -20,5 +20,8 @@ return[ "sub_districts" =>"Alt Bölgeler", "sub_neighborhoods" =>"Alt Mahalleler", "sub_village" =>"Alt Köy", - "general_settings" =>"Genel Ayarlar" + "general_settings" =>"Genel Ayarlar", + 'update_category' => [ + 'name' => 'Kategori Güncelle' + ], ]; \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/resources/lang/tr/field.php b/addons/default/visiosoft/advs-module/resources/lang/tr/field.php index dc45494c0..26d7da2ec 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/tr/field.php +++ b/addons/default/visiosoft/advs-module/resources/lang/tr/field.php @@ -265,5 +265,6 @@ return [ 'sold_out' => [ 'name' => 'Tükendi', ], + 'edit_category' => 'Kategori Düzenle', ]; \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/resources/lang/tr/message.php b/addons/default/visiosoft/advs-module/resources/lang/tr/message.php index 77c022c02..50ac01074 100644 --- a/addons/default/visiosoft/advs-module/resources/lang/tr/message.php +++ b/addons/default/visiosoft/advs-module/resources/lang/tr/message.php @@ -5,6 +5,7 @@ return [ "please_buy_package" => "Lütfen paket satın al", 'please_payment' => 'Lütfen Ödeme Yapınız', 'bank_account_info' => 'Banka Hesap Bilgilerimiz', - 'agreement' =>'Yayınla\'yı tıkladığınızda, Kullanım Koşulları ve Gizlilik Politikasını kabul etmiş olursunuz, bu öğenin hak sahibi olduğunuzu kabul edersiniz.' - + 'agreement' => 'Yayınla\'yı tıkladığınızda, Kullanım Koşulları ve Gizlilik Politikasını kabul etmiş olursunuz, bu öğenin hak sahibi olduğunuzu kabul edersiniz.', + 'update_category_msg' => 'İlan kategorisi güncellenecektir.', + 'updated_category_msg' => 'Kategori başarıyla güncellendi.', ]; \ No newline at end of file diff --git a/addons/default/visiosoft/advs-module/resources/views/advs/edit-cat.twig b/addons/default/visiosoft/advs-module/resources/views/advs/edit-cat.twig new file mode 100644 index 000000000..43bf021eb --- /dev/null +++ b/addons/default/visiosoft/advs-module/resources/views/advs/edit-cat.twig @@ -0,0 +1,113 @@ +{% extends "theme::layouts/default" %} +{% block content %} +
+
+ + +
+
+ +
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+ +
+
+

{{ trans('visiosoft.module.advs::message.update_category_msg') }}

+ +
+
+
+
+
+ {{ blocks('center-add-ad-banner-area') }} +
+
+
+
+
+
+ + {{ asset_add("scripts.js", "visiosoft.module.advs::js/edit_cats.js") }} + {{ asset_style("visiosoft.module.advs::css/edit_category.css") }} +{% endblock %} diff --git a/addons/default/visiosoft/advs-module/resources/views/advs/new-create.twig b/addons/default/visiosoft/advs-module/resources/views/advs/new-create.twig index 67e86109b..59078615e 100644 --- a/addons/default/visiosoft/advs-module/resources/views/advs/new-create.twig +++ b/addons/default/visiosoft/advs-module/resources/views/advs/new-create.twig @@ -51,6 +51,7 @@ {% endfor %} + {{ trans('visiosoft.module.advs::field.edit_category') }}
diff --git a/addons/default/visiosoft/advs-module/resources/views/advs/post-cat.twig b/addons/default/visiosoft/advs-module/resources/views/advs/post-cat.twig index c25a224be..83593e43e 100644 --- a/addons/default/visiosoft/advs-module/resources/views/advs/post-cat.twig +++ b/addons/default/visiosoft/advs-module/resources/views/advs/post-cat.twig @@ -13,91 +13,90 @@
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_category') }}

-
    - -
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+
+
+

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

+
    + +
+
+
+ +
+ +
+
+
+
+ {{ blocks('center-add-ad-banner-area') }}
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
-
-
-

{{ trans('visiosoft.module.advs::field.select_a_sub_category') }}

-
    - -
-
-
- -
- -
-
-
-
-
- Image -
-
-
@@ -108,6 +107,7 @@ border: none; overflow-y: auto } + .cat-select option { border-top: 1px solid #f2f2f2; padding: 15px 0 20px; @@ -116,15 +116,19 @@ font-size: 16px; color: #505050; } + .cat-item-2 { display: none; } + .cat-item-3 { display: none; } + #main { background-image: {{ img('theme::images/bg/main.png').url }} !important; } + .btn-1 { background-color: #00a651; padding: 5px 50px 7px; diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index 6e353d9f8..0f5db33ee 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -137,7 +137,7 @@ class AdvsModuleServiceProvider extends AddonServiceProvider 'as' => 'post_adv', 'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@create', ], - 'class/getcats/{id}' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getCats', + 'class/getcats/{id}' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getCatsForNewAd', 'advs/save_adv' => [ 'as' => 'visiosoft.module.advs::post_cat', 'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@store' @@ -190,6 +190,14 @@ class AdvsModuleServiceProvider extends AddonServiceProvider 'as' => 'assets_clear', 'uses' => 'Visiosoft\AdvsModule\Http\Controller\Admin\AdvsController@assetsClear', ], + 'adv/edit/category/{id}' => [ + 'as' => 'adv::edit_category', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@editCategoryForAd', + ], + 'ajax/getcats/{id}' => [ + 'as' => 'ajax::getCats', + 'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getCats', + ], ]; /** 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 d1b1d16eb..ff952a749 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -56,63 +56,147 @@ use Visiosoft\StoreModule\User\UserModel; class AdvsController extends PublicController { + private $adv_model; + private $adv_repository; + + private $country_repository; + + private $city_model; + + private $district_model; + + private $neighborhood_model; + + private $village_model; + + private $profile_model; + private $profile_repository; + + private $category_model; + private $category_repository; + + private $requestHttp; + private $settings_repository; + private $event; + + public function __construct( + AdvModel $advModel, + AdvRepositoryInterface $advRepository, + + CountryRepositoryInterface $country_repository, + + CityModel $city_model, + + DistrictModel $district_model, + + NeighborhoodModel $neighborhood_model, + + VillageModel $village_model, + + ProfileModel $profile_model, + ProfileRepositoryInterface $profile_repository, + + CategoryModel $categoryModel, + CategoryRepositoryInterface $category_repository, + + SettingRepositoryInterface $settings_repository, + + Dispatcher $events, + + Request $request + ) + { + $this->adv_model = $advModel; + $this->adv_repository = $advRepository; + + $this->country_repository = $country_repository; + + $this->city_model = $city_model; + + $this->district_model = $district_model; + + $this->neighborhood_model = $neighborhood_model; + + $this->village_model = $village_model; - public function index(AdvRepositoryInterface $advRepository, - CategoryRepositoryInterface $categories, - CountryRepositoryInterface $countries, - ProfileRepositoryInterface $profileRepository, - Request $request) + $this->profile_model = $profile_model; + $this->profile_repository = $profile_repository; + + $this->category_model = $categoryModel; + $this->category_repository = $category_repository; + + $this->settings_repository = $settings_repository; + + $this->event = $events; + + $this->requestHttp = $request; + + parent::__construct(); + } + + + /** + * @return \Illuminate\Contracts\View\View|mixed + */ + public function index() { $customParameters = array(); - $param = $request->toArray(); - $advmodel = new AdvModel(); - $isActiveDopings = $advmodel->is_enabled('dopings'); - $isActiveCustomFields = $advmodel->is_enabled('customfields'); - // AdvRepository - $advs = $advRepository->searchAdvs('list', $param, $customParameters); + $featured_advs = array(); + $subCats = array(); + + $param = $this->requestHttp->toArray(); + + $countries = $this->country_repository->viewAll(); + + $isActiveDopings = $this->adv_model->is_enabled('dopings'); + + $isActiveCustomFields = $this->adv_model->is_enabled('customfields'); + + $advs = $this->adv_repository->searchAdvs('list', $param, $customParameters); + + $advs = $this->adv_repository->addAttributes($advs); - $advs = $advRepository->addAttributes($advs); - $featured_advs = []; if ($isActiveDopings) { $dopingModel = new DopingModel(); $featured_advs = $dopingModel->filterAdvs(2, $advs); + foreach ($featured_advs as $index => $ad) { - $featured_advs[$index]->detail_url = $advmodel->getAdvDetailLinkByModel($ad, 'list'); - $featured_advs[$index] = $advmodel->AddAdsDefaultCoverImage($ad); + $featured_advs[$index]->detail_url = $this->adv_model->getAdvDetailLinkByModel($ad, 'list'); + $featured_advs[$index] = $this->adv_model->AddAdsDefaultCoverImage($ad); } + $advs = $dopingModel->reFilterAdvs(2, $advs); } + foreach ($advs as $index => $ad) { - $advs[$index]->detail_url = $advmodel->getAdvDetailLinkByModel($ad, 'list'); - $advs[$index] = $advmodel->AddAdsDefaultCoverImage($ad); + $advs[$index]->detail_url = $this->adv_model->getAdvDetailLinkByModel($ad, 'list'); + $advs[$index] = $this->adv_model->AddAdsDefaultCoverImage($ad); + if ($isActiveCustomFields && isset($param['cat']) and $param['cat'] != "") { - $rtnvalues = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->indexseen($ad, $param['cat'], $advs, $index); + $rtnvalues = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController') + ->indexseen($ad, $param['cat'], $advs, $index); $advs = $rtnvalues['advs']; $seenList = $rtnvalues['seenList']; } } - $countries = $countries->viewAll(); - $subCats = []; if (isset($param['cat']) and $param['cat'] != "") { $cat = $param['cat']; - $mainCats = new CategoryModel(); - - $seo_keywords = $mainCats->getMeta_keywords($param['cat']); - $seo_description = $mainCats->getMeta_description($param['cat']); - $seo_title = $mainCats->getMeta_title($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']); $this->template->set('meta_keywords', implode(',', $seo_keywords)); $this->template->set('meta_description', $seo_description); $this->template->set('meta_title', $seo_title); - $mainCats = $mainCats->getParentCats($cat, 'category_ids'); - $subCats = $categories->getSubCatById($cat); + $mainCats = $this->category_model->getParentCats($cat, 'category_ids'); + $subCats = $this->category_repository->getSubCatById($cat); } else { $cat = null; - $mainCats = $categories->mainCats(); + $mainCats = $this->category_repository->mainCats(); } if ($isActiveCustomFields) { @@ -124,20 +208,22 @@ class AdvsController extends PublicController } if (!empty($param['user'])) { - $user = $profileRepository->getUser($param['user']); - $userProfile = $profileRepository->getProfile($user->id); + $user = $this->profile_repository->getUser($param['user']); + $userProfile = $this->profile_repository->getProfile($user->id); } + $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'textfields', 'checkboxes', 'request', 'user', 'userProfile', 'featured_advs', 'type', 'topfields', 'ranges', 'seenList'); - Cookie::queue(Cookie::make('last_search', $request->getRequestUri(), 84000)); + Cookie::queue(Cookie::make('last_search', $this->requestHttp->getRequestUri(), 84000)); - $viewType = $request->cookie('viewType'); - if (isset($viewType) and $viewType == 'table') { + $viewType = $this->requestHttp->cookie('viewType'); + + if (isset($viewType) and $viewType == 'table') return $this->view->make('visiosoft.module.advs::advs/table', $compact); - } elseif (isset($viewType) and $viewType == 'map') { + elseif (isset($viewType) and $viewType == 'map') return $this->view->make('visiosoft.module.advs::advs/map', $compact); - } + return $this->view->make('visiosoft.module.advs::advs/list', $compact); } @@ -147,37 +233,30 @@ class AdvsController extends PublicController return redirect($this->request->headers->get('referer')); } - public function view - ( - $id, - CategoryRepositoryInterface $categoryRepository, - Dispatcher $events, - AdvRepositoryInterface $advRepository, - AdvModel $advModel - ) + public function view($id) { - $isActiveComplaints = $advModel->is_enabled('complaints'); - $isCommentActive = $advModel->is_enabled('comments'); + $categories = array(); + $categories_id = array(); + $isActiveComplaints = $this->adv_model->is_enabled('complaints'); + $isCommentActive = $this->adv_model->is_enabled('comments'); if ($isActiveComplaints) { $complaints = ComplaintsComplainTypesEntryModel::all(); } - $adv = $advRepository->getListItemAdv($id); + $adv = $this->adv_repository->getListItemAdv($id); + + $recommended_advs = $this->adv_repository->getRecommendedAds($adv->id); - $recommended_advs = $advRepository->getRecommendedAds($adv->id); foreach ($recommended_advs as $index => $ad) { - $recommended_advs[$index]->detail_url = $advModel->getAdvDetailLinkByModel($ad, 'list'); - $recommended_advs[$index] = $advModel->AddAdsDefaultCoverImage($ad); + $recommended_advs[$index]->detail_url = $this->adv_model->getAdvDetailLinkByModel($ad, 'list'); + $recommended_advs[$index] = $this->adv_model->AddAdsDefaultCoverImage($ad); } - $categories = array(); - $categories_id = array(); - for ($i = 1; $i < 7; $i++) { $cat = "cat" . $i; if ($adv->$cat != null) { - $item = $categoryRepository->getItem($adv->$cat); + $item = $this->category_repository->getItem($adv->$cat); $categories['cat' . $i] = [ 'name' => $item->name, 'id' => $item->id @@ -186,13 +265,13 @@ class AdvsController extends PublicController } } - if ($advModel->is_enabled('customfields')) { + if ($this->adv_model->is_enabled('customfields')) { $features = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->view($adv); } //Cloudinary Module $adv->video_url = null; - $isActiveCloudinary = $advModel->is_enabled('cloudinary'); + $isActiveCloudinary = $this->adv_model->is_enabled('cloudinary'); if ($isActiveCloudinary) { $CloudinaryModel = new VideoModel(); @@ -203,17 +282,16 @@ class AdvsController extends PublicController } } - $profile = new ProfileModel(); - $profile = $profile->getProfile($adv->created_by_id)->first(); + $profile = $this->profile_model->getProfile($adv->created_by_id)->first(); if ($isCommentActive) { $CommentModel = new CommentModel(); $comments = $CommentModel->getComments($adv->id)->get(); } - $events->dispatch(new viewAd($adv));//view ad + $this->event->dispatch(new viewAd($adv));//view ad - $isActiveqrContact = $advModel->is_enabled('qrcontact'); + $isActiveqrContact = $this->adv_model->is_enabled('qrcontact'); if ($isActiveqrContact) { $qrModel = new QrModel(); $qrSRC = $qrModel->source($adv); @@ -231,21 +309,21 @@ class AdvsController extends PublicController } - public function getLocations(Request $request) + public function getLocations() { - $table = $request->table; - $id = $request->id; - $db = $request->typeDb; + $table = $this->requestHttp->table; + $id = $this->requestHttp->id; + $db = $this->requestHttp->typeDb; $location = ""; if ($table == "cities") { - $location = CityModel::query()->where($db, $id)->get(); + $location = $this->city_model->query()->where($db, $id)->get(); } elseif ($table == "districts") { - $location = DistrictModel::query()->whereIn($db, $id)->get(); + $location = $this->district_model->query()->whereIn($db, $id)->get(); } elseif ($table == "neighborhoods") { - $location = NeighborhoodModel::query()->where($db, $id)->get(); + $location = $this->neighborhood_model->query()->where($db, $id)->get(); } elseif ($table == "village") { - $location = VillageModel::query()->where($db, $id)->get(); + $location = $this->village_model->query()->where($db, $id)->get(); } return $location; @@ -260,9 +338,14 @@ class AdvsController extends PublicController return back(); } - public function getCats($id, SettingRepositoryInterface $settings, CategoryRepositoryInterface $category, AdvModel $advModel, CategoryModel $categoryModel) + public function getCats($id) { - $adv = $category->getSubCatById($id); + return $this->category_repository->getSubCatById($id); + } + + public function getCatsForNewAd($id) + { + $adv = $this->getCats($id); if (empty($adv->toArray())) { @@ -272,9 +355,9 @@ class AdvsController extends PublicController $adv['cancelBtn'] = trans('visiosoft.module.advs::field.cancel_add_advs_btn.name'); $adv['link'] = ""; - if ($advModel->is_enabled('packages')) { + if ($this->adv_model->is_enabled('packages')) { $packageModel = new PackageModel(); - $parent_cat = $categoryModel->getParentCats($id, 'parent_id'); + $parent_cat = $this->category_model->getParentCats($id, 'parent_id'); $package = $packageModel->reduceLimit($parent_cat); if ($package != null) { return $package; @@ -627,9 +710,9 @@ class AdvsController extends PublicController } - public function statusAds($id, $type, SettingRepositoryInterface $settings, Dispatcher $events, AdvModel $advModel) + public function statusAds($id, $type, SettingRepositoryInterface $settings, Dispatcher $events) { - $ad = $advModel->getAdv($id); + $ad = $this->adv_model->getAdv($id); $auto_approved = $settings->value('visiosoft.module.advs::auto_approve'); $default_published_time = $settings->value('visiosoft.module.advs::default_published_time'); @@ -638,41 +721,78 @@ class AdvsController extends PublicController } if ($type == "approved") { - $advModel->publish_at_Ads($id); + $this->adv_model->publish_at_Ads($id); if ($ad->finish_at == NULL AND $type == "approved") { - if ($advModel->is_enabled('packages')) { + if ($this->adv_model->is_enabled('packages')) { $packageModel = new PackageModel(); $published_time = $packageModel->reduceTimeLimit($ad->cat1); if ($published_time != null) { $default_published_time = $published_time; } } - $advModel->finish_at_Ads($id, $default_published_time); + $this->adv_model->finish_at_Ads($id, $default_published_time); } } - $isActiveAlgolia = $advModel->is_enabled('algolia'); + $isActiveAlgolia = $this->adv_model->is_enabled('algolia'); if ($isActiveAlgolia) { $algolia = new SearchModel(); $algolia->updateStatus($id, $type, $settings); } - $advModel->statusAds($id, $type); + $this->adv_model->statusAds($id, $type); $events->dispatch(new ChangeStatusAd($id, $settings));//Create Notify return back(); } - public function cats(CategoryRepositoryInterface $repository) + public function cats() { if (!Auth::user()) { redirect('/login?redirect=' . url()->current())->send(); } - $main_cats = $repository->mainCats(); + $main_cats = $this->category_repository->mainCats(); return $this->view->make('visiosoft.module.advs::advs/post-cat', compact('main_cats')); } + /** + * @param $id + * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|mixed + */ + public function editCategoryForAd($id) + { + if (!Auth::user()) { + redirect('/login?redirect=' . url()->current())->send(); + } + + $is_ad = $this->adv_model->userAdv($id)->find($id); + + if (is_null($is_ad)) { + abort(403); + } + + if ($this->requestHttp->action == 'update') { + $params = $this->requestHttp->all(); + unset($params['action']); + + for ($i = 2; $i <= 7; $i++) { + if (!isset($params['cat' . $i])) { + $params['cat' . $i] = NULL; + } + } + + $is_ad->update($params); + $this->messages->success(trans('visiosoft.module.advs::message.updated_category_msg')); + return redirect('/advs/edit_advs/' . $id); + } + + $main_cats = $this->category_repository->mainCats(); + + return $this->view->make('visiosoft.module.advs::advs/edit-cat', compact('main_cats', 'id')); + + } + public function login() { if (auth()->check()) { diff --git a/addons/default/visiosoft/advs-module/src/Seed/BlockSeeder.php b/addons/default/visiosoft/advs-module/src/Seed/BlockSeeder.php index b3de6f141..e67221aea 100644 --- a/addons/default/visiosoft/advs-module/src/Seed/BlockSeeder.php +++ b/addons/default/visiosoft/advs-module/src/Seed/BlockSeeder.php @@ -20,9 +20,40 @@ class BlockSeeder extends Seeder ->orWhere('slug', 'middle-home-banner-area') ->orWhere('slug', 'right-home-banner-area') ->orWhere('slug', 'list-item-right-sidebar') + ->orWhere('slug', 'center-add-ad-banner-area') ->orWhere('slug', 'profile-right-sidebar') ->delete(); + // Add Ad Center Banner Area + $center_add_ad_banner_area = BlocksAreasEntryModel::create([ + 'en' => [ + 'name' => 'Center Add Ad Banner Area', + ], + 'tr' => [ + 'name' => 'İlan Ver Orta Reklam Alanı', + ], + 'slug' => 'center-add-ad-banner-area', + ]); + + $center_add_ad_banner_html = HtmlBlockBlocksEntryModel::create([ + 'en' => [ + 'html' => file_get_contents(__DIR__ . '/Blocks/middle-home-banner-area.twig'), + ], + 'tr' => [ + 'html' => file_get_contents(__DIR__ . '/Blocks/middle-home-banner-area.twig'), + ], + ]); + + BlocksBlocksEntryModel::create([ + 'area_id' => $center_add_ad_banner_area->id, + 'area_type' => 'Anomaly\BlocksModule\Area\AreaModel', + 'field_id' => 52, + 'extension' => 'anomaly.extension.html_block', + 'display_title' => 0, + 'entry_type' => 'Anomaly\HtmlBlockExtension\Block\BlockModel', + 'entry_id' => $center_add_ad_banner_html->id, + ]); + // left Home Banner Area $left_home_banner_area = BlocksAreasEntryModel::create([ 'en' => [