FEATURE: add another repositories
This commit is contained in:
@@ -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