commit 16471b010f8f74c733153fd389af5f9381fde1f3 Author: Michal Kváček Date: Tue Aug 22 14:10:50 2017 +0200 FEATURE: move categories into own repository diff --git a/Config/config.php b/Config/config.php new file mode 100755 index 0000000..5b050b7 --- /dev/null +++ b/Config/config.php @@ -0,0 +1,12 @@ + 'Categories', + 'translatedName' => 'categories::module.name', + 'translatedDescription' => 'categories::module.description', + 'alias' => 'categories', + 'handler' => \Modules\Categories\Handlers\Categories::class, + 'providers' => [\Modules\Categories\Providers\CategoriesServiceProvider::class], + 'files' => ['start.php'], + 'order' => 0, +]; \ No newline at end of file diff --git a/Contracts/Repositories/Category.php b/Contracts/Repositories/Category.php new file mode 100755 index 0000000..ea344d3 --- /dev/null +++ b/Contracts/Repositories/Category.php @@ -0,0 +1,9 @@ +increments('id'); + $table->timestamps(); + $table->softDeletes(); + $table->integer('parent_id') + ->unsigned() + ->nullable(); + $table->integer('position', false, true); + $table->integer('real_depth', false, true); + $table->integer('user_id') + ->comment('Author of this category'); + $table->integer('module_id') + ->comment('ID of module, where this category is used'); + $table->string('name') + ->comment('Human readable name of category'); + $table->string('url') + ->index() + ->comment('URL slug of category'); + $table->text('description'); + + $table->unique(['url', 'module_id']); + }); + + Schema::table('categories', function (Blueprint $table) { + $table->foreign('parent_id') + ->references('id') + ->on('categories') + ->onDelete('set null'); + + $table->foreign('user_id') + ->references('id') + ->on('users') + ->onDelete('cascade') + ->onUpdate('cascade'); + + $table->foreign('module_id') + ->references('id') + ->on('modules') + ->onDelete('cascade') + ->onUpdate('cascade'); + }); + } + + public function down() + { + Schema::table('categories', function (Blueprint $table) { + Schema::dropIfExists('categories'); + }); + } +} diff --git a/Database/Migrations/2016_08_10_204046_create_category_closures_table.php b/Database/Migrations/2016_08_10_204046_create_category_closures_table.php new file mode 100755 index 0000000..d580f81 --- /dev/null +++ b/Database/Migrations/2016_08_10_204046_create_category_closures_table.php @@ -0,0 +1,35 @@ +increments('closure_id'); + + $table->integer('ancestor', false, true); + $table->integer('descendant', false, true); + $table->integer('depth', false, true); + + $table->foreign('ancestor') + ->references('id') + ->on('categories') + ->onDelete('cascade'); + $table->foreign('descendant') + ->references('id') + ->on('categories') + ->onDelete('cascade'); + }); + } + + public function down() + { + Schema::table('category_closure', function (Blueprint $table) { + Schema::dropIfExists('category_closure'); + }); + } +} diff --git a/Database/Seeders/.gitkeep b/Database/Seeders/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/Database/Seeders/CategoriesDatabaseSeeder.php b/Database/Seeders/CategoriesDatabaseSeeder.php new file mode 100755 index 0000000..5a509fb --- /dev/null +++ b/Database/Seeders/CategoriesDatabaseSeeder.php @@ -0,0 +1,20 @@ +call("OthersTableSeeder"); + } + +} \ No newline at end of file diff --git a/Entities/Category.php b/Entities/Category.php new file mode 100755 index 0000000..f1147b2 --- /dev/null +++ b/Entities/Category.php @@ -0,0 +1,33 @@ +belongsTo(Module::class); + } + + public function content() + { + return $this->hasMany(Content::class, 'categoryId'); + } +} diff --git a/Entities/CategoryClosure.php b/Entities/CategoryClosure.php new file mode 100755 index 0000000..bdb3a03 --- /dev/null +++ b/Entities/CategoryClosure.php @@ -0,0 +1,14 @@ +dropdown(trans('categories::categories.name'), function ($sub) { + $sub->route('categories.new', trans('categories::categories.new'), [], 10, ['icon' => 'fa fa-fw fa-plus']); + $sub->route('categories.overview', trans('categories::categories.overview'), [], 30, ['icon' => 'fa fa-fw fa-tags']); + }, 55, ['icon' => 'fa fa-fw fa-tags']); + } +} \ No newline at end of file diff --git a/Http/Controllers/CategoriesOverview.php b/Http/Controllers/CategoriesOverview.php new file mode 100644 index 0000000..3d14233 --- /dev/null +++ b/Http/Controllers/CategoriesOverview.php @@ -0,0 +1,22 @@ +toArray(); + + $modules = ModuleNamesWithIds::getWithTranslations(); + + return view('categories::admin.overview', [ + 'categories' => $categories, + 'modules' => $modules + ]); + } +} \ No newline at end of file diff --git a/Http/Controllers/CreateNewCategory.php b/Http/Controllers/CreateNewCategory.php new file mode 100644 index 0000000..9e228f4 --- /dev/null +++ b/Http/Controllers/CreateNewCategory.php @@ -0,0 +1,60 @@ +toArray(); + + // get list of modules which supports categories + $modules = Module::where('enabled', true) + ->where('support_categories', true) + ->get(); + + return view('categories::admin.new', [ + 'category' => new Category(), + 'categories' => $categories, + 'modules' => $modules + ]); + } + + /** + * Create new category + * + * @param Request $request + * + * @return \Illuminate\Http\RedirectResponse + */ + public function postNew(Request $request) + { + $category = new Category(); + $category->user_id = Auth::user()->id; + $category->module_id = $request->moduleId; + $category->name = $request->name; + $category->url = Str::slug($request->url); + $category->description = $request->description; + + if ((int)$request->parentCategory) { + $category->parent_id = $request->parentCategory; + } + + $category->save(); + + return redirect() + ->route('categories.overview') + ->with('success', trans('categories::categories.saveSuccessfull')); + } +} \ No newline at end of file diff --git a/Http/Controllers/EditCategory.php b/Http/Controllers/EditCategory.php new file mode 100644 index 0000000..1405249 --- /dev/null +++ b/Http/Controllers/EditCategory.php @@ -0,0 +1,77 @@ +toArray(); + + // get list of modules which supports categories + $modules = Module::where('enabled', true) + ->where('support_categories', true) + ->get(); + + return view('categories::admin.edit', [ + 'category' => $category, + 'categories' => $categories, + 'modules' => $modules + ]); + } + + /** + * Create new category + * + * @param Request $request + * @param $id + * + * @return \Illuminate\Http\RedirectResponse + */ + public function postEdit(Request $request, $id) + { + $category = Category::findOrFail($id); + + $category->name = $request->name; + $category->url = Str::slug($request->url); + $category->description = $request->description; + + $category->save(); + + if ($category->parent_id !== $request->parentCategory) { + $category->parent_id = empty($request->parentCategory) ? null : $request->parentCategory; + $category->save(); + + if (empty($request->parentCategory)) { + $category->makeRoot($category->position); + } + } + + return redirect() + ->route('categories.edit', ['id' => $id]) + ->with('success', trans('categories::categories.saveSuccessfull')); + } + + public function delete($id) { + $category = Category::findOrFail($id); + + $category->delete(); + + return redirect() + ->route('categories.overview') + ->with('success', trans('categories::categories.deleteSuccessfull')); + } +} \ No newline at end of file diff --git a/Http/Middleware/.gitkeep b/Http/Middleware/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/Http/Requests/.gitkeep b/Http/Requests/.gitkeep new file mode 100755 index 0000000..e69de29 diff --git a/Http/routes.php b/Http/routes.php new file mode 100755 index 0000000..52ff9a1 --- /dev/null +++ b/Http/routes.php @@ -0,0 +1,23 @@ + LaravelLocalization::setLocale() . '/admin/categories', + 'middleware' => ['admin'], + 'namespace' => 'Modules\Categories\Http\Controllers' + ], function () { + Route::get('/', 'CategoriesOverview@getOverview') + ->name('categories.overview'); + + Route::get('/new', 'CreateNewCategory@getNew') + ->name('categories.new'); + Route::post('/new', 'CreateNewCategory@postNew') + ->name('categories.postNew'); + + Route::get('/edit/{id}', 'EditCategory@getEdit') + ->name('categories.edit'); + Route::post('/edit/{id}', 'EditCategory@postEdit') + ->name('categories.postEdit'); + + Route::get('/delete/{id}', 'EditCategory@delete') + ->name('categories.delete'); +}); \ No newline at end of file diff --git a/Providers/CategoriesServiceProvider.php b/Providers/CategoriesServiceProvider.php new file mode 100644 index 0000000..cdde8c9 --- /dev/null +++ b/Providers/CategoriesServiceProvider.php @@ -0,0 +1,26 @@ +alias = 'categories'; + } + + public function boot() + { + parent::boot(); + + $this->app->bind(ICategory::class, Category::class); + } + + protected function setModulePath() + { + $this->path = __DIR__; + } +} diff --git a/Repositories/Category.php b/Repositories/Category.php new file mode 100644 index 0000000..7ef044e --- /dev/null +++ b/Repositories/Category.php @@ -0,0 +1,21 @@ +first(); + $categories = []; + if ($module->support_categories && !is_null($categoryModule) && $categoryModule->enabled) { + $categories = CategoryModel::where('module_id', $module->id) + ->get(); + } + + return $categories; + } +} \ No newline at end of file diff --git a/Resources/lang/cs/categories.php b/Resources/lang/cs/categories.php new file mode 100755 index 0000000..70faf2e --- /dev/null +++ b/Resources/lang/cs/categories.php @@ -0,0 +1,20 @@ + "Akce", +"deleteSuccessfull" => "Kategorie úspěšně smazána", +"description" => "Modul pro správu a kategorizaci obsahu.", +"edit" => "Úprava kategorie", +"fields" => ["description" => "Popis", +"module" => "Modul", +"name" => "Jméno", +"parentCategory" => "Rodičovská kategorie", +"save" => "Uložit", +"url" => "URL", +], +"module" => "Modul", +"name" => "Kategorie", +"new" => "Nová kategorie", +"noCategories" => "Žádná vytvořená kategorie.", +"overview" => "Všechny kategorie", +"saveSuccessfull" => "Kategorie úspěšně uložena", +]; diff --git a/Resources/lang/en/categories.php b/Resources/lang/en/categories.php new file mode 100755 index 0000000..a01d847 --- /dev/null +++ b/Resources/lang/en/categories.php @@ -0,0 +1,21 @@ + 'Categories', + 'description' => 'Module for category management and content categorization.', + 'new' => 'New category', + 'overview' => 'All categories', + 'fields' => [ + 'name' => 'Name', + 'description' => 'Description', + 'url' => 'URL', + 'module' => 'Module', + 'parentCategory' => 'Parent category', + 'save' => 'Save category' + ], + 'edit' => 'Edit category', + 'saveSuccessfull' => 'Category successfully saved', + 'deleteSuccessfull' => 'Category successfully deleted', + 'module' => 'Module', + 'actions' => 'Actions', + 'noCategories' => 'No categories available' +]; \ No newline at end of file diff --git a/Resources/lang/sk/categories.php b/Resources/lang/sk/categories.php new file mode 100755 index 0000000..ceb9a5d --- /dev/null +++ b/Resources/lang/sk/categories.php @@ -0,0 +1,20 @@ + "Akcie", + "deleteSuccessfull" => "Kategória úspešne zmazaná.", + "description" => "Modul pre správu kategórií a kategorizovanie obsahu", + "edit" => "Upraviť kategóriu", + "fields" => ["description" => "Popis", + "module" => "Modul", + "name" => "Názov", + "parentCategory" => "Rodičovská kategória", + "save" => "Uložiť kategóriu", + "url" => "URL", + ], + "module" => "Modul", + "name" => "Kategórie", + "new" => "Nová kategória", + "noCategories" => "Žiadne kategórie nie sú dostupné.", + "overview" => "Všetky kategórie", + "saveSuccessfull" => "Kategória úspešne uložená.", +]; diff --git a/Resources/views/admin/edit.blade.php b/Resources/views/admin/edit.blade.php new file mode 100755 index 0000000..9f2c69a --- /dev/null +++ b/Resources/views/admin/edit.blade.php @@ -0,0 +1,7 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('categories::categories.edit')) + +@section('content') + @include('categories::admin.form', ['action' => route('categories.postEdit', ['id' => $category->id])]) +@endsection \ No newline at end of file diff --git a/Resources/views/admin/form.blade.php b/Resources/views/admin/form.blade.php new file mode 100755 index 0000000..9e744f2 --- /dev/null +++ b/Resources/views/admin/form.blade.php @@ -0,0 +1,67 @@ +
+ {!! csrf_field() !!} +
+
+ + + +
+
+ + + + +
+
+
+ +
+
+
+ + + + + +
+
+ + + +
+
+ @if(count($categories)) + + + + @endif +
+
+ + +
\ No newline at end of file diff --git a/Resources/views/admin/new.blade.php b/Resources/views/admin/new.blade.php new file mode 100755 index 0000000..12cae2a --- /dev/null +++ b/Resources/views/admin/new.blade.php @@ -0,0 +1,7 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('categories::categories.new')) + +@section('content') + @include('categories::admin.form', ['action' => route('categories.postNew')]) +@endsection \ No newline at end of file diff --git a/Resources/views/admin/overview.blade.php b/Resources/views/admin/overview.blade.php new file mode 100644 index 0000000..e11ed7b --- /dev/null +++ b/Resources/views/admin/overview.blade.php @@ -0,0 +1,35 @@ +@extends('admin.layoutWithNavigation') + +@section('pageHeading', trans('categories::categories.overview')) + +@section('content') + +
+
+ + @if(count($categories)) +
+ + + + + + + + + + + @foreach($categories as $category) + @include('categories::admin.snippets.overviewRow', ['level' => 0, 'currentCategory' => $category]) + @endforeach + +
@lang('categories::categories.name')@lang('categories::categories.module')@lang('categories::categories.actions')
+
+ @else +
+ @lang('categories::categories.noCategories') +
+ @endif +
+
+@stop \ No newline at end of file diff --git a/Resources/views/admin/snippets/optionParentCategories.blade.php b/Resources/views/admin/snippets/optionParentCategories.blade.php new file mode 100755 index 0000000..aee0f61 --- /dev/null +++ b/Resources/views/admin/snippets/optionParentCategories.blade.php @@ -0,0 +1,9 @@ + + +@if(isset($currentCategory['children'])) + @foreach($currentCategory['children'] as $category) + @include('categories::admin.snippets.optionParentCategories', ['selectedCategory' => $selectedCategory, 'currentCategory' => $category, 'level' => $level+1]) + @endforeach +@endif \ No newline at end of file diff --git a/Resources/views/admin/snippets/overviewRow.blade.php b/Resources/views/admin/snippets/overviewRow.blade.php new file mode 100644 index 0000000..f92a53f --- /dev/null +++ b/Resources/views/admin/snippets/overviewRow.blade.php @@ -0,0 +1,39 @@ + + + {{str_repeat('-', $level)}} {{$currentCategory['name']}} + + @lang($modules[$currentCategory['module_id']]) + +
+ + + + + + + + +
+
    + +
  • + +
  • +
  • + +
  • +
+
+
+ + + + +@if(isset($currentCategory['children'])) + @foreach($currentCategory['children'] as $category) + @include('categories::admin.snippets.overviewRow', ['currentCategory' => $category, 'level' => $level+1]) + @endforeach +@endif \ No newline at end of file diff --git a/start.php b/start.php new file mode 100755 index 0000000..7d8ae75 --- /dev/null +++ b/start.php @@ -0,0 +1,15 @@ +