FEATURE #1426: add log of all users
This commit is contained in:
+18
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user