FEATURE: add another repositories
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Content;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
interface AdvancedContentModifier {
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function createNew(Content &$content, Request $request);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
@@ -18,51 +18,6 @@ interface AppHandler extends BaseModuleHandler
|
||||
|
||||
public static function getHistoryHandler();
|
||||
|
||||
/**
|
||||
* Load some extra data for content management form?
|
||||
*
|
||||
* @param Content $content
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function loadExtraData(Content $content);
|
||||
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
*
|
||||
* @return mixed
|
||||
* @internal param Widget $widget
|
||||
*/
|
||||
public static function createNew(Content &$content, Request $request);
|
||||
|
||||
/**
|
||||
* 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 $revisionID string ID of revision used
|
||||
*
|
||||
* @return int number of edited fields
|
||||
*/
|
||||
public static function edit(Content &$content, Request $request, $revisionID);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* Getter for section names in creating/editing content resource
|
||||
*
|
||||
+1
-8
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
@@ -15,11 +15,4 @@ interface BaseModuleHandler
|
||||
*/
|
||||
public static function registerAdminMenu(User $user);
|
||||
|
||||
/**
|
||||
* Install module.
|
||||
*
|
||||
* This method is called after inserting info about module into database. It can be called only using Artisan in
|
||||
* CLI.
|
||||
*/
|
||||
public static function install();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Models\Module;
|
||||
|
||||
interface InstallableModule {
|
||||
/**
|
||||
* Install module.
|
||||
*
|
||||
* This method is called after inserting info about module into database. It can be called only using Artisan in
|
||||
* CLI.
|
||||
*/
|
||||
public static function install();
|
||||
|
||||
/**
|
||||
* Uninstalls module
|
||||
*
|
||||
* @param Module $module
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function uninstall(Module $module);
|
||||
}
|
||||
+1
-11
@@ -1,9 +1,8 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Contracts;
|
||||
namespace App\CMS\Contracts\Modules;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\Module;
|
||||
|
||||
/**
|
||||
* Interface TemplateHandler
|
||||
@@ -14,15 +13,6 @@ use App\Models\Module;
|
||||
*/
|
||||
interface TemplateHandler extends BaseModuleHandler
|
||||
{
|
||||
/**
|
||||
* Uninstall template
|
||||
*
|
||||
* Delete some items in database, delete files etc.
|
||||
*
|
||||
* @param Module $template
|
||||
*/
|
||||
public static function uninstall(Module $template);
|
||||
|
||||
/**
|
||||
* Get list of registered templates and supported modules.
|
||||
*
|
||||
@@ -3,11 +3,9 @@ namespace App\CMS\Contracts\Repositories;
|
||||
|
||||
interface Module extends BaseRepository {
|
||||
|
||||
public function supportsCategories();
|
||||
public function getCreateContentTitle(\App\Models\Module $module);
|
||||
|
||||
public function getCreateContentTitle();
|
||||
|
||||
public function getUpdateContentTitle();
|
||||
public function getUpdateContentTitle(\App\Models\Module $module);
|
||||
|
||||
public function getOverviewTitle(\App\Models\Module $module);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace App\CMS\Contracts\Repositories;
|
||||
|
||||
use App\Models\Module as ModuleModel;
|
||||
|
||||
interface Template
|
||||
{
|
||||
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;
|
||||
|
||||
public function getPathToTemplate();
|
||||
|
||||
public function getForModule(ModuleModel $module);
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers;
|
||||
|
||||
use App\CMS\Contracts\Modules\BaseModuleHandler;
|
||||
use App\CMS\Enumerations\TemplatePathsHumanReadableRootOnly;
|
||||
use App\CMS\Enumerations\WidgetTypes;
|
||||
use App\CMS\Handlers\Contracts\AppHandler;
|
||||
use App\CMS\Handlers\Contracts\BaseModuleHandler;
|
||||
use App\Models\User;
|
||||
|
||||
abstract class BaseHandler implements BaseModuleHandler
|
||||
@@ -97,8 +96,6 @@ abstract class BaseHandler implements BaseModuleHandler
|
||||
}, 60, ['icon' => '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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers;
|
||||
|
||||
use App\CMS\Handlers\Contracts\AppHandler;
|
||||
use App\CMS\Contracts\Modules\AppHandler;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Content\Content;
|
||||
|
||||
@@ -15,16 +15,6 @@ use App\Models\Content\Content;
|
||||
*/
|
||||
abstract class Handler extends BaseHandler implements AppHandler
|
||||
{
|
||||
/**
|
||||
* todo: Temporary method, will be implemented for each Handler
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function supportCategories()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getHistoryHandler()
|
||||
{
|
||||
return History::class;
|
||||
@@ -64,16 +54,7 @@ abstract class Handler extends BaseHandler implements AppHandler
|
||||
'files' => '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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -9,7 +9,9 @@ class Template
|
||||
/**
|
||||
* Getter for real template name
|
||||
*
|
||||
* @param $template
|
||||
* @param $template
|
||||
*
|
||||
* @param bool $throwExceptions
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace App\Cms\Repositories\Templates;
|
||||
|
||||
use App\CMS\Contracts\Repositories\Template as ITemplate;
|
||||
use App\CMS\Repositories\Repository;
|
||||
use App\Models\Module;
|
||||
use App\Models\Templates\Template as TemplateModel;
|
||||
|
||||
class Template extends Repository implements ITemplate
|
||||
{
|
||||
public function __construct(TemplateModel $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for absolute path to template
|
||||
*
|
||||
* @param null $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPathToTemplate($mode = null)
|
||||
{
|
||||
$templateName = $this->model->template_name;
|
||||
$path = $this->model->path()->get();
|
||||
|
||||
// delete namespace if given
|
||||
if (strpos($this->model->template_name, '::')) {
|
||||
list(, $templateName) = explode('::', $templateName);
|
||||
}
|
||||
|
||||
// get template name, do not care about directories (they are already contained in path)
|
||||
$parts = explode('.', $templateName);
|
||||
$templateName = last($parts);
|
||||
|
||||
// just a shortcut for this unbelievable long constant name...
|
||||
$_ = DIRECTORY_SEPARATOR;
|
||||
|
||||
// path parts
|
||||
$absolutePath = base_path($path->path);
|
||||
$templatePath = str_replace('.', $_, $templateName);
|
||||
$file = $templatePath . ITemplate::TEMPLATE_SUFFIX;
|
||||
|
||||
// compose two versions of path - original and with "custom" directory
|
||||
$original = $absolutePath . $_ . $file;
|
||||
$edited = $absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file;
|
||||
|
||||
// decide which path will be returned
|
||||
switch ($mode) {
|
||||
case ITemplate::CUSTOM_EDIT_DIRECTORY:
|
||||
return $edited;
|
||||
break;
|
||||
|
||||
case ITemplate::ORIGINAL_DIRECTORY:
|
||||
return $original;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (file_exists($absolutePath . $_ . ITemplate::EDITED_TEMPLATES_DIRECTORY . $_ . $file)) {
|
||||
return $edited;
|
||||
}
|
||||
|
||||
return $original;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function getForModule(Module $module) {
|
||||
return Template::where('module_id', $module->id)
|
||||
->select(['template_name', 'name', 'description'])
|
||||
->get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user