diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvCriteria.php b/addons/default/visiosoft/advs-module/src/Adv/AdvCriteria.php index 6c62c79ae..c2cdf09f0 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvCriteria.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvCriteria.php @@ -91,7 +91,7 @@ class AdvCriteria extends EntryCriteria public function countAdsByCategoryId($catId, $level = 1) { - return $this->advRepository->countByCat($catId, $level); + return $this->advRepository->getAdsCountByCategory($catId, $level); } public function getCurrentLocale() diff --git a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php index 164fe6d8e..4bf44eba9 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php +++ b/addons/default/visiosoft/advs-module/src/Adv/AdvRepository.php @@ -423,7 +423,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface return $ads; } - public function countByCat($catID, $level = 1) + public function getAdsCountByCategory($catID, $level = 1) { return DB::table('advs_advs') ->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) 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 1eaac9dac..6338739ab 100644 --- a/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php +++ b/addons/default/visiosoft/advs-module/src/Adv/Contract/AdvRepositoryInterface.php @@ -39,7 +39,7 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface public function getByCat($catID, $level = 1, $limit = 20); - public function countByCat($catID, $level = 1); + public function getAdsCountByCategory($catID, $level = 1); public function getCategoriesWithAdID($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 d344eaff4..fd87100d6 100644 --- a/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php +++ b/addons/default/visiosoft/advs-module/src/Http/Controller/advsController.php @@ -29,7 +29,6 @@ use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface; use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; -use Visiosoft\CloudinaryModule\Video\VideoModel; use Visiosoft\FavsModule\Http\Controller\FavsController; use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityRepository; @@ -529,17 +528,7 @@ class AdvsController extends PublicController $features = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->view($adv); } - //Cloudinary Module $adv->video_url = null; - if ($this->adv_model->is_enabled('cloudinary')) { - - $CloudinaryModel = new VideoModel(); - $Cloudinary = $CloudinaryModel->getVideo($id); - - if (count($Cloudinary->get()) > 0) { - $adv->video_url = $Cloudinary->first()->toArray()['url']; - } - } $options = $this->optionRepository->findAllBy('adv_id', $id); @@ -714,7 +703,7 @@ class AdvsController extends PublicController if ($isActive->is_enabled('customfields')) { $custom_fields = app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->create($categories); } - //Cloudinary Module + return $this->view->make('visiosoft.module.advs::new-ad/new-create', compact( 'request', 'formBuilder', 'cats_d', 'custom_fields')); } @@ -788,18 +777,6 @@ class AdvsController extends PublicController $adv->save(); - //Todo Move To Module - //Cloudinary Module - if (is_module_installed('visiosoft.module.cloudinary')) { - $CloudinaryModel = new VideoModel(); - $CloudinaryModel->updateRequest($this->request); - - if ($this->request->url != "") { - $adv->save(); - } - } - - //Todo Create Event if (is_module_installed('visiosoft.module.customfields')) { app('Visiosoft\CustomfieldsModule\Http\Controller\cfController')->store($adv, $this->request); @@ -938,18 +915,6 @@ class AdvsController extends PublicController $options = $this->optionRepository->findAllBy('adv_id', $id); - //Cloudinary Module - $Cloudinary = null; - $isActiveCloudinary = $this->adv_model->is_enabled('cloudinary'); - if ($isActiveCloudinary) { - $CloudinaryModel = new VideoModel(); - $Cloudinary = $CloudinaryModel->getVideo($id)->get(); - - if (count($Cloudinary) > 0) { - $Cloudinary = $Cloudinary->first()->toArray(); - } - } - $categories = array_keys($cats); $custom_fields = array(); @@ -960,7 +925,7 @@ class AdvsController extends PublicController return $this->view->make( 'visiosoft.module.advs::new-ad/new-create', - compact('id', 'cats_d', 'cats', 'Cloudinary', 'adv', 'custom_fields', 'options') + compact('id', 'cats_d', 'cats', 'adv', 'custom_fields', 'options') ); } diff --git a/addons/default/visiosoft/cats-module/src/Category/Command/CalculateAdsCount.php b/addons/default/visiosoft/cats-module/src/Category/Command/CalculateAdsCount.php new file mode 100644 index 000000000..0a958e4da --- /dev/null +++ b/addons/default/visiosoft/cats-module/src/Category/Command/CalculateAdsCount.php @@ -0,0 +1,55 @@ +category_id = $category_id; + } + + public function handle() + { + $date = new DateTime; + $date->modify('-30 minutes'); + $formatted_date = $date->format('Y-m-d H:i:s'); + + $query = DB::table('cats_category') + ->select('id', 'level'); + + if ($this->category_id) { + $category = $query->where('id', $this->category_id)->first(); + + $this->calculateCategory($category->id, $category->level); + } else { + $result = $query->where('count_at', '<', $formatted_date) + ->orWhereNull('count_at')->get(); + + foreach ($result as $key => $category) { + $this->calculateCategory($category->id, $category->level); + } + } + } + + public function calculateCategory($category_id, $level) + { + $advRepository = app(AdvRepositoryInterface::class); + if (!empty($level)) { + $count = $advRepository->getAdsCountByCategory($category_id, $level); + DB::table('cats_category')->where('id', $category_id)->update(array( + 'count' => $count, + 'count_at' => now(), + )); + } else { + $this->dispatch(new CalculateCategoryLevel($category_id)); + } + } +} diff --git a/addons/default/visiosoft/cats-module/src/Category/Command/CalculateCategoryLevel.php b/addons/default/visiosoft/cats-module/src/Category/Command/CalculateCategoryLevel.php new file mode 100644 index 000000000..3d9dab75c --- /dev/null +++ b/addons/default/visiosoft/cats-module/src/Category/Command/CalculateCategoryLevel.php @@ -0,0 +1,53 @@ +category_id = $category_id; + } + + public function handle() + { + if ($this->category_id) { + $this->calculateLevelByCategory($this->category_id); + } else { + $date = new DateTime; + $date->modify('-30 minutes'); + $formatted_date = $date->format('Y-m-d H:i:s'); + + $result = DB::table('cats_category') + ->select('id') + ->where('level_at', '<', $formatted_date) + ->where('level', '=', 0) + ->orWhereNull('level_at') + ->get(); + + foreach ($result as $key => $category) { + $this->calculateLevelByCategory($category->id); + } + } + } + + public function calculateLevelByCategory($category_id) + { + $categoryRepository = app(CategoryRepositoryInterface::class); + + $level = $categoryRepository->getLevelById($category_id); + + DB::table('cats_category')->where('id', $category_id) + ->update(array( + 'level' => $level, + 'level_at' => now(), + )); + } +} diff --git a/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForEditedAdCategory.php b/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForEditedAdCategory.php index 9399febbb..09c98d156 100644 --- a/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForEditedAdCategory.php +++ b/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForEditedAdCategory.php @@ -1,11 +1,14 @@ categoryRepository->find($category_id)) { - $category->setAttribute('count', $category->count - 1); - $category->setAttribute('count_at', now()); - $category->save(); - } + $this->dispatch(new CalculateAdsCount($category_id)); } //Update New Category Count foreach ($category_fields_new as $category_id) { - if ($category = $this->categoryRepository->find($category_id)) { - $category->setAttribute('count', $category->count + 1); - $category->setAttribute('count_at', now()); - $category->save(); - } + $this->dispatch(new CalculateAdsCount($category_id)); } } } \ No newline at end of file diff --git a/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForNewAd.php b/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForNewAd.php index a6784ae6d..aec20054a 100644 --- a/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForNewAd.php +++ b/addons/default/visiosoft/cats-module/src/Category/Listener/CalculatedTotalForNewAd.php @@ -1,10 +1,13 @@ categoryRepository->find($category_id)) { - $category->setAttribute('count', $category->count + 1); - $category->setAttribute('count_at', now()); - $category->save(); - } + $this->dispatch(new CalculateAdsCount($category_id)); } } } \ No newline at end of file diff --git a/addons/default/visiosoft/cats-module/src/Http/Controller/Admin/CategoryController.php b/addons/default/visiosoft/cats-module/src/Http/Controller/Admin/CategoryController.php index cc727c9b6..b453d4dfd 100644 --- a/addons/default/visiosoft/cats-module/src/Http/Controller/Admin/CategoryController.php +++ b/addons/default/visiosoft/cats-module/src/Http/Controller/Admin/CategoryController.php @@ -1,13 +1,11 @@ request->action == "delete") { - $CategoriesModel = new CategoryModel(); foreach ($this->request->id as $item) { //Todo Delete sub Categories } @@ -121,23 +118,27 @@ class CategoryController extends AdminController 'seo_keyword' => $all['seo_keyword'], 'seo_description' => $all['seo_description'], ])); + + + $this->dispatch(new CalculateCategoryLevel($category->id)); + } else { for ($i = 0; $i < count($isMultiCat[0]); $i++) { foreach ($isMultiCat as $cat) { $translatableEntries = array_merge($translatableEntries, $cat[$i]); } - $this->categoryRepository->create(array_merge($translatableEntries, [ + $category = $this->categoryRepository->create(array_merge($translatableEntries, [ 'slug' => $this->str->slug(reset($translatableEntries)['name'], '_'), 'parent_category' => $all['parent_category'] === "" ? null : $all['parent_category'], 'icon' => $all['icon'], 'seo_keyword' => $all['seo_keyword'], 'seo_description' => $all['seo_description'], ])); + + $this->dispatch(new CalculateCategoryLevel($category->id)); } }; - $this->catLevelCalc(); - // $this->categoryRepository->create(array_merge($translatableEntries, [ // 'slug' => $all['slug'], // 'parent_category' => $all['parent_category'], @@ -214,54 +215,21 @@ class CategoryController extends AdminController } return redirect('admin/cats')->with('success', [$deletedCatsCount . ' categories has been deleted.']); } - public function adCountCalc(AdvRepositoryInterface $advRepository) - { - $date = new DateTime; - $date2 = new DateTime; - $date->modify('-30 minutes'); - $formatted_date = $date->format('Y-m-d H:i:s'); - $result = DB::table('cats_category') - ->select('id','level') - ->where('count_at','<',$formatted_date) - ->orWhereNull('count_at') - ->get(); - foreach ($result as $key => $data) { - $id = $data->id; - $level = $data->level; - if(!empty($level)) { - $count = $advRepository->countByCat($id, $level); - DB::table('cats_category')->where('id',$id)->update(array( - 'count'=>$count, - 'count_at'=>$date2, - )); - } - } + public function adCountCalc() + { + $this->dispatch(new CalculateAdsCount()); + + $this->messages->success(trans('streams::message.edit_success', ['name' => trans('visiosoft.module.cats::addon.title')])); + return redirect('admin/cats'); } + public function catLevelCalc() { - $date = new DateTime; - $date2 = new DateTime; - $date->modify('-30 minutes'); - $formatted_date = $date->format('Y-m-d H:i:s'); + $this->dispatch(new CalculateCategoryLevel()); - $result = DB::table('cats_category') - ->select('id') - ->where('level_at','<',$formatted_date) - ->where('level','=',0) - ->orWhereNull('level_at') - ->get(); - foreach ($result as $key => $data) { - $id = $data->id; - $category_repository = app(CategoryRepositoryInterface::class); - $level = $category_repository->getLevelById($id); - - DB::table('cats_category')->where('id',$id)->update(array( - 'level'=>$level, - 'level_at'=>$date2, - )); - } - return redirect('admin/cats')->with('success', ['Updated']); + $this->messages->success(trans('streams::message.edit_success', ['name' => trans('visiosoft.module.cats::addon.title')])); + return redirect('admin/cats'); } }