mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-24 22:11:01 -06:00
#3968 [cats-module] export import
This commit is contained in:
parent
6bdcf4eed9
commit
432fa9136e
@ -30,6 +30,10 @@ return [
|
|||||||
'instructions' => 'It is used to add icons indicating the category type.',
|
'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',
|
'please_wait' => 'Please wait.Deleting Sub Categories',
|
||||||
'category_selection' => 'Category Selection',
|
'category_selection' => 'Category Selection',
|
||||||
'go_to_parent' => 'Go To Parent',
|
'go_to_parent' => 'Go To Parent',
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
namespace Visiosoft\CatsModule\Category;
|
||||||
|
|
||||||
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||||
|
|
||||||
|
class CategoryExport implements WithMapping, FromCollection, WithHeadings
|
||||||
|
{
|
||||||
|
public function collection()
|
||||||
|
{
|
||||||
|
return CategoryModel::all();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function map($cats): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
$cats->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'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?php namespace Visiosoft\CatsModule\Category;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Maatwebsite\Excel\Concerns\ToModel;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||||
|
|
||||||
|
class CategoryImport implements ToModel, WithHeadingRow
|
||||||
|
{
|
||||||
|
public function model(array $row)
|
||||||
|
{
|
||||||
|
if ($row['name'] !== null) {
|
||||||
|
return new CategoryModel([
|
||||||
|
'name' => $row['name'],
|
||||||
|
'slug' => Str::slug($row['name']),
|
||||||
|
'parent_category_id' => $row['parent_id'] ?? null,
|
||||||
|
'level' => $row['level'] ?? 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
<?php namespace Visiosoft\CatsModule;
|
<?php namespace Visiosoft\CatsModule;
|
||||||
|
|
||||||
|
use Anomaly\Streams\Platform\Addon\AddonCollection;
|
||||||
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
|
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
|
||||||
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
|
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
|
||||||
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
|
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
|
||||||
@ -59,13 +60,24 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
|||||||
'admin/cats/adcountcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@adCountCalc',
|
'admin/cats/adcountcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@adCountCalc',
|
||||||
'admin/cats/catlevelcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@catLevelCalc',
|
'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/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create',
|
||||||
'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit',
|
'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit',
|
||||||
'admin/cats/category/delete/{id}' => [
|
'admin/cats/category/delete/{id}' => [
|
||||||
'as' => 'visiosoft.module.cats::admin.delete_category',
|
'as' => 'visiosoft.module.cats::admin.delete_category',
|
||||||
'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@delete',
|
'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
|
||||||
'sitemap.xml' => 'Visiosoft\CatsModule\Http\Controller\SitemapController@index',
|
'sitemap.xml' => 'Visiosoft\CatsModule\Http\Controller\SitemapController@index',
|
||||||
@ -187,10 +199,24 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
|||||||
/**
|
/**
|
||||||
* Boot the addon.
|
* Boot the addon.
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot(AddonCollection $addonCollection)
|
||||||
{
|
{
|
||||||
// Run extra post-boot registration logic here.
|
$settings_url = [
|
||||||
// Use method injection or commands to bring in services.
|
'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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
|
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
|
||||||
|
|
||||||
|
use Anomaly\FilesModule\File\Contract\FileRepositoryInterface;
|
||||||
use Anomaly\FilesModule\File\FileSanitizer;
|
use Anomaly\FilesModule\File\FileSanitizer;
|
||||||
use Anomaly\FilesModule\File\FileUploader;
|
use Anomaly\FilesModule\File\FileUploader;
|
||||||
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
|
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
|
||||||
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
|
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
|
||||||
|
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use League\Flysystem\MountManager;
|
use League\Flysystem\MountManager;
|
||||||
|
use Visiosoft\CatsModule\Category\CategoryExport;
|
||||||
|
use Visiosoft\CatsModule\Category\CategoryImport;
|
||||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||||
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
|
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
|
||||||
use Visiosoft\CatsModule\Category\Command\CalculateCategoryLevel;
|
use Visiosoft\CatsModule\Category\Command\CalculateCategoryLevel;
|
||||||
@ -17,6 +21,7 @@ use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
|
|||||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||||
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
|
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
|
||||||
use Visiosoft\CatsModule\Category\Traits\DeleteCategory;
|
use Visiosoft\CatsModule\Category\Traits\DeleteCategory;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
|
||||||
class CategoryController extends AdminController
|
class CategoryController extends AdminController
|
||||||
{
|
{
|
||||||
@ -273,4 +278,38 @@ class CategoryController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function import(FormBuilder $builder, FileRepositoryInterface $fileRepository){
|
||||||
|
|
||||||
|
if (request()->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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user