<?php
//----------------------------------------------------------------------
// src/Logging/Activity/Prospect/SurveyLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity\Prospect;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Client\Client;
use App\Entity\Platform\Survey\Survey;
use App\Logging\DeletionContextLogger;
use App\Logging\Tools;
use App\Services\LogTools;
class SurveyLog
{
private array $pendingLogArgs = [];
public function __construct(ManagerRegistry $doctrine, DeletionContextLogger $contextLogger, LogTools $logTools, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->contextLogger = $contextLogger;
$this->logTools = $logTools;
$this->tools = $tools;
}
public function logCreation(Survey $survey)
{
// Mandatory conditions
$prospect = $survey->getProspect();
if ($prospect === null) return [];
if ($prospect->getIndividual() === null) return [];
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info stored in the object
$loggingData = $this->logTools->handleLoggingData($survey);
$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($survey, $prospect, $loggingData);
//----------------------------------------------------------------------
$action = "prospect_add_survey";
$args["action"] = $action;
$args["new_value"] = $survey->display();
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logChanges(Survey $survey, $changes)
{
// Mandatory conditions
$prospect = $survey->getProspect();
if ($prospect === null) return [];
if ($prospect->getIndividual() === null) return [];
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($survey);
$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($survey, $prospect, $loggingData);
//----------------------------------------------------------------------
$action = "prospect_edit_survey";
$args["action"] = $action;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
public function logRemoval(Survey $survey)
{
// Mandatory conditions
$cachedData = $this->contextLogger->getContext($survey);
if ($cachedData === null || empty($cachedData)) return [];
if (array_key_exists('prospect', $cachedData) && $cachedData['prospect'] !== null)
{
$prospect = $cachedData['prospect'];
if ($prospect->getIndividual() === null) return [];
}
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($survey);
$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($survey, $prospect, $loggingData);
//----------------------------------------------------------------------
$args["action"] = "prospect_delete_survey";
$args["old_value"] = $survey->displayForLogDelete();
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(Survey $survey, Client $prospect, $loggingData)
{
$objectEntity = "Client.Prospect";
$receiver = $prospect;
$individual = $prospect->getIndividual();
$society = $individual->getSociety();
$societyGroup = $individual->getSocietyGroup();
$args = array(
"object_id" => $prospect->getId(),
"object_bundle" => "Platform",
"object_entity" => $objectEntity,
"object_display" => $prospect->display(),
"object_client_id" => $receiver !== null ? $receiver->getId() : null,
"object_client_display" => $receiver !== null ? $receiver->getName() : null,
"society_group" => $societyGroup,
"society" => $society,
"info" => $loggingData['info'],
"special_author" => $loggingData['special_author'],
);
return $args;
}
}