1. Go to this page and download the library: Download ebola/logging library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// User in logging object
$loggingUser = $this->getUser();
// Path to download directory from config download_path
$fileLoggingPath = $this->getFileLoggingPath();
// Path to activity model from config activitylog.activity_model
$activityModel = $this->getActivityModel();
// Path to translation path from config translation_path
$pathToTranslationFields = $this->getTranslationPath();
// From config num_rows_on_page
$countRowOnDisplayFromConfig = $this->logging->getRowCount();
// Fields from object. Default from config logging_fields
$fieldsForDisplay = $this->logging->getFields();
// Translates from config translation_path. Default from vendor
$translatedFieldsForDisplay = $this->logging->getTranslatedFields();
// Returns the constructed query
// Fields must exist in the log table and be broken according to the type of filtering in the config logging_filters
// Default filters are empty array
$rows = $this->logging->getRows($filters);
// Creates a file and displays a custom save window
$rows = $this->logging->getRows()->get()
$this->logging->getLoggingFile($rows);
// Work with json properties field from Activity model
class Properties
{
public static function getProperties($activity, $flag='attributes')
{
$properties = $activity->properties->toArray();
return array_key_exists($flag, $properties) ? $properties[$flag] : null;
}
public static function getPropertiesChanges($activity)
{
$attributes = self::getProperties($activity, 'attributes');
$old = self::getProperties($activity, 'old');
$result = [];
foreach ($attributes ?? [] as $key => $value) {
if (isset($old) && ($attributes[$key] != $old[$key])) {
$result[] = $key;
}
}
return !empty($result) ? $result : null;
}
public static function getPropertiesArray($model)
{
$attributes = $model->getAttributes();
$oldAttributes = $model->getOriginal();
$properties['attributes'] = $attributes;
$checkAttributes = false;
foreach ($attributes as $key => $value) {
if (!empty($oldAttributes) && ($oldAttributes[$key] != $value)) {
$checkAttributes = true;
break;
}
}
if ($checkAttributes)
$properties['old'] = $oldAttributes;
return $properties;
}
}
// Display filter if transmitted field is in array from config logging_filters
class Filters
{
const SELECT_DEFAULT_KEY = 'default';
public static function getFilter($field, $translate)
{
$fieldsForFilterSelect = config('logging.logging_filters.selectable');
$fieldsForFilterText = config('logging.logging_filters.according_to_the_text');
if (in_array($field, $fieldsForFilterSelect)) {
$resultHtml = self::getSelectFilter($field, $translate);
} elseif (in_array($field, $fieldsForFilterText)) {
$resultHtml = self::getTextFilter($field, $translate);
} else {
$resultHtml = null;
}
return $resultHtml;
}
private static function getSelectFilter($field, $translate)
{
$activityModel = config('activitylog.activity_model');
$values = $activityModel::select([$field])->distinct()->orderBy($field)->get();
$arrayValues[self::SELECT_DEFAULT_KEY] = $translate;
foreach ($values as $value) {
if (!is_null($value->{$field})) {
$arrayValues[$value->{$field}] = $value->{$field};
} else {
$arrayValues['null'] = __('logging::logging.user_logging.undefined');
}
}
return view('logging::filters._select_filter', compact('field', 'arrayValues'));
}
private static function getTextFilter($field, $translate)
{
return view('logging::filters._text_filter', compact('field', 'translate'));
}
}