src/AppRemix/Logging/Objects/TemplateLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/AppRemix/Logging/TemplateLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\AppRemix\Logging\Objects;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\AppRemix\Entity\Template;
  8. use App\AppRemix\Logging\Tools;
  9. use App\Services\LogTools;
  10. class TemplateLog
  11. {
  12.     private array $pendingLogArgs = [];
  13.     public function __construct(ManagerRegistry $doctrine, LogTools $logTools, Tools $tools)
  14.     {
  15.         $this->em = $doctrine->getManager();
  16.         $this->logTools = $logTools;
  17.         $this->tools = $tools;
  18.     }
  19.     public function logCreation(Template $template)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData = $this->logTools->handleLoggingData($template);
  25.         $info = $loggingData['info'];        
  26.         $ignore = $loggingData['ignore'];
  27.         if ($ignore) return $pendingLogArgs;
  28.         //----------------------------------------------------------------------
  29.         // Init base log args
  30.         // This does not contain action
  31.         $args = $this->initArgs($template, $loggingData);
  32.         //----------------------------------------------------------------------
  33.         $action = "template_add";
  34.         $args["action"] = $action;
  35.         $pendingLogArgs[] = $args;
  36.         return $pendingLogArgs;
  37.     }
  38.     public function logChanges(Template $template, $changes)
  39.     {
  40.         $pendingLogArgs = [];
  41.         //----------------------------------------------------------------------
  42.         // Fetch eventual info stored in the object
  43.         $loggingData = $this->logTools->handleLoggingData($template);
  44.         $info = $loggingData['info'];        
  45.         $ignore = $loggingData['ignore'];
  46.         if ($ignore) return $pendingLogArgs;
  47.         //----------------------------------------------------------------------
  48.         // Init base log args
  49.         // This does not contain action
  50.         $args = $this->initArgs($template, $loggingData);
  51.         //----------------------------------------------------------------------
  52.         $action = "template_edit";
  53.         // This is triggered when we are actually changing the connected Address object
  54.         // The changes in the actual object are handled in AddressLog
  55.         $jsonChanges = array(
  56.         );
  57.         $basicChanges = array(                    
  58.             "title",
  59.         );
  60.         // See what changed and log (members first)
  61.         foreach ($changes as $key => $change)
  62.         {
  63.             // Something to skip ?
  64.             if (false)
  65.             {
  66.                 continue;
  67.             }
  68.             $name = $this->logTools->camelToSnakeCase($key);
  69.             $args["action"]    = $action."_".$name;
  70.             $before = $change[0];
  71.             $after = $change[1];
  72.             if (in_array($key, $basicChanges))
  73.             {
  74.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
  75.                 continue;
  76.             }
  77.             if (in_array($key, $jsonChanges))
  78.             {
  79.                 $pendingLogArgs[] = $this->tools->handleJsonChanges($args, $before, $after);
  80.                 continue;
  81.             }
  82.         }
  83.         return $pendingLogArgs;
  84.     }
  85.     public function logRemoval(Template $template)
  86.     {
  87.         $pendingLogArgs = [];
  88.         //----------------------------------------------------------------------
  89.         // Fetch eventual info stored in the object
  90.         $loggingData = $this->logTools->handleLoggingData($template);
  91.         $info = $loggingData['info'];        
  92.         $ignore = $loggingData['ignore'];
  93.         if ($ignore) return $pendingLogArgs;
  94.         //----------------------------------------------------------------------
  95.         // Init base log args
  96.         // This does not contain action
  97.         $args = $this->initArgs($template, $loggingData);
  98.         //----------------------------------------------------------------------
  99.         $args["action"] = "template_delete";
  100.         $pendingLogArgs[] = $args;
  101.         return $pendingLogArgs;
  102.     }
  103.     private function initArgs(Template $template, $loggingData)
  104.     {
  105.         $args = array(
  106.             "object_id"                    =>    $template->getId(),            
  107.             "object_entity"                =>    "Template",
  108.             "object_display"            =>    $template->display(),
  109.             
  110.             "society"                    =>    $template->getSociety(),
  111.             "info"                        =>    $loggingData['info'],            
  112.         );
  113.         return $args;
  114.     }
  115. }