REFACTORING: another ugly commit full of refactored code

This commit is contained in:
Michal Kváček
2016-10-19 00:28:44 +02:00
parent 4f6a006ad9
commit 28f67ffe3c
34 changed files with 101 additions and 258 deletions
+36 -28
View File
@@ -2,64 +2,72 @@
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
{
/**
* @var ModuleModel
*/
private $module;
public function __construct(ModuleModel $module)
{
$this->module = $module;
$this->model = $module;
}
public function getOne($id = null)
{
if (!is_null($id)) {
if (is_numeric($id)) {
return ModuleModel::findOrFail($id);
} else {
return ModuleModel::where('alias', $id)
->firstOrFail();
}
} else {
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)]);
if (is_callable([$module->handler, 'getCreateNewTitle'])) {
$pageHeading = call_user_func([$module->handler, 'getCreateNewTitle']);
}
$moduleHeading = $this->call($module, 'getCreateNewTitle');
return $pageHeading;
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function getUpdateContentTitle(ModuleModel $module)
public function getUpdateContentTitle(ModuleModel $module, Content $content = null)
{
// TODO: Implement getUpdateContentTitle() method.
$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');
// does user want to filter results using module?
if (!is_null($module) && is_callable([$module->handler, 'getOverviewTitle'])) {
$pageHeading = call_user_func([$module->handler, 'getOverviewTitle']);
}
return $pageHeading;
return is_null($moduleHeading) ? $pageHeading : $moduleHeading;
}
public function all()
{
// TODO: Implement all() method.
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;
}
}