src/Logging/Activity/AdvancedNotificationLog.php line 18

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/AdvancedNotificationLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Ding\AdvancedNotification;
  8. use App\Logging\DeletionContextLogger;
  9. use App\Logging\Tools;
  10. use App\Services\LogTools;
  11. class AdvancedNotificationLog
  12. {
  13.     private array $pendingLogArgs = [];
  14.     public function __construct(ManagerRegistry $doctrineDeletionContextLogger $contextLoggerLogTools $logToolsTools $tools)
  15.     {
  16.         $this->em $doctrine->getManager();
  17.         $this->logTools $logTools;
  18.         $this->contextLogger $contextLogger;
  19.         $this->tools $tools;
  20.     }
  21.     public function logCreation(AdvancedNotification $advancedNotification)
  22.     {
  23.         $pendingLogArgs = [];
  24.         return $pendingLogArgs;
  25.     }
  26.     public function logChanges(AdvancedNotification $advancedNotification$changes)
  27.     {
  28.         $pendingLogArgs = [];
  29.         return $pendingLogArgs;
  30.     }
  31.     public function logRemoval(AdvancedNotification $advancedNotification)
  32.     {
  33.         $pendingLogArgs = [];
  34.         $cachedData $this->contextLogger->getContext($advancedNotification);
  35.         if ($cachedData === null || empty($cachedData))
  36.         {
  37.             return $pendingLogArgs;
  38.         }
  39.         // SocietyGroup is mandatory
  40.         if (!array_key_exists('societyGroup'$cachedData) || $cachedData['societyGroup'] === null)
  41.         {
  42.             return $pendingLogArgs;
  43.         }
  44.         //----------------------------------------------------------------------
  45.         // Fetch eventual info in the object
  46.         $loggingData $this->logTools->handleLoggingData($advancedNotification);
  47.         $info $loggingData['info'];
  48.         $specialAuthor $loggingData['special_author'];
  49.         $ignore $loggingData['ignore'];
  50.         if ($ignore) return $pendingLogArgs;
  51.         //----------------------------------------------------------------------
  52.         // Init base log args
  53.         // This does not contain action
  54.         $args $this->initArgs($advancedNotification$loggingData$cachedData);
  55.         //----------------------------------------------------------------------
  56.         $action "advanced_notification_solved";
  57.         if ($info == "rfi_auto")
  58.         {
  59.             // Task notifications are automatically solved when adding the missimg RFI
  60.             $action "advanced_notification_solved_rfi_auto";
  61.             $args["info"] = null;
  62.         }
  63.         $args["action"] = $action;
  64.         $pendingLogArgs[] = $args;
  65.         return $pendingLogArgs;
  66.     }
  67.     private function initArgs(AdvancedNotification $advancedNotification$loggingData$cachedData)
  68.     {
  69.         $societyGroup $cachedData['societyGroup'];
  70.         // Two types of objects are possible for now : Tasks and Documents
  71.         // Both have Receivers
  72.         if (array_key_exists('receiver'$cachedData) && $cachedData['receiver'] !== null)
  73.             $receiver $cachedData['receiver'];
  74.         if (array_key_exists('society'$cachedData) && $cachedData['society'] !== null)
  75.             $society $cachedData['society'];
  76.         $args = array(
  77.             "object_id"                    =>    $advancedNotification->getId(),
  78.             "object_bundle"                =>    "Ding",
  79.             "object_entity"                =>    "AdvancedNotification",
  80.             "object_display"            =>    $advancedNotification->display(),
  81.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  82.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  83.             "society_group"                =>    $societyGroup,
  84.             "society"                    =>    $society,
  85.             "info"                        =>    $loggingData['info'],
  86.             "special_author"            =>    $loggingData['special_author'],
  87.         );
  88.         return $args;
  89.     }
  90. }