From c61bf9dbb5c0635f9b113d387ebca498f6d0cc4e Mon Sep 17 00:00:00 2001 From: diashalabi Date: Tue, 12 Oct 2021 16:42:11 +0300 Subject: [PATCH] =?UTF-8?q?#1266=20=C4=B0lan=20Status=20de=C4=9Fi=C5=9Ftir?= =?UTF-8?q?me=20Fonksiyonlar=C4=B1=20Merkezile=C5=9Ftirilmeli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../advs-module/src/Adv/AdvModel.php | 40 ++++--------- .../Adv/Command/UpdateClassifiedStatus.php | 57 +++++++++++++++++++ .../src/Adv/Contract/AdvInterface.php | 2 - .../src/Adv/Table/Handler/Approve.php | 32 ++--------- .../src/Adv/Table/Handler/Decline.php | 19 ++----- .../src/Adv/Table/Handler/Delete.php | 6 +- .../src/Adv/Table/Handler/Extend.php | 3 +- .../src/AdvsModuleServiceProvider.php | 1 - .../Http/Controller/Admin/AdvsController.php | 19 +++---- .../src/Http/Controller/AdvsController.php | 33 +++-------- .../Http/Controller/MyProfileController.php | 12 ++-- 11 files changed, 102 insertions(+), 122 deletions(-) create mode 100755 addons/default/visiosoft/advs-module/src/Adv/Command/UpdateClassifiedStatus.php diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php index 8b1f5531c..e49bc7e4a 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvModel.php @@ -2,7 +2,6 @@ use Anomaly\Streams\Platform\Image\Command\MakeImageInstance; use Anomaly\Streams\Platform\Message\MessageBag; -use Anomaly\Streams\Platform\Model\Advs\AdvsCustomFieldsEntryModel; use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -38,8 +37,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface public function getDetailUrlAttribute() { // Checking for slug - if($this->attributes) - { + if ($this->attributes) { return $this->getAdvDetailLinkByModel($this, 'list'); } } @@ -73,13 +71,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface public function getCategory1Attribute() { return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first(); - } public function getCategory2Attribute() { return $this->hasMany('Visiosoft\CatsModule\Category\CategoryModel', 'id', 'cat1')->first(); - } public function getThumbnailAttribute() @@ -112,6 +108,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface if ($addon = app('module.collection')->get($slug)) { return $addon->installed; } + return false; } @@ -120,8 +117,9 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface $isActive = DB::table('addons_extensions')->where('namespace', 'visiosoft.extension.' . $slug . '_provider')->first(); if ($isActive == null) { return 0; - } else - return $isActive->enabled; + } + + return $isActive->enabled; } public function is_active($id) @@ -130,9 +128,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface ->where('advs_advs.id', $id) ->where('advs_advs.slug', '!=', "") ->first(); + if ($isActive->status != 'approved') { return 0; } + return 1; } @@ -148,13 +148,14 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface if ($nullable_ad) { return $query->find($id); } else { - return $query->where('advs_advs.slug', '!=', "") - ->find($id); + return $query->where('advs_advs.slug', '!=', "")->find($id); } } + if ($nullable_ad) { return $query->newQuery(); } + return $query->where('advs_advs.slug', '!=', ""); } @@ -366,22 +367,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface return 0; } - public function saveCustomField($category_id, $field_id, $name) - { - $all = array(); - $all['category_id'] = $category_id; - $all['field_id'] = $field_id; - $all['name'] = $name; - - if (AdvsCustomFieldsEntryModel::create($all)) { - return response()->json([ - 'success' => true - ]); - } else { - abort(404); - } - } - public function customfields() { if ($cFs = (array) json_decode($this->cf_json)) { @@ -405,11 +390,6 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface return json_decode($this->cf_json, true); } - // public function getCustomFieldEditId($id) { - // $custom_field = AdvsCustomFieldsEntryModel::query()->where('advs_custom_fields.id', $id)->first(); - // return DB::table('streams_assignments')->where('field_id', $custom_field->field_id)->first(); - // } - public function priceFormat($adv) { return number_format($adv->price, "2", ",", str_replace(' ', ' ', ".")); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Command/UpdateClassifiedStatus.php b/addons/default/visiosoft/advs-module/src/Adv/Command/UpdateClassifiedStatus.php new file mode 100755 index 000000000..ffc8b1008 --- /dev/null +++ b/addons/default/visiosoft/advs-module/src/Adv/Command/UpdateClassifiedStatus.php @@ -0,0 +1,57 @@ +classified = $classified; + $this->type = $type; + } + + public function handle() + { + $defaultClassifiedPublishTime = setting_value('visiosoft.module.advs::default_published_time'); + if (is_module_installed('visiosoft.module.packages')) { + $packageModel = new PackageModel(); + if ($packagePublishedTime = $packageModel->reduceTimeLimit($this->classified->cat1)) { + $defaultClassifiedPublishTime = $packagePublishedTime; + } + } + + switch ($this->type) { + case 'approved': + $update = [ + 'status' => 'approved', + ]; + + if (!setting_value('visiosoft.module.advs::show_finish_and_publish_date')) { + $update['publish_at'] = date('Y-m-d H:i:s'); + + if (is_null($this->classified->finish_at)) { + $update['finish_at'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultClassifiedPublishTime . ' day')); + } + } + + $this->classified->update($update); + + break; + default: + $this->classified->update([ + 'status' => $this->type, + ]); + + break; + } + + event(new ChangedStatusAd($this->classified)); + } +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php index 105da9504..50c5f838c 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvInterface.php @@ -56,8 +56,6 @@ interface AdvInterface extends EntryInterface public function stockControl($id, $quantity); - public function saveCustomField($category_id, $field_id, $name); - public function customfields(); public function cFJSON(); diff --git a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Approve.php b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Approve.php index 78b88175e..fe77f50b0 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Approve.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Approve.php @@ -1,36 +1,16 @@ getTableModel(); - foreach ($selected as $id) { - $defaultAdPublishTime = $settingRepository->value('visiosoft.module.advs::default_published_time'); - - if ($ad = $model->newQuery()->find($id)) { - - $update = [ - 'status' => 'approved', - ]; - - if (!setting_value('visiosoft.module.advs::show_finish_and_publish_date')) { - $update = array_merge($update, [ - 'finish_at' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultAdPublishTime . ' day')), - 'publish_at' => date('Y-m-d H:i:s') - ]); - } - - $ad->update($update); - - event(new ChangedStatusAd($ad));//Create Notify + if ($classified = $advRepository->find($id)) { + $this->dispatch(new UpdateClassifiedStatus($classified, 'approved')); } } @@ -38,4 +18,4 @@ class Approve extends ActionHandler $this->messages->success(trans('visiosoft.module.advs::field.approved')); } } -} \ No newline at end of file +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Decline.php b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Decline.php index 704176383..f32bc3caa 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Decline.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Decline.php @@ -1,28 +1,21 @@ getTableModel(); - foreach ($selected as $id) { + $classified = $advRepository->find($id); - $ad = $model->find($id); - $ad->status = 'declined'; - $ad->update(); - - event(new ChangedStatusAd($ad));//Create Notify - + $this->dispatch(new UpdateClassifiedStatus($classified, 'declined')); } if ($selected) { $this->messages->success(trans('visiosoft.module.advs::field.declined')); } } -} \ No newline at end of file +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Delete.php b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Delete.php index ec7c5ed9a..ef0de1580 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Delete.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Delete.php @@ -1,13 +1,9 @@ messages->warning(trans('streams::message.delete_success', compact('count'))); } } -} \ No newline at end of file +} diff --git a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Extend.php b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Extend.php index 0809dcc3f..9f126d745 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Extend.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Table/Handler/Extend.php @@ -3,7 +3,6 @@ use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler; use Visiosoft\AdvsModule\Adv\Table\AdvTableBuilder; - class Extend extends ActionHandler { public function handle(AdvTableBuilder $builder, array $selected) @@ -20,4 +19,4 @@ class Extend extends ActionHandler $this->messages->success(trans('visiosoft.module.advs::field.extended')); } } -} \ No newline at end of file +} diff --git a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php index e0aedcb40..9be6ee12d 100644 --- a/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php +++ b/addons/default/visiosoft/advs-module/src/AdvsModuleServiceProvider.php @@ -1,6 +1,5 @@ where('advs_advs.id', '=', $id)->first(); - $ad->status = $type; + $ad = $this->advRepository->find($id); - $default_adv_publish = $settings->value('visiosoft.module.advs::default_published_time'); - $ad->finish_at = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $default_adv_publish . ' day')); - $ad->publish_at = date('Y-m-d H:i:s'); + $this->dispatch(new UpdateClassifiedStatus($ad, $type)); - //algolia Search Module + // Algolia Search Module $isActiveAlgolia = $advModel->is_enabled('algolia'); if ($isActiveAlgolia) { $algolia = new SearchModel(); - $algolia->updateStatus($id, $type, $settings); + $algolia->updateStatus($id, $type); } - $ad->update(); - event(new ChangedStatusAd($ad));//Create Notify + return back(); } 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 2d708ccc2..d8652d0b7 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/AdvsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/AdvsController.php @@ -11,8 +11,8 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Cookie; use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\Command\IsOptionsByCategory; +use Visiosoft\AdvsModule\Adv\Command\UpdateClassifiedStatus; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; -use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd; use Visiosoft\AdvsModule\Adv\Event\CreatedAd; use Visiosoft\AdvsModule\Adv\Event\EditedAd; use Visiosoft\AdvsModule\Adv\Event\EditedAdCategory; @@ -29,7 +29,6 @@ use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface; use Visiosoft\LocationModule\District\DistrictModel; use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; use Visiosoft\LocationModule\Village\VillageModel; -use Visiosoft\PackagesModule\Package\PackageModel; use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface; use Visiosoft\SeoModule\Legend\Command\AddMetaData; @@ -1019,36 +1018,20 @@ class AdvsController extends PublicController ); } - public function statusAds($id, $type, SettingRepositoryInterface $settings, Dispatcher $events) + public function statusAds($id, $type) { $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'); + $autoApprove = setting_value('visiosoft.module.advs::auto_approve'); - if ($auto_approved == true and $type == 'pending_admin') { + if ($autoApprove && $type == 'pending_admin') { $type = "approved"; } - if ($type == "approved" and $auto_approved != true) { + + if ($type == "approved" && !$autoApprove) { $type = "pending_admin"; } - if ($type == "approved") { - $this->adv_model->publish_at_Ads($id); - if ($ad->finish_at == NULL and $type == "approved") { - 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; - } - } - $this->adv_model->finish_at_Ads($id, $default_published_time); - } - } - - $this->adv_model->statusAds($id, $type); - - event(new ChangedStatusAd($ad));//Create Notify + $this->dispatch(new UpdateClassifiedStatus($ad, $type)); if ($type === 'approved') { $message = trans('visiosoft.module.advs::message.approve_status_change'); @@ -1057,7 +1040,9 @@ class AdvsController extends PublicController } else { $message = trans('visiosoft.module.advs::message.passive_status_change'); } + $this->messages->success($message); + return back(); } diff --git a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php index ded768322..c25518cb1 100644 --- a/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php +++ b/addons/default/visiosoft/profile-module/src/Http/Controller/MyProfileController.php @@ -7,7 +7,6 @@ use Anomaly\UsersModule\User\Contract\UserRepositoryInterface; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Visiosoft\AdvsModule\Adv\AdvModel; -use Visiosoft\AdvsModule\Adv\Event\ChangeStatusAd; use Visiosoft\AdvsModule\Status\Contract\StatusRepositoryInterface; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\AlgoliaModule\Search\SearchModel; @@ -98,11 +97,11 @@ class MyProfileController extends PublicController } } - public function statusAds($id, $type, SettingRepositoryInterface $settings, Dispatcher $events, AdvModel $advModel) + public function statusAds($id, $type, AdvModel $advModel) { $ad = $advModel->getAdv($id); - $auto_approved = $settings->value('visiosoft.module.advs::auto_approve'); - $default_published_time = $settings->value('visiosoft.module.advs::default_published_time'); + $auto_approved = setting_value('visiosoft.module.advs::auto_approve'); + $default_published_time = setting_value('visiosoft.module.advs::default_published_time'); if ($auto_approved == true AND $type == 'pending_admin') { $type = "approved"; @@ -125,13 +124,12 @@ class MyProfileController extends PublicController $isActiveAlgolia = $isActiveAlgolia->is_enabled('algolia'); if ($isActiveAlgolia) { $algolia = new SearchModel(); - $algolia->updateStatus($id, $type, $settings); + $algolia->updateStatus($id, $type); } + $status = $advModel->statusAds($id, $type); - $events->dispatch(new ChangeStatusAd($id, $settings));//Create Notify return response()->json(['status' => $status]); - }