109 lines
3.2 KiB
PHP
109 lines
3.2 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;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
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 getContentModules()
|
|
{
|
|
return Cache::remember('enabled-content-modules', setting('cacheModules', 3600), function () {
|
|
return ModuleModel::where('enabled', true)
|
|
->where('manages_content', true)
|
|
->get();
|
|
});
|
|
}
|
|
|
|
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.edit', ['name' => trans($module->name)]);
|
|
$moduleHeading = $this->call($module, 'getEditTitle', [$content]);
|
|
|
|
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
|
|
}
|
|
|
|
public function getOverviewTitle(ModuleModel $module = null)
|
|
{
|
|
$pageHeading = 'admin/contents.overview';
|
|
|
|
if (is_null($module)) {
|
|
return $pageHeading;
|
|
}
|
|
|
|
$moduleHeading = $this->call($module, 'getOverviewTitle');
|
|
|
|
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
|
|
}
|
|
|
|
public function all()
|
|
{
|
|
return Cache::remember('enabled-modules-and-template', setting('cacheModules', 3600), function () {
|
|
return ModuleModel::where('enabled', true)
|
|
->get();
|
|
});
|
|
}
|
|
|
|
public function getOnlyModules()
|
|
{
|
|
return Cache::remember('enabled-modules', setting('cacheModules', 3600), function () {
|
|
return ModuleModel::where('enabled', true)
|
|
->where('is_template', false)
|
|
->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;
|
|
}
|
|
|
|
public function callOnString($moduleHandler, $method, $parameters = [])
|
|
{
|
|
if (is_callable([$moduleHandler, $method])) {
|
|
return call_user_func_array([$moduleHandler, $method], $parameters);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
} |