<?php
//----------------------------------------------------------------------
// src/Logging/CostNoteLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Platform\Cost\CostNote;
use App\Logging\Tools;
use App\Services\LogTools;
class CostNoteLog
{
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(CostNote $costNote)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($costNote);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($costNote, $loggingData);
//----------------------------------------------------------------------
$action = "cost_note_add";
$args["action"] = $action;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logChanges(CostNote $costNote, $changes)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($costNote);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($costNote, $loggingData);
//----------------------------------------------------------------------
$action = "cost_note_edit";
$basicChanges = array(
"info",
);
// See what changed and log (members first)
foreach ($changes as $key => $change)
{
$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;
}
}
return $pendingLogArgs;
}
public function logRemoval(CostNote $costNote)
{
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($costNote);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args
// This does not contain action
$args = $this->initArgs($costNote, $loggingData);
//----------------------------------------------------------------------
$args["action"] = "cost_note_delete";
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(CostNote $costNote, $loggingData)
{
$society = $costNote->getSociety();
$societyGroup = $costNote->getSocietyGroup();
$args = array(
"object_id" => $costNote->getId(),
"object_bundle" => "Platform",
"object_entity" => "CostNote",
"object_display" => $costNote->display(),
"society_group" => $societyGroup,
"society" => $society,
"info" => $loggingData['info'],
"special_author" => $loggingData['special_author'],
);
return $args;
}
}