src/Logging/Activity/StoreGroupLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/StoreGroupLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Client\StoreGroup;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class StoreGroupLog
  11. {
  12.     private array $pendingLogArgs = [];
  13.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsTools $tools)
  14.     {
  15.         $this->em $doctrine->getManager();
  16.         $this->logTools $logTools;
  17.         $this->tools $tools;
  18.     }
  19.     public function logCreation(StoreGroup $storeGroup)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($storeGroup);
  25.         $info $loggingData['info'];
  26.         $specialAuthor $loggingData['special_author'];
  27.         $ignore $loggingData['ignore'];
  28.         if ($ignore) return $pendingLogArgs;
  29.         //----------------------------------------------------------------------
  30.         // Init base log args
  31.         // This does not contain action
  32.         $args $this->initArgs($storeGroup$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $action "store_group_add";
  35.         $args["action"] = $action;
  36.         $pendingLogArgs[] = $args;
  37.         return $pendingLogArgs;
  38.     }
  39.     public function logChanges(StoreGroup $storeGroup$changes)
  40.     {
  41.         $pendingLogArgs = [];
  42.         //----------------------------------------------------------------------
  43.         // Fetch eventual info skeletond in the object
  44.         $loggingData $this->logTools->handleLoggingData($storeGroup);
  45.         $info $loggingData['info'];
  46.         $specialAuthor $loggingData['special_author'];
  47.         $ignore $loggingData['ignore'];
  48.         if ($ignore) return $pendingLogArgs;
  49.         //----------------------------------------------------------------------
  50.         // Init base log args
  51.         // This does not contain action
  52.         $args $this->initArgs($storeGroup$loggingData);
  53.         //----------------------------------------------------------------------
  54.         $action "store_group_edit";
  55.         $basicChanges = array(
  56.             "name",
  57.             "ref",
  58.         );
  59.         $labelChanges = array(
  60.         );
  61.         // Method getLogLabel() should be defined for these objects/entities
  62.         $objectChanges = array(
  63.             "tva",
  64.         );
  65.         // See what changed and log (members first)
  66.         foreach ($changes as $key => $change)
  67.         {
  68.             // Something to skip ?
  69.             if (false)
  70.             {
  71.                 continue;
  72.             }
  73.             $name $this->logTools->camelToSnakeCase($key);
  74.             $args["action"]    = $action."_".$name;
  75.             $before $change[0];
  76.             $after $change[1];
  77.             if (in_array($key$basicChanges))
  78.             {
  79.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  80.                 continue;
  81.             }
  82.             if (in_array($key$labelChanges))
  83.             {
  84.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  85.                 continue;
  86.             }
  87.             if (in_array($key$objectChanges))
  88.             {
  89.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  90.                 continue;
  91.             }
  92.         }
  93.         return $pendingLogArgs;
  94.     }
  95.     public function logRemoval(StoreGroup $storeGroup)
  96.     {
  97.         $pendingLogArgs = [];
  98.         return $pendingLogArgs;
  99.     }
  100.     private function initArgs(StoreGroup $storeGroup$loggingData)
  101.     {
  102.         $societyGroup $storeGroup->getSocietyGroup();
  103.         $args = array(
  104.             "object_id"                    =>    $storeGroup->getId(),
  105.             "object_bundle"                =>    "Client",
  106.             "object_entity"                =>    "StoreGroup",
  107.             "object_display"            =>    $storeGroup->display(),
  108.             "society_group"                =>    $societyGroup,
  109.             "info"                        =>    $loggingData['info'],
  110.             "special_author"            =>    $loggingData['special_author'],
  111.         );
  112.         return $args;
  113.     }
  114. }