From 4f6a006ad9746dca27acbdc7bc4d7f8bce6ee138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 18 Oct 2016 22:35:06 +0200 Subject: [PATCH] FEATURE: add another repositories --- .../Content/AdvancedContentModifier.php | 40 +++++++ .../Contracts/{ => Modules}/AppHandler.php | 47 +------- .../{ => Modules}/BaseModuleHandler.php | 9 +- .../Contracts/Modules/InstallableModule.php | 23 ++++ .../{ => Modules}/TemplateHandler.php | 12 +- app/CMS/Contracts/Repositories/Module.php | 6 +- app/CMS/Contracts/Repositories/Template.php | 18 +++ app/CMS/Handlers/BaseHandler.php | 7 +- app/CMS/Handlers/Handler.php | 23 +--- .../Registrators/TemplateRegistrator.php | 2 +- app/CMS/Helpers/Template.php | 4 +- .../Admin/Content/ChangeStatus.php | 0 .../Interactions/Admin/Content/DeletePage.php | 0 .../Admin/Content/EditContent.php | 9 +- .../Admin/Content/SetHomepage.php | 0 .../Admin/Content/UploadRelatedFiles.php | 0 .../Admin/Content/UploadTitlePhoto.php | 0 .../Admin/FileManager/CreateDirectory.php | 0 .../Admin/FileManager/DeleteFile.php | 0 .../Admin/FileManager/EditDirectory.php | 0 .../FileManager/EditFileMetaInformation.php | 0 .../Admin/FileManager/UploadFile.php | 0 .../Admin/FileManager/UploadFileRevision.php | 0 app/CMS/Repositories/Content/Content.php | 11 +- app/CMS/Repositories/Module.php | 37 +++++-- .../Repositories/Templates}/Template.php | 48 ++++---- .../Admin/Contents/CreateNewContent.php | 73 +++++-------- .../Admin/Contents/EditContent.php | 73 +++++++------ app/Http/routes/admin/contents.php | 6 +- app/Models/Content/Content.php | 4 +- app/Models/Templates/Template.php | 16 +-- app/Models/Templates/TemplatePath.php | 3 - app/Providers/AppServiceProvider.php | 3 + modules/Blog/Article/Handlers/Article.php | 68 +++++++++--- .../Contracts/Repositories/Category.php | 9 ++ modules/Categories/Entities/Category.php | 2 +- .../Categories/Entities/CategoryClosure.php | 2 +- .../Entities/CategoryClosureInterface.php | 8 -- .../Categories/Entities/CategoryInterface.php | 7 -- modules/Categories/Handlers/Categories.php | 26 +---- .../Providers/CategoriesServiceProvider.php | 12 +- modules/Categories/Repositories/Category.php | 22 ++++ modules/ContactForm/Handlers/ContactForm.php | 58 ++++++---- modules/StaticPages/Handlers/StaticPage.php | 103 ++++-------------- resources/views/admin/content/new.blade.php | 2 +- .../views/admin/content/overview.blade.php | 6 +- templates/Base/OnePage/Handlers/OnePage.php | 11 +- 47 files changed, 410 insertions(+), 400 deletions(-) create mode 100644 app/CMS/Contracts/Content/AdvancedContentModifier.php rename app/CMS/Contracts/{ => Modules}/AppHandler.php (53%) rename app/CMS/Contracts/{ => Modules}/BaseModuleHandler.php (61%) create mode 100644 app/CMS/Contracts/Modules/InstallableModule.php rename app/CMS/Contracts/{ => Modules}/TemplateHandler.php (84%) create mode 100644 app/CMS/Contracts/Repositories/Template.php create mode 100644 app/CMS/Interactions/Admin/Content/ChangeStatus.php create mode 100644 app/CMS/Interactions/Admin/Content/DeletePage.php create mode 100644 app/CMS/Interactions/Admin/Content/SetHomepage.php create mode 100644 app/CMS/Interactions/Admin/Content/UploadRelatedFiles.php create mode 100644 app/CMS/Interactions/Admin/Content/UploadTitlePhoto.php create mode 100644 app/CMS/Interactions/Admin/FileManager/CreateDirectory.php create mode 100644 app/CMS/Interactions/Admin/FileManager/DeleteFile.php create mode 100644 app/CMS/Interactions/Admin/FileManager/EditDirectory.php create mode 100644 app/CMS/Interactions/Admin/FileManager/EditFileMetaInformation.php create mode 100644 app/CMS/Interactions/Admin/FileManager/UploadFile.php create mode 100644 app/CMS/Interactions/Admin/FileManager/UploadFileRevision.php rename app/{Models/Templates/ModelTraits => CMS/Repositories/Templates}/Template.php (55%) create mode 100644 modules/Categories/Contracts/Repositories/Category.php delete mode 100644 modules/Categories/Entities/CategoryClosureInterface.php delete mode 100644 modules/Categories/Entities/CategoryInterface.php create mode 100644 modules/Categories/Repositories/Category.php diff --git a/app/CMS/Contracts/Content/AdvancedContentModifier.php b/app/CMS/Contracts/Content/AdvancedContentModifier.php new file mode 100644 index 00000000..eef8c9d7 --- /dev/null +++ b/app/CMS/Contracts/Content/AdvancedContentModifier.php @@ -0,0 +1,40 @@ + 'fa fa-fw fa-file-code-o']); } - - // $menu->dropdown(trans('admin/mainMenu.customFields'), function ($sub) { // $sub->route('customfields.new', trans('admin/mainMenu.customFieldsNew'), [], 10, ['icon' => 'fa fa-fw fa-code']); // $sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-fw fa-code-fork']); @@ -107,8 +104,6 @@ abstract class BaseHandler implements BaseModuleHandler $sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']); $sub->route('settings.overview', trans('admin/mainMenu.settings'), [], 80, ['icon' => 'fa fa-fw fa-gear']); }, 10000, ['icon' => 'fa fa-fw fa-gears']); - - }); // order diff --git a/app/CMS/Handlers/Handler.php b/app/CMS/Handlers/Handler.php index f480589a..1efd3656 100644 --- a/app/CMS/Handlers/Handler.php +++ b/app/CMS/Handlers/Handler.php @@ -1,7 +1,7 @@ 'admin.content.formParts.files' ]; } - - public static function delete(Content $content) - { - // temporarily nothing to do - } - - public static function loadExtraData(Content $content) { - // temporarily nothing to do - } - + public static function getExtendedFormInputsEdit() { return self::getExtendedFormInputsCreate(); diff --git a/app/CMS/Handlers/Registrators/TemplateRegistrator.php b/app/CMS/Handlers/Registrators/TemplateRegistrator.php index 040eb6c7..6937fb7d 100644 --- a/app/CMS/Handlers/Registrators/TemplateRegistrator.php +++ b/app/CMS/Handlers/Registrators/TemplateRegistrator.php @@ -3,7 +3,7 @@ namespace App\CMS\Handlers\Registrators; use App\CMS\Enumerations\TemplatePaths; use App\CMS\Enumerations\Templates; -use App\Models\Templates\Template; +use App\CMS\Contracts\Repositories\Template; use App\Models\Templates\TemplatePath; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; diff --git a/app/CMS/Helpers/Template.php b/app/CMS/Helpers/Template.php index a19f1acb..26080194 100644 --- a/app/CMS/Helpers/Template.php +++ b/app/CMS/Helpers/Template.php @@ -9,7 +9,9 @@ class Template /** * Getter for real template name * - * @param $template + * @param $template + * + * @param bool $throwExceptions * * @return null|string */ diff --git a/app/CMS/Interactions/Admin/Content/ChangeStatus.php b/app/CMS/Interactions/Admin/Content/ChangeStatus.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/Content/DeletePage.php b/app/CMS/Interactions/Admin/Content/DeletePage.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/Content/EditContent.php b/app/CMS/Interactions/Admin/Content/EditContent.php index b2d3a1de..5629b759 100644 --- a/app/CMS/Interactions/Admin/Content/EditContent.php +++ b/app/CMS/Interactions/Admin/Content/EditContent.php @@ -16,6 +16,7 @@ class EditContent implements Interaction $page = $parameters[0]; // upload file - if provided + // todo use interaction $file = $page->uploadTitlePhoto($request); // let template to modify request and content page @@ -52,13 +53,17 @@ class EditContent implements Interaction // todo move this method out of the controller! $data = \App\Http\Controllers\Admin\Contents\EditContent::getFields($request, array_values($fields)); + // todo use Model Observer and model::original attributes + list($revision, $changedColumns) = $page->updateWithHistory($fields, $data); $changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]); + + + // move to interaction $changedColumns += $page->uploadRelatedFiles($request, $revision); - if ($changedColumns > 0) // fire event with - { + if ($changedColumns > 0) { Event::fire(new EditContentEvent($page, $revision)); } diff --git a/app/CMS/Interactions/Admin/Content/SetHomepage.php b/app/CMS/Interactions/Admin/Content/SetHomepage.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/Content/UploadRelatedFiles.php b/app/CMS/Interactions/Admin/Content/UploadRelatedFiles.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/Content/UploadTitlePhoto.php b/app/CMS/Interactions/Admin/Content/UploadTitlePhoto.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/CreateDirectory.php b/app/CMS/Interactions/Admin/FileManager/CreateDirectory.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/DeleteFile.php b/app/CMS/Interactions/Admin/FileManager/DeleteFile.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/EditDirectory.php b/app/CMS/Interactions/Admin/FileManager/EditDirectory.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/EditFileMetaInformation.php b/app/CMS/Interactions/Admin/FileManager/EditFileMetaInformation.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/UploadFile.php b/app/CMS/Interactions/Admin/FileManager/UploadFile.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Interactions/Admin/FileManager/UploadFileRevision.php b/app/CMS/Interactions/Admin/FileManager/UploadFileRevision.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Repositories/Content/Content.php b/app/CMS/Repositories/Content/Content.php index 3d2a0a2e..da08eeeb 100644 --- a/app/CMS/Repositories/Content/Content.php +++ b/app/CMS/Repositories/Content/Content.php @@ -14,7 +14,7 @@ class Content extends Repository implements IContent /** * @var ContentModel */ - private $model; + protected $model; public function __construct(ContentModel $model) { @@ -54,9 +54,16 @@ class Content extends Repository implements IContent $page = new ContentModel(); $page->user_id = \Auth::user()->id; $page->language = LaravelLocalization::getCurrentLocale(); + $page->status = IContent::STATUS_DRAFT; $page->module_settings = []; } else { - $page = $this->model->find($id); + if (is_numeric($id)) { + $page = $this->model->findOrFail($id); + } else { + $page = $this->model->where('language', LaravelLocalization::getCurrentLocale()) + ->where('url', $id) + ->firstOrFail(); + } $page->module_settings = json_decode($page->module_settings); } diff --git a/app/CMS/Repositories/Module.php b/app/CMS/Repositories/Module.php index a31e62e5..3da714f7 100644 --- a/app/CMS/Repositories/Module.php +++ b/app/CMS/Repositories/Module.php @@ -6,25 +6,42 @@ use App\Models\Module as ModuleModel; class Module extends Repository implements IModule { - public function getOne($id = null) { + /** + * @var ModuleModel + */ + private $module; + + public function __construct(ModuleModel $module) + { + $this->module = $module; + } + + public function getOne($id = null) + { if (!is_null($id)) { - return ModuleModel::find($id); + + if (is_numeric($id)) { + return ModuleModel::findOrFail($id); + } else { + return ModuleModel::where('alias', $id) + ->firstOrFail(); + } } else { return new ModuleModel(); } } - public function supportsCategories() + public function getCreateContentTitle(ModuleModel $module) { - // TODO: Implement supportsCategories() method. + $pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]); + if (is_callable([$module->handler, 'getCreateNewTitle'])) { + $pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']); + } + + return $pageHeading; } - public function getCreateContentTitle() - { - // TODO: Implement getCreateContentTitle() method. - } - - public function getUpdateContentTitle() + public function getUpdateContentTitle(ModuleModel $module) { // TODO: Implement getUpdateContentTitle() method. } diff --git a/app/Models/Templates/ModelTraits/Template.php b/app/CMS/Repositories/Templates/Template.php similarity index 55% rename from app/Models/Templates/ModelTraits/Template.php rename to app/CMS/Repositories/Templates/Template.php index 769bb01a..310b0ec5 100644 --- a/app/Models/Templates/ModelTraits/Template.php +++ b/app/CMS/Repositories/Templates/Template.php @@ -1,26 +1,16 @@ pathModel) { - $this->pathModel = TemplatePath::where('id', $this->path) - ->first(); - } - - return $this->pathModel; + $this->model = $model; } /** @@ -32,11 +22,11 @@ trait Template { */ public function getPathToTemplate($mode = null) { - $templateName = $this->template_name; - $path = $this->getPath(); + $templateName = $this->model->template_name; + $path = $this->model->path()->get(); // delete namespace if given - if (strpos($this->template_name, '::')) { + if (strpos($this->model->template_name, '::')) { list(, $templateName) = explode('::', $templateName); } @@ -50,24 +40,24 @@ trait Template { // path parts $absolutePath = base_path($path->path); $templatePath = str_replace('.', $_, $templateName); - $file = $templatePath . TemplateModel::TEMPLATE_SUFFIX; + $file = $templatePath . ITemplate::TEMPLATE_SUFFIX; // compose two versions of path - original and with "custom" directory $original = $absolutePath . $_ . $file; - $edited = $absolutePath . $_ . TemplateModel::EDITED_TEMPLATES_DIRECTORY . $_ . $file; + $edited = $absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file; // decide which path will be returned switch ($mode) { - case TemplateModel::CUSTOM_EDIT_DIRECTORY: + case ITemplate::CUSTOM_EDIT_DIRECTORY: return $edited; break; - case TemplateModel::ORIGINAL_DIRECTORY: + case ITemplate::ORIGINAL_DIRECTORY: return $original; break; default: - if (file_exists($absolutePath . $_ . TemplateModel::EDITED_TEMPLATES_DIRECTORY . $_ . $file)) { + if (file_exists($absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file)) { return $edited; } @@ -75,4 +65,10 @@ trait Template { break; } } + + public function getForModule(Module $module) { + return Template::where('module_id', $module->id) + ->select(['template_name', 'name', 'description']) + ->get(); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Admin/Contents/CreateNewContent.php b/app/Http/Controllers/Admin/Contents/CreateNewContent.php index dac734a4..d9e6fb02 100644 --- a/app/Http/Controllers/Admin/Contents/CreateNewContent.php +++ b/app/Http/Controllers/Admin/Contents/CreateNewContent.php @@ -3,17 +3,14 @@ namespace App\Http\Controllers\Admin\Contents; use App\CMS\Contracts\Repositories\Content as IContent; use App\CMS\Contracts\Repositories\Module as IModuleRepository; +use App\CMS\Contracts\Repositories\Template as ITemplate; +use Modules\Categories\Contracts\Repositories\Category as ICategory; use App\CMS\Enumerations\ContentStatuses; use App\Cms\Handlers\Interactions\Interaction; use App\Cms\Interactions\Admin\Content\NewContent; use App\Http\Controllers\Admin\Controller; use App\Http\Requests\CreateNewContentRequest; use App\Http\Requests\Request; -use App\Models\FileManager\File; -use App\Models\Module; -use App\Models\Templates\Template; -use Modules\Categories\Entities\Category; -use Pingpong\Modules\Facades\Module as ModuleInstance; /** * Class CreateNewContent @@ -24,10 +21,6 @@ use Pingpong\Modules\Facades\Module as ModuleInstance; */ class CreateNewContent extends Controller { - /** - * @var File - */ - private $file; /** * @var IContent */ @@ -36,71 +29,63 @@ class CreateNewContent extends Controller * @var IModuleRepository */ private $module; + /** + * @var ICategory + */ + private $category; + /** + * @var ITemplate + */ + private $template; /** * CreateNewContent constructor. * * Sets File and Content models into class variables * - * @param File $file - * @param Content $content + * @param IContent|Content $content * @param IModuleRepository $module + * @param ICategory $category + * + * @param ITemplate $template + * + * @internal param File $file */ - public function __construct(File $file, IContent $content, IModuleRepository $module) + public function __construct(IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template) { parent::__construct(); - $this->file = $file; $this->content = $content; $this->module = $module; + $this->category = $category; + $this->template = $template; } /** * Display form for new content page * - * @param $moduleId + * @param $module * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function create($moduleId) + public function create($module) { - $module = Module::findOrFail($moduleId); + $module = $this->module->getOne($module); $statuses = ContentStatuses::getWithTranslations(); + $pageHeading = $this->module->getCreateContentTitle($module); + $templates = $this->template->getForModule($module); + $categories = $this->category->getForModule($module); - // set default page title - $pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]); - if (is_callable([$module->handler, 'getCreateNewTitle'])) { - $pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']); - } - - // get list of usable templates - $templates = Template::where('module_id', $moduleId) - ->select(['template_name', 'name', 'description']) - ->get(); - - // add categories, if supported - $categoryModule = ModuleInstance::get('categories'); - $categories = []; - if ($module->support_categories && !is_null($categoryModule) && $categoryModule->enabled()) { - $categories = Category::where('module_id', $moduleId) - ->get(); - } - - // create default content object - $this->content->status = IContent::STATUS_DRAFT; + $page = $this->content->getOne(); // render view return view('admin.content.new', [ 'pageHeading' => $pageHeading, 'contentStatuses' => $statuses, 'templates' => $templates, - 'moduleId' => $moduleId, 'module' => $module, 'categories' => $categories, - 'page' => $this->content, - 'rootPages' => $this->content->getOverview() - ->get(), - 'moduleName' => trans($module->name), - 'extraData' => call_user_func([$module->handler, 'loadExtraData'], $this->content), + 'page' => $page, + 'rootPages' => $this->content->getOverview(), 'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']), 'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']), ]); @@ -116,7 +101,7 @@ class CreateNewContent extends Controller */ public function store(Request $request, $moduleId) { - $module = Module::findOrFail($moduleId); + $module = $this->module->getOne($moduleId); // create new page Interaction::handle($request, new NewContent(), $module->handler); diff --git a/app/Http/Controllers/Admin/Contents/EditContent.php b/app/Http/Controllers/Admin/Contents/EditContent.php index 2bc7a092..90f2c515 100644 --- a/app/Http/Controllers/Admin/Contents/EditContent.php +++ b/app/Http/Controllers/Admin/Contents/EditContent.php @@ -18,6 +18,10 @@ use Illuminate\Support\Facades\Event; use Modules\Categories\Entities\Category; use Pingpong\Modules\Facades\Module as ModuleInstance; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use App\CMS\Contracts\Repositories\Content as IContent; +use App\CMS\Contracts\Repositories\Module as IModuleRepository; +use App\CMS\Contracts\Repositories\Template as ITemplate; +use Modules\Categories\Contracts\Repositories\Category as ICategory; class EditContent extends Controller { @@ -29,66 +33,70 @@ class EditContent extends Controller * @var File */ private $file; + /** + * @var IContent + */ + private $content; + /** + * @var IModuleRepository + */ + private $module; + /** + * @var ICategory + */ + private $category; + /** + * @var ITemplate + */ + private $template; /** * EditContent constructor. * * Load ContentHistory and File into this controller * - * @param ContentHistory $history - * @param File $file + * @param ContentHistory $history + * @param File $file + * @param IContent $content + * @param IModuleRepository $module + * @param ICategory $category + * @param ITemplate $template */ - public function __construct(ContentHistory $history, File $file) + public function __construct(ContentHistory $history, File $file, IContent $content, IModuleRepository $module, ICategory $category, ITemplate $template) { $this->history = $history; $this->file = $file; + $this->content = $content; + $this->module = $module; + $this->category = $category; + $this->template = $template; } /** * Display form for editing static page * - * @param $id + * @param $url * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function edit($id) + public function edit($url) { - // select all content statuses $statuses = ContentStatuses::getWithTranslations(); - - // try to find requested page - $page = Content::findOrFail($id); - $page->module_settings = json_decode($page->module_settings); + $page = $this->content->getOne($url); // get module ID $module = Module::where('handler', $page->module_handler) ->firstOrFail(); - $pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]); - if (is_callable([$module->handler, 'getEditTitle'])) { - $pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page); - } + $pageHeading = $this->module->getUpdateContentTitle($module); + $templates = $this->template->getForModule($module); + $categories = $this->category->getForModule($module); + $history = $this->history->getStructuredHistoryOf($page); - // get all Blade templates for rendering page - $templates = Template::where('module_id', $module->id) - ->select(['template_name', 'name', 'description']) - ->get(); - - // get module for Categories - PingPong module - $categoryModule = ModuleInstance::get('categories'); - - // add categories, if supported - $categories = []; - if ($module->support_categories && !is_null($categoryModule) && $categoryModule->enabled()) { - $categories = Category::where('module_id', $module->id) - ->get(); - } // modify data for edit form according to installed template call_user_func_array([CurrentTemplate::handler(), 'beforePopulatingEditForm'], [&$page]); - $history = $this->history->getStructuredHistoryOf($page); - // render view return view('admin.content.edit', [ 'pageHeading' => $pageHeading, @@ -96,11 +104,8 @@ class EditContent extends Controller 'page' => $page, 'module' => $module, 'categories' => $categories, - 'rootPages' => $page->getOverview() - ->where('contents.id', '!=', $page->id) - ->get(), + 'rootPages' => $this->content->getOverview(), 'templates' => $templates, - 'extraData' => call_user_func([$page->module_handler, 'loadExtraData'], $page), 'formSectionNames' => call_user_func([$page->module_handler, 'getExtendedFormSections']), 'formSections' => call_user_func([$page->module_handler, 'getExtendedFormInputsEdit']), 'historySize' => count($history['changesets']) diff --git a/app/Http/routes/admin/contents.php b/app/Http/routes/admin/contents.php index 20a2fe81..712cb998 100644 --- a/app/Http/routes/admin/contents.php +++ b/app/Http/routes/admin/contents.php @@ -1,15 +1,15 @@ 'Contents'], function () { // list of all static pages - Route::get('content/overview/{moduleId?}/{status?}', 'ContentOverview@index') + Route::get('content/overview/{module?}', 'ContentOverview@index') ->name('content.overview'); // form for creating new static page - Route::get('content/new/{moduleId}', 'CreateNewContent@create') + Route::get('content/new/{module}', 'CreateNewContent@create') ->name('content.new'); // form for editing existing static page - Route::get('content/edit/{id}', 'EditContent@edit') + Route::get('content/edit/{url}', 'EditContent@edit') ->name('content.edit'); // post method for creating new static page diff --git a/app/Models/Content/Content.php b/app/Models/Content/Content.php index 35ae6a49..93d1e5f7 100644 --- a/app/Models/Content/Content.php +++ b/app/Models/Content/Content.php @@ -2,8 +2,6 @@ namespace App\Models\Content; -use App\Events\CreateNewContent; -use App\Events\Event; use App\Models\FileManager\File; use App\Models\User; use Illuminate\Database\Eloquent\Model; @@ -44,7 +42,7 @@ class Content extends Model */ public function history() { - return $this->hasMany(\App\Models\Content\ContentHistory::class); + return $this->hasMany(ContentHistory::class); } /** diff --git a/app/Models/Templates/Template.php b/app/Models/Templates/Template.php index ed43dd63..129e778f 100644 --- a/app/Models/Templates/Template.php +++ b/app/Models/Templates/Template.php @@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Model; class Template extends Model { - use ModelTraits\Template; public $timestamps = true; protected $fillable = [ 'template_name', @@ -16,10 +15,13 @@ class Template extends Model 'description', 'editable' ]; - const EDITED_TEMPLATES_DIRECTORY = 'custom'; - const ASSETS_DIRECTORY = 'assets'; - const MODULES_DIRECTORY = 'modules'; - const TEMPLATE_SUFFIX = '.blade.php'; - const CUSTOM_EDIT_DIRECTORY = 1; - const ORIGINAL_DIRECTORY = 2; + + /** + * Template path where this template is stored + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function path() { + return $this->belongsTo(TemplatePath::class, 'path'); + } } \ No newline at end of file diff --git a/app/Models/Templates/TemplatePath.php b/app/Models/Templates/TemplatePath.php index 2fec2de6..4ba09508 100644 --- a/app/Models/Templates/TemplatePath.php +++ b/app/Models/Templates/TemplatePath.php @@ -4,9 +4,6 @@ namespace App\Models\Templates; use Illuminate\Database\Eloquent\Model; -/** - * Class CustomFieldType - */ class TemplatePath extends Model { public $timestamps = true; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index fa711848..f5b55649 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,6 +4,7 @@ namespace App\Providers; use App\CMS\Contracts\Repositories\Content as IContent; use App\CMS\Contracts\Repositories\Module as IModule; +use App\CMS\Contracts\Repositories\Template as ITemplate; use App\CMS\Handlers\Registrators\SearchEngineRegistrator; use App\CMS\Handlers\Registrators\SettingsExtensionRegistrator; use App\CMS\Handlers\Registrators\TemplateRegistrator; @@ -14,6 +15,7 @@ use App\CMS\Handlers\Search\Presenters\AdminContent as AdminContentPresenter; use App\CMS\Handlers\Search\Presenters\AdminFiles; use App\CMS\Repositories\Content\Content as ContentRepository; use App\CMS\Repositories\Module as ModuleRepository; +use App\CMS\Repositories\Templates\Template as TemplateRepository; use App\CMS\Widgets\HtmlCode\HtmlCode; use App\CMS\Widgets\Menu\Menu; use Barryvdh\Debugbar\ServiceProvider as DebugBarServiceProvider; @@ -41,6 +43,7 @@ class AppServiceProvider extends ServiceProvider $this->app->bind(IContent::class, ContentRepository::class); $this->app->bind(IModule::class, ModuleRepository::class); + $this->app->bind(ITemplate::class, TemplateRepository::class); } /** diff --git a/modules/Blog/Article/Handlers/Article.php b/modules/Blog/Article/Handlers/Article.php index d6286a19..123d5a5c 100644 --- a/modules/Blog/Article/Handlers/Article.php +++ b/modules/Blog/Article/Handlers/Article.php @@ -1,18 +1,20 @@ dropdown(trans('article::module.name'), function ($sub) { - $sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']); - $sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']); + $sub->route('content.new', trans('article::article.new'), ['id' => config('article.alias')], 10, ['icon' => 'fa fa-fw fa-pencil']); + $sub->route('content.overview', trans('article::article.overview'), ['id' => config('article.alias')], 30, ['icon' => 'fa fa-fw fa-book']); }, 10, ['icon' => 'fa fa-fw fa-book']); $blogSubmenu->route('comments.overview', trans('article::module.commentsOverview'), [], 20, ['icon' => 'fa fa-fw fa-commenting-o']); } - public static function getModuleId() - { - $handler = config('article.handler'); - $allModules = ModulesHandlerToId::getWithTranslations(); - $moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null; - - return $moduleId; - } - /** * Install module */ @@ -153,6 +146,19 @@ class Article extends Handler implements ContentTitles } } + /** + * Uninstalls module + * + * @param Module $module + * + * @return mixed|void + */ + public static function uninstall(Module $module) + { + ActionLogType::whereIn('string_id', ['commentCreated', 'commentDeleted', 'commentApproved']) + ->delete(); + } + /** * Get translated title for pages overview of given type. * @@ -186,4 +192,38 @@ class Article extends Handler implements ContentTitles { return trans('article::module.editArticle'); } + + /** + * Method called right after content page is marked as deleted + * + * This method is supposed to clean after "deleted" page. + * + * @param Content $content + * + * @return mixed + */ + public static function delete(Content $content) + { + } + + /** + * Load some extra data for content management form? + * + * @param Content $content + * + * @return mixed + */ + public static function loadExtraData(Content $content) + { + } + + /** + * Does this module support categories? + * + * @return boolean + */ + public static function supportCategories() + { + return true; + } } \ No newline at end of file diff --git a/modules/Categories/Contracts/Repositories/Category.php b/modules/Categories/Contracts/Repositories/Category.php new file mode 100644 index 00000000..ea344d3d --- /dev/null +++ b/modules/Categories/Contracts/Repositories/Category.php @@ -0,0 +1,9 @@ +dropdown(trans('categories::categories.name'), function ($sub) { @@ -35,14 +23,4 @@ class Categories extends BaseHandler $sub->route('categories.overview', trans('categories::categories.overview'), [], 30, ['icon' => 'fa fa-fw fa-tags']); }, 55, ['icon' => 'fa fa-fw fa-tags']); } - - /** - * Install module - * - * @return mixed - */ - public static function install() - { - // nothing to install - } } \ No newline at end of file diff --git a/modules/Categories/Providers/CategoriesServiceProvider.php b/modules/Categories/Providers/CategoriesServiceProvider.php index 4f70a624..970fcc57 100644 --- a/modules/Categories/Providers/CategoriesServiceProvider.php +++ b/modules/Categories/Providers/CategoriesServiceProvider.php @@ -1,6 +1,9 @@ -alias = 'categories'; } + public function boot() + { + parent::boot(); + + $this->app->bind(ICategory::class, Category::class); + } + protected function setModulePath() { $this->path = __DIR__; diff --git a/modules/Categories/Repositories/Category.php b/modules/Categories/Repositories/Category.php new file mode 100644 index 00000000..d7c2a452 --- /dev/null +++ b/modules/Categories/Repositories/Category.php @@ -0,0 +1,22 @@ +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/modules/ContactForm/Handlers/ContactForm.php b/modules/ContactForm/Handlers/ContactForm.php index 34284a1a..3e114f0d 100644 --- a/modules/ContactForm/Handlers/ContactForm.php +++ b/modules/ContactForm/Handlers/ContactForm.php @@ -1,6 +1,7 @@ whereTitle(trans('admin/mainMenu.contentPages')); $submenu->dropdown(trans('staticpages::adminMenu.staticPages'), function ($submenu) use ($user) { - $submenu->route('content.new', trans('staticpages::adminMenu.new'), ['moduleId' => self::getModuleId()], 10, ['icon' => 'fa fa-plus']); - $submenu->route('content.overview', trans('staticpages::adminMenu.overview'), ['moduleId' => self::getModuleId()], 20, ['icon' => 'fa fa-list']); + $submenu->route('content.new', trans('staticpages::adminMenu.new'), ['module' => config('staticpages.alias')], 10, ['icon' => 'fa fa-plus']); + $submenu->route('content.overview', trans('staticpages::adminMenu.overview'), ['module' => config('staticpages.alias')], 20, ['icon' => 'fa fa-list']); }, 15, ['icon' => 'fa fa-newspaper-o']); } - public static function getModuleId() - { - $handler = config('staticpages.handler'); - $allModules = ModulesHandlerToId::getWithTranslations(); - $moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null; - - return $moduleId; - } - - /** - * Does given module manage content? Or is it just module with widgets/something internal/something absolutely else? - * - * @return bool - */ - public static function managesContent() - { - return true; - } - - /** - * Save module-specific values into database - * - * @param Content $content - * @param Request $request - * - * @return mixed - */ - public static function createNew(Content &$content, Request $request) - { - // There is nothing more we can save. Static pages are only text saved into database. - // This funcionality is already covered in saving content page alone. - } - - /** - * Method used for editing existing content page. - * - * Reason why it is separated from createNew() method is simple - we need to save history of changes. - * - * @param Content $content - * @param Request $request - * @param string $revisionId - * - * @return mixed - */ - public static function edit(Content &$content, Request $request, $revisionId) - { - // There is nothing more we can save. Static pages are only text saved into database. - // This funcionality is already covered in saving content page alone. - - return 0; - } - - /** - * Install module - * - * @return mixed - */ - public static function install() - { - // nothing to do - } - - /** - * Load some extra data for content management form? - * - * @param Content $content - * - * @return mixed - */ - public static function loadExtraData(Content $content) - { - // nothing to do - } - - /** * Get translated title for pages overview of given type. * @@ -133,4 +54,24 @@ class StaticPage extends Handler implements ContentTitles { return trans('staticpages::module.editPage'); } + + /** + * Does given module manage content? Or is it just module with widgets/something internal/something absolutely else? + * + * @return bool + */ + public static function managesContent() + { + return true; + } + + /** + * Does this module support categories? + * + * @return boolean + */ + public static function supportCategories() + { + return true; + } } \ No newline at end of file diff --git a/resources/views/admin/content/new.blade.php b/resources/views/admin/content/new.blade.php index c7eff0df..fc2a5996 100644 --- a/resources/views/admin/content/new.blade.php +++ b/resources/views/admin/content/new.blade.php @@ -10,7 +10,7 @@ @endif -
+ {!! csrf_field() !!} @include('admin.content.formInputs') diff --git a/resources/views/admin/content/overview.blade.php b/resources/views/admin/content/overview.blade.php index 697f6970..1ffb0519 100644 --- a/resources/views/admin/content/overview.blade.php +++ b/resources/views/admin/content/overview.blade.php @@ -34,7 +34,7 @@ @foreach($pages as $page)
- + {{$page->title}} @@ -92,7 +92,7 @@ @endif
  • - diff --git a/templates/Base/OnePage/Handlers/OnePage.php b/templates/Base/OnePage/Handlers/OnePage.php index 141320ce..4a9e8043 100644 --- a/templates/Base/OnePage/Handlers/OnePage.php +++ b/templates/Base/OnePage/Handlers/OnePage.php @@ -1,24 +1,25 @@