<?php
//----------------------------------------------------------------------
// src/Logging/AdvancedNotificationLog.php
//----------------------------------------------------------------------
namespace App\Logging\Activity;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\Ding\AdvancedNotification;
use App\Logging\DeletionContextLogger;
use App\Logging\Tools;
use App\Services\LogTools;
class AdvancedNotificationLog
{
private array $pendingLogArgs = [];
public function __construct(ManagerRegistry $doctrine, DeletionContextLogger $contextLogger, LogTools $logTools, Tools $tools)
{
$this->em = $doctrine->getManager();
$this->logTools = $logTools;
$this->contextLogger = $contextLogger;
$this->tools = $tools;
}
public function logCreation(AdvancedNotification $advancedNotification)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
public function logChanges(AdvancedNotification $advancedNotification, $changes)
{
$pendingLogArgs = [];
return $pendingLogArgs;
}
public function logRemoval(AdvancedNotification $advancedNotification)
{
$pendingLogArgs = [];
$cachedData = $this->contextLogger->getContext($advancedNotification);
if ($cachedData === null || empty($cachedData))
{
return $pendingLogArgs;
}
// SocietyGroup is mandatory
if (!array_key_exists('societyGroup', $cachedData) || $cachedData['societyGroup'] === null)
{
return $pendingLogArgs;
}
//----------------------------------------------------------------------
// Fetch eventual info in the object
$loggingData = $this->logTools->handleLoggingData($advancedNotification);
$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($advancedNotification, $loggingData, $cachedData);
//----------------------------------------------------------------------
$action = "advanced_notification_solved";
if ($info == "rfi_auto")
{
// Task notifications are automatically solved when adding the missimg RFI
$action = "advanced_notification_solved_rfi_auto";
$args["info"] = null;
}
$args["action"] = $action;
$pendingLogArgs[] = $args;
return $pendingLogArgs;
}
private function initArgs(AdvancedNotification $advancedNotification, $loggingData, $cachedData)
{
$societyGroup = $cachedData['societyGroup'];
// Two types of objects are possible for now : Tasks and Documents
// Both have Receivers
if (array_key_exists('receiver', $cachedData) && $cachedData['receiver'] !== null)
$receiver = $cachedData['receiver'];
if (array_key_exists('society', $cachedData) && $cachedData['society'] !== null)
$society = $cachedData['society'];
$args = array(
"object_id" => $advancedNotification->getId(),
"object_bundle" => "Ding",
"object_entity" => "AdvancedNotification",
"object_display" => $advancedNotification->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;
}
}