Files
core/app/CMS/Repositories/Module.php
T

73 lines
2.1 KiB
PHP

<?php
namespace App\CMS\Repositories;
use App\CMS\Contracts\Repositories\Module as IModule;
use App\Models\Content\Content;
use App\Models\Module as ModuleModel;
class Module extends Repository implements IModule
{
public function __construct(ModuleModel $module)
{
$this->model = $module;
}
public function getOne($id = null)
{
if (is_null($id)) {
return new ModuleModel();
}
if (is_numeric($id)) {
return ModuleModel::findOrFail($id);
} else {
return ModuleModel::where('alias', $id)
->firstOrFail();
}
}
public function getCreateContentTitle(ModuleModel $module)
{
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
$moduleHeading = $this->call($module, 'getCreateNewTitle');
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function getUpdateContentTitle(ModuleModel $module, Content $content = null)
{
$pageHeading = trans('admin/contents.new', ['name' => trans($module->name)]);
$moduleHeading = $this->call($module, 'getEditTitle', $content);
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function getOverviewTitle(ModuleModel $module)
{
$pageHeading = 'admin/contents.overview';
$moduleHeading = $this->call($module, 'getOverviewTitle');
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function all()
{
return ModuleModel::where('enabled', true)
->get();
}
public function getByHandler($handler)
{
return ModuleModel::where('handler', $handler)
->firstOrFail();
}
public function call(ModuleModel $module, $method, ...$parameters)
{
if (!is_null($module) && is_callable([$module->handler, $method])) {
return call_user_func_array([$module->handler, $method], $parameters);
}
return null;
}
}