<?php
//----------------------------------------------------------------------
// src/Logging/Activity/GhostDevisLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Logging\Tools;
use App\Services\LogTools;
use App\Entity\Platform\Devis\Devis;
use App\Entity\Platform\Devis\GhostDevis;
class GhostDevisLog
{
private array $pendingLogArgs = [];
public function __construct(ManagerRegistry $doctrine, TranslatorInterface $translator, LogTools $logTools, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->logTools = $logTools;
$this->tools = $tools;
$this->translator = $translator;
}
public function logCreation(GhostDevis $ghostDevis)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
public function logChanges(GhostDevis $ghostDevis, $changes)
{
$pendingLogArgs = [];
$devis = $ghostDevis->getDevis();
if ($devis === null) return $pendingLogArgs;
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($ghostDevis);
$info = $loggingData['info'];
$specialAuthor = $loggingData['special_author'];
$ignore = $loggingData['ignore'];
if ($ignore) return $pendingLogArgs;
//----------------------------------------------------------------------
// Init base log args (for Devis, not the GhostDevis)
// This does not contain action
$args = $this->initArgs($devis, $loggingData);
//----------------------------------------------------------------------
// Plan.io Task #4475 : I want to know if a devis changes algorithm
$action = "ghost_devis_edit";
// See what changed and log (members first)
foreach ($changes as $key => $change)
{
// Something to skip ?
if ($key != "algo")
{
continue;
}
$name = $this->logTools->camelToSnakeCase($key);
$args["action"] = $action."_".$name;
$before = $change[0];
$after = $change[1];
$args["old_value"] = $before;
$args["new_value"] = $after;
switch ($before)
{
case GhostDevis::algo_original:
$args["old_value"] = $this->translator->trans('ghost_devis_used_method_original')." "
.$this->translator->trans('ghost_devis_used_method_original_info');
break;
case GhostDevis::algo_makeover:
$args["old_value"] = $this->translator->trans('ghost_devis_used_method_makeover')." "
.$this->translator->trans('ghost_devis_used_method_makeover_info');
break;
default:
$args["old_value"] = $this->translator->trans('ghost_devis_used_method_unknown');
break;
}
switch ($after)
{
case GhostDevis::algo_original:
$args["new_value"] = $this->translator->trans('ghost_devis_used_method_original')." "
.$this->translator->trans('ghost_devis_used_method_original_info');
break;
case GhostDevis::algo_makeover:
$args["new_value"] = $this->translator->trans('ghost_devis_used_method_makeover')." "
.$this->translator->trans('ghost_devis_used_method_makeover_info');
break;
default:
$args["new_value"] = $this->translator->trans('ghost_devis_used_method_unknown');
break;
}
$pendingLogArgs[] = $args;
}
return $pendingLogArgs;
}
public function logRemoval(GhostDevis $ghostDevis)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
private function initArgs(Devis $devis, $loggingData)
{
$receiver = $devis->getReceiver();
$society = $devis->getSociety();
$societyGroup = $society->getSocietyGroup();
$mission = $devis->getMission();
$args = array(
"object_id" => $devis->getId(),
"object_bundle" => "Platform",
"object_entity" => "Devis",
"object_display" => $devis->display(),
"object_client_id" => $receiver !== null ? $receiver->getId() : null,
"object_client_display" => $receiver !== null ? $receiver->getName() : null,
"object_mission_id" => $mission !== null ? $mission->getId() : null,
"object_mission_display" => $mission !== null ? $mission->getRef() : null,
"society_group" => $societyGroup,
"society" => $society,
"info" => $loggingData['info'],
"special_author" => $loggingData['special_author'],
);
return $args;
}
}