From 3aabb8fa7b23fe87b2d5b322c8688e8599d41977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Wed, 23 Nov 2016 01:03:37 +0100 Subject: [PATCH] REFACTORING #1880 @20m: move action log logic into repository --- .../Repositories/ActionLog/Actions.php} | 29 +++++++++++++-- .../Controllers/Admin/ActionLog/Overview.php | 37 +++---------------- .../Controllers/Admin/Dashboard/Dashboard.php | 2 +- app/Http/routes.php | 4 +- app/Models/ActionLog/ActionLog.php | 6 ++- 5 files changed, 37 insertions(+), 41 deletions(-) rename app/{Models/ActionLog/ModelTraits/ActionLog.php => CMS/Repositories/ActionLog/Actions.php} (79%) diff --git a/app/Models/ActionLog/ModelTraits/ActionLog.php b/app/CMS/Repositories/ActionLog/Actions.php similarity index 79% rename from app/Models/ActionLog/ModelTraits/ActionLog.php rename to app/CMS/Repositories/ActionLog/Actions.php index 376fcb97..acbd3ac4 100644 --- a/app/Models/ActionLog/ModelTraits/ActionLog.php +++ b/app/CMS/Repositories/ActionLog/Actions.php @@ -1,10 +1,33 @@ getLogActionsQuery(true); + + $user = null; + if ($userId) { + $user = User::findOrFail($userId); + $actions->where('users.id', $userId); + } + + $actions = $actions->paginate(25); + + $this->translateLogMessages($actions); + + return [$user, $actions]; + } + /** * Query factory for loading action logs with their type (therefore with name and value) * @@ -58,8 +81,6 @@ trait ActionLog * Method used for translating and filling parameters into value of log. * * @param $messages - * - * @return array */ public function translateLogMessages(&$messages) { diff --git a/app/Http/Controllers/Admin/ActionLog/Overview.php b/app/Http/Controllers/Admin/ActionLog/Overview.php index 1d13ad24..57eb6485 100644 --- a/app/Http/Controllers/Admin/ActionLog/Overview.php +++ b/app/Http/Controllers/Admin/ActionLog/Overview.php @@ -2,49 +2,22 @@ namespace App\Http\Controllers\Admin\ActionLog; +use App\Cms\Repositories\ActionLog\Actions; use App\Http\Controllers\Admin\Controller; -use App\Models\ActionLog\ActionLog; -use App\Models\User; use Illuminate\Support\Facades\Input; class Overview extends Controller { - /** - * @var ActionLog - */ - private $log; - - /** - * ActionLog constructor. - * - * @param ActionLog $log - */ - public function __construct(ActionLog $log) - { - parent::__construct(); - $this->log = $log; - } - /** * Get overview of logged actions * + * @param Actions $repository + * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function getOverview() + public function index(Actions $repository) { - $user = null; - $userId = Input::get('userId'); - - $actions = $this->log->getLogActionsQuery(true); - - if ($userId) { - $user = User::findOrFail($userId); - $actions->where('users.id', $userId); - } - - $actions = $actions->paginate(25); - - $this->log->translateLogMessages($actions); + list($user, $actions) = $repository->getLoggedActions(Input::get('userId')); return view('admin.actionLog.overview', ['actions' => $actions, 'user' => $user]); } diff --git a/app/Http/Controllers/Admin/Dashboard/Dashboard.php b/app/Http/Controllers/Admin/Dashboard/Dashboard.php index 3e666127..bad941c3 100644 --- a/app/Http/Controllers/Admin/Dashboard/Dashboard.php +++ b/app/Http/Controllers/Admin/Dashboard/Dashboard.php @@ -7,7 +7,7 @@ use Illuminate\Http\Request; class Dashboard extends Controller { - public function getIndex(Request $request) + public function index(Request $request) { return redirect()->route('content.overview'); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 9edfdf89..c648aaf7 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -28,11 +28,11 @@ Route::group(['prefix' => LaravelLocalization::setLocale()], function () { } // display dashboard with some usefull information - Route::get('/', 'Dashboard\Dashboard@getIndex') + Route::get('/', 'Dashboard\Dashboard@index') ->name('admin.dashboard'); // list of all actions - Route::get('actions', 'ActionLog\Overview@getOverview') + Route::get('actions', 'ActionLog\Overview@index') ->name('log.overview'); // search form with results diff --git a/app/Models/ActionLog/ActionLog.php b/app/Models/ActionLog/ActionLog.php index cbdb19ae..dceb76f2 100644 --- a/app/Models/ActionLog/ActionLog.php +++ b/app/Models/ActionLog/ActionLog.php @@ -9,8 +9,6 @@ use Illuminate\Database\Eloquent\Model; */ class ActionLog extends Model { - use ModelTraits\ActionLog; - protected $table = 'action_log'; public $timestamps = false; protected $fillable = [ @@ -20,4 +18,8 @@ class ActionLog extends Model 'user_agent', 'parameters' ]; + + protected $casts = [ + 'parameters' => 'array' + ]; } \ No newline at end of file