<?php
//----------------------------------------------------------------------
// src/Logging/Activity/Prospect/SurveyQuestionLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity\Prospect;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Client\Client;
use App\Entity\Platform\Survey\Survey;
use App\Entity\Platform\Survey\SurveyQuestion;
use App\Logging\DeletionContextLogger;
use App\Logging\Tools;
use App\Services\LogTools;
class SurveyQuestionLog
{
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(SurveyQuestion $surveyQuestion)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
public function logChanges(SurveyQuestion $surveyQuestion, $changes)
{
// Mandatory conditions
$survey = $surveyQuestion->getSurvey();
if ($survey === null) return [];
$prospect = $survey->getProspect();
if ($prospect === null) return [];
if ($prospect->getIndividual() === null) return [];
$pendingLogArgs = [];
//----------------------------------------------------------------------
// Fetch eventual info skeletond in the object
$loggingData = $this->logTools->handleLoggingData($surveyQuestion);
$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_question";
$basicChanges = array(
"answer",
);
// 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(SurveyQuestion $surveyQuestion)
{
$pendingLogArgs = [];
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;
}
}