FEATURE #1373: add history of content
This commit contains only core funcionality of displaying history. Module settings must be implemented in each module.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Models\User;
|
||||
|
||||
interface AppHandler
|
||||
{
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
*
|
||||
* @param Content $content DB model from table contents
|
||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render(Content $content, $parameters);
|
||||
|
||||
public static function getHistoryHandler();
|
||||
|
||||
/**
|
||||
* Register admin menu (or multiple ones)
|
||||
*
|
||||
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
|
||||
* starting any middleware..
|
||||
*
|
||||
* @param User $user model of logged user
|
||||
*/
|
||||
public static function registerAdminMenu(User $user);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
namespace App\Handlers\Contracts;
|
||||
|
||||
interface HistoryHandler
|
||||
{
|
||||
public static function parseColumnName($name);
|
||||
|
||||
public static function parseChangedValue($changeset);
|
||||
}
|
||||
@@ -1,28 +1,23 @@
|
||||
<?php
|
||||
namespace App\Handlers;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Handlers\Contracts\AppHandler;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Class Handler
|
||||
*
|
||||
* Handler is a class which handles module-specific behaviour which cannot be done by module itself, resp. cannot be done by some abstract magic.
|
||||
* Handler is a class which handles module-specific behaviour which cannot be done by module itself, resp. cannot be
|
||||
* done by some abstract magic.
|
||||
*
|
||||
* @package App\Handlers
|
||||
*/
|
||||
abstract class Handler
|
||||
abstract class Handler implements AppHandler
|
||||
{
|
||||
/**
|
||||
* Render given module into visitor area.
|
||||
*
|
||||
* @param Content $content DB model from table contents
|
||||
* @param array $parameters parameters used for modifications/custom settings of given model
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract public function render(Content $content, $parameters);
|
||||
public static function getHistoryHandler()
|
||||
{
|
||||
return History::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin menu (or multiple ones)
|
||||
@@ -34,6 +29,6 @@ abstract class Handler
|
||||
*/
|
||||
public static function registerAdminMenu(User $user)
|
||||
{
|
||||
//
|
||||
// core menu is registered in AdminMenuServiceProvider
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace App\Handlers;
|
||||
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use App\Handlers\Contracts\HistoryHandler;
|
||||
use App\Helpers\Differ;
|
||||
|
||||
class History implements HistoryHandler
|
||||
{
|
||||
public static function parseColumnName($column)
|
||||
{
|
||||
return trans('admin/history.column' . ucfirst($column));
|
||||
}
|
||||
|
||||
public static function parseChangedValue($changeset)
|
||||
{
|
||||
switch ($changeset->column) {
|
||||
case 'pageContent':
|
||||
$route = route('history.diff', [
|
||||
'revision' => $changeset->edit_batch,
|
||||
'id' => $changeset->id
|
||||
]);
|
||||
|
||||
return "(<a href='" . $route . "'>" . trans('admin/history.diff') . "</a>)";
|
||||
break;
|
||||
case 'metaDescription':
|
||||
return Differ::htmlDiff($changeset->old_value, $changeset->new_value);
|
||||
break;
|
||||
case 'status':
|
||||
$statuses = ContentStatuses::getWithTranslations();
|
||||
|
||||
return trans('admin/history.changedFromTo', [
|
||||
'from' => $statuses[$changeset->old_value],
|
||||
'to' => $statuses[$changeset->new_value]
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
return trans('admin/history.changedFromTo', [
|
||||
'from' => $changeset->old_value,
|
||||
'to' => $changeset->new_value
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user