From 432fa9136ef66b2b7ca72dd8235a5e83e9aaa523 Mon Sep 17 00:00:00 2001 From: muammertop Date: Sat, 22 May 2021 16:50:38 +0300 Subject: [PATCH] #3968 [cats-module] export import --- .../cats-module/resources/lang/en/field.php | 4 ++ .../src/Category/CategoryExport.php | 40 +++++++++++++++++++ .../src/Category/CategoryImport.php | 20 ++++++++++ .../src/CatsModuleServiceProvider.php | 34 ++++++++++++++-- .../Controller/Admin/CategoryController.php | 39 ++++++++++++++++++ 5 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 addons/default/visiosoft/cats-module/src/Category/CategoryExport.php create mode 100644 addons/default/visiosoft/cats-module/src/Category/CategoryImport.php diff --git a/addons/default/visiosoft/cats-module/resources/lang/en/field.php b/addons/default/visiosoft/cats-module/resources/lang/en/field.php index c2148802a..11e211b50 100644 --- a/addons/default/visiosoft/cats-module/resources/lang/en/field.php +++ b/addons/default/visiosoft/cats-module/resources/lang/en/field.php @@ -30,6 +30,10 @@ return [ 'instructions' => 'It is used to add icons indicating the category type.', ], + 'parent' => 'Parent', + 'level' => 'Level', + 'count' => 'Ad Counts', + 'please_wait' => 'Please wait.Deleting Sub Categories', 'category_selection' => 'Category Selection', 'go_to_parent' => 'Go To Parent', diff --git a/addons/default/visiosoft/cats-module/src/Category/CategoryExport.php b/addons/default/visiosoft/cats-module/src/Category/CategoryExport.php new file mode 100644 index 000000000..2c8a6790f --- /dev/null +++ b/addons/default/visiosoft/cats-module/src/Category/CategoryExport.php @@ -0,0 +1,40 @@ +id, + $cats->name, + $cats->parent_category_id, + $cats->level, + $cats->count, + $cats->seo_keyword, + $cats->seo_description, + ]; + } + + public function headings(): array + { + return [ + 'ID', + trans('module::field.name.name'), + trans('module::field.parent'), + trans('module::field.level'), + trans('module::field.count'), + trans('module::field.seo_keyword.name'), + trans('module::field.seo_description.name'), + ]; + } +} diff --git a/addons/default/visiosoft/cats-module/src/Category/CategoryImport.php b/addons/default/visiosoft/cats-module/src/Category/CategoryImport.php new file mode 100644 index 000000000..c7dcf0f93 --- /dev/null +++ b/addons/default/visiosoft/cats-module/src/Category/CategoryImport.php @@ -0,0 +1,20 @@ + $row['name'], + 'slug' => Str::slug($row['name']), + 'parent_category_id' => $row['parent_id'] ?? null, + 'level' => $row['level'] ?? 0, + ]); + } + } +} diff --git a/addons/default/visiosoft/cats-module/src/CatsModuleServiceProvider.php b/addons/default/visiosoft/cats-module/src/CatsModuleServiceProvider.php index 60915487a..fc1813a8d 100644 --- a/addons/default/visiosoft/cats-module/src/CatsModuleServiceProvider.php +++ b/addons/default/visiosoft/cats-module/src/CatsModuleServiceProvider.php @@ -1,5 +1,6 @@ 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@adCountCalc', 'admin/cats/catlevelcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@catLevelCalc', - 'admin/cats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index', + 'admin/cats' => [ + 'as' => 'visiosoft.module.cats::admin_cats', + 'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index' + ], 'admin/cats/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create', 'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit', 'admin/cats/category/delete/{id}' => [ 'as' => 'visiosoft.module.cats::admin.delete_category', 'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@delete', ], + 'admin/cats/import' => [ + 'as' => 'visiosoft.module.cats::import', + 'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@import', + ], + 'admin/cats/export' => [ + 'as' => 'visiosoft.module.cats::export', + 'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@export', + ], // Sitemap 'sitemap.xml' => 'Visiosoft\CatsModule\Http\Controller\SitemapController@index', @@ -187,10 +199,24 @@ class CatsModuleServiceProvider extends AddonServiceProvider /** * Boot the addon. */ - public function boot() + public function boot(AddonCollection $addonCollection) { - // Run extra post-boot registration logic here. - // Use method injection or commands to bring in services. + $settings_url = [ + 'import' => [ + 'title' => 'visiosoft.module.advs::button.import', + 'href' => route('visiosoft.module.cats::import'), + 'page' => 'visiosoft.module.cats' + ], + 'export' => [ + 'title' => 'visiosoft.module.advs::button.export', + 'href' => route('visiosoft.module.cats::export'), + 'page' => 'visiosoft.module.cats' + ], + ]; + + foreach ($settings_url as $key => $value) { + $addonCollection->get($value['page'])->addSection($key, $value); + } } /** 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 ac9e18ca2..58bfb1049 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,17 @@ action == "save" and $file = $fileRepository->find(request()->file)) { + if ($file->extension === 'xls' || $file->extension === 'xlsx') { + $pathToFolder = "/storage/streams/default/files-module/local/ads_excel/"; + Excel::import(new CategoryImport(), base_path() . $pathToFolder . $file->name); + $this->messages->success(trans('streams::message.create_success', ['name' => trans('module::addon.title')])); + } + } + + //Form Render + $builder->setFields([ + 'file' => [ + "type" => "anomaly.field_type.file", + "config" => [ + 'folders' => ["ads_excel"], + 'mode' => 'upload' + ] + ], + ]); + $builder->setActions([ + 'save' + ]); + + $builder->setOptions([ + 'redirect' => route('visiosoft.module.cats::admin_cats') + ]); + + return $builder->render(); + } + + public function export(){ + return Excel::download(new CategoryExport(), 'cats-' . time() . '.xlsx'); + } }