REFACTORING #1880 @20m: move action log logic into repository

This commit is contained in:
Michal Kváček
2016-11-23 01:03:37 +01:00
parent 2fffea39fa
commit 3aabb8fa7b
5 changed files with 37 additions and 41 deletions
@@ -1,10 +1,33 @@
<?php
namespace App\Models\ActionLog\ModelTraits;
namespace App\Cms\Repositories\ActionLog;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
trait ActionLog
class Actions
{
/**
* @param null $userId
*
* @return array
*/
public function getLoggedActions($userId = null)
{
$actions = $this->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)
{
@@ -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]);
}
@@ -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');
}
+2 -2
View File
@@ -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
+4 -2
View File
@@ -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'
];
}