<?php
//----------------------------------------------------------------------
// src/AppRemix/Logging/TemplateLog.php
//----------------------------------------------------------------------
namespace App\AppRemix\Logging\Objects;
use Doctrine\Persistence\ManagerRegistry;
use App\AppRemix\Entity\Template;
use App\AppRemix\Logging\Tools;
use App\Services\LogTools;
class TemplateLog
{
private array $pendingLogArgs = [];
public function __construct(ManagerRegistry $doctrine, LogTools $logTools, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->logTools = $logTools;
$this->tools = $tools;
}
public function logCreation(Template $template)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($template);
$info = $loggingData['info'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($template, $loggingData);
//----------------------------------------------------------------------
$action = "template_add";
$args["action"] = $action;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logChanges(Template $template, $changes)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($template);
$info = $loggingData['info'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($template, $loggingData);
//----------------------------------------------------------------------
$action = "template_edit";
// This is triggered when we are actually changing the connected Address object
// The changes in the actual object are handled in AddressLog
$jsonChanges = array(
);
$basicChanges = array(
"title",
);
// See what changed and log (members first)
foreach ($changes as $key => $change)
{
// Something to skip ?
if (false)
{
continue;
}
$name = $this->logTools->camelToSnakeCase($key);
$args["action"] = $action."_".$name;
$before = $change[0];
$after = $change[1];
if (in_array($key, $basicChanges))
{
$pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
continue;
}
if (in_array($key, $jsonChanges))
{
$pendingLogArgs[] = $this->tools->handleJsonChanges($args, $before, $after);
continue;
}
}
return $pendingLogArgs;
}
public function logRemoval(Template $template)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($template);
$info = $loggingData['info'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($template, $loggingData);
//----------------------------------------------------------------------
$args["action"] = "template_delete";
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(Template $template, $loggingData)
{
$args = array(
"object_id" => $template->getId(),
"object_entity" => "Template",
"object_display" => $template->display(),
"society" => $template->getSociety(),
"info" => $loggingData['info'],
);
return $args;
}
}