FEATURE #1426: add log of all users

This commit is contained in:
Michal Kváček
2016-02-08 23:05:32 +01:00
parent 9de95c24c8
commit 2ab3896ee7
9 changed files with 119 additions and 14 deletions
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Helpers;
class Gravatar
{
public static function img($email, $size = 50)
{
return "http://www.gravatar.com/avatar/" . md5(strtolower(trim($email))) . "?s=" . $size;
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Models\ActionLog;
class ActionLogOverview extends Controller
{
/**
* @var ActionLog
*/
private $log;
/**
* ActionLog constructor.
*
* @param ActionLog $log
*/
public function __construct(ActionLog $log)
{
$this->log = $log;
}
public function getOverview()
{
$actions = $this->log->getLogActionsQuery(true)
->paginate(25);
$this->log->translateLogMessages($actions);
return view('admin.actionLog.overview', ['actions' => $actions]);
}
}
+4
View File
@@ -89,6 +89,10 @@ Route::group([
Route::get('history/{revision}/{id}', 'History@getDiff')
->name('history.diff');
// list of all actions
Route::get('actions', 'ActionLogOverview@getOverview')
->name('log.overview');
// uploader methods
Route::get('upload/file', 'UploadFile@getFile')
->name('upload.file');
+18 -12
View File
@@ -22,13 +22,22 @@ class ActionLog extends Model
/**
* Query factory for loading action logs with their type (therefore with name and value)
*
* @param bool $joinUser
*
* @return mixed
*/
public function getLogActionsQuery()
public function getLogActionsQuery($joinUser = false)
{
$actions = \DB::table('action_log')
->select('action_log.*', 'action_log_types.*')
->join('action_log_types', 'action_log_types.id', '=', 'action_log.type_id')
->orderBy('created_at', 'DESC');
->orderBy('action_log.created_at', 'DESC');
if ($joinUser) {
$actions = $actions->join('users', 'users.id', '=', 'action_log.user_id')
->select('action_log.*', 'action_log_types.*', 'users.email', 'users.name as user_name');
}
return $actions;
}
@@ -55,7 +64,9 @@ class ActionLog extends Model
->get();
// translate and return result
return $this->translateLogMessages($actions);
$this->translateLogMessages($actions);
return $actions;
}
/**
@@ -65,17 +76,12 @@ class ActionLog extends Model
*
* @return array
*/
public function translateLogMessages($messages)
public function translateLogMessages(&$messages)
{
$log = [];
// translate name and value of each record
foreach ($messages as $action) {
$action->name = trans($action->name);
$action->value = trans($action->value, (array)json_decode($action->parameters));
$log[] = $action;
foreach ($messages as $i => $action) {
$messages[$i]->name = trans($action->name);
$messages[$i]->value = trans($action->value, (array)json_decode($action->parameters));
}
return $log;
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use App\Helpers\Gravatar;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticableInterface;
use Illuminate\Database\Eloquent\Model;
@@ -48,6 +49,6 @@ class User extends Model implements AuthenticableInterface
*/
public function gravatar($size = 50)
{
return "http://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))) . "?s=" . $size;
return Gravatar::img($this->email, $size);
}
}
+1
View File
@@ -41,6 +41,7 @@ class AdminMenusProvider extends ServiceProvider
$sub->route('customfields.new', trans('admin/mainMenu.customFieldsNew'), [], 10, ['icon' => 'fa fa-code']);
$sub->route('customfields.overview', trans('admin/mainMenu.customFieldsOverview'), [], 50, ['icon' => 'fa fa-code-fork']);
}, 30, ['icon' => 'fa fa-code']);
$menu->route('log.overview', trans('admin/mainMenu.actionLog'), [], 40, ['icon' => 'fa fa-history']);
$menu->url('#', trans('admin/mainMenu.settings'), 50, ['icon' => 'fa fa-gear']);
});