src/Logging/Activity/StoreLog.php line 17

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/StoreLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Logging\Tools;
  8. use App\Services\LogTools;
  9. use App\Entity\Client\Store;
  10. class StoreLog
  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(Store $store)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($store);
  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($store$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $action "store_add";
  35.         $args["action"] = $action;
  36.         $pendingLogArgs[] = $args;
  37.         return $pendingLogArgs;
  38.     }
  39.     public function logChanges(Store $store$changes)
  40.     {
  41.         $pendingLogArgs = [];
  42.         //----------------------------------------------------------------------
  43.         // Fetch eventual info stored in the object
  44.         $loggingData $this->logTools->handleLoggingData($store);
  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($store$loggingData);
  53.         //----------------------------------------------------------------------
  54.         $action "store_edit";
  55.         // This is triggered when we are actually changing the connected Address object
  56.         // The changes in the actual object are handled in AddressLog
  57.         $addressChanges = array(
  58.             "address",
  59.             "billingAddress",
  60.         );
  61.         $basicChanges = array(
  62.             "name",
  63.             "ref",
  64.             "info",
  65.             "email",
  66.             "phone",
  67.             "ikeaDefaultEmitter",
  68.         );
  69.         $dateChanges = array(
  70.         );
  71.         $labelChanges = array(
  72.         );
  73.         // Method getLogLabel() should be defined for these objects/entities
  74.         $objectChanges = array(
  75.             "group",
  76.         );
  77.         // See what changed and log (members first)
  78.         foreach ($changes as $key => $change)
  79.         {
  80.             $name $this->logTools->camelToSnakeCase($key);
  81.             $args["action"]    = $action."_".$name;
  82.             $before $change[0];
  83.             $after $change[1];
  84.             if (in_array($key$addressChanges))
  85.             {
  86.                 $pendingLogArgs[] = $this->tools->handleAddressChanges($args$before$after);
  87.                 continue;
  88.             }
  89.             if (in_array($key$basicChanges))
  90.             {
  91.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  92.                 continue;
  93.             }
  94.             if (in_array($key$dateChanges))
  95.             {
  96.                 // dateChanges can be null
  97.                 $changeLogs $this->tools->handleDateChanges($args$before$after);
  98.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  99.                 continue;
  100.             }
  101.             if (in_array($key$labelChanges))
  102.             {
  103.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  104.                 continue;
  105.             }
  106.             if (in_array($key$objectChanges))
  107.             {
  108.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  109.                 continue;
  110.             }
  111.         }
  112.         return $pendingLogArgs;
  113.     }
  114.     public function logRemoval(Store $store)
  115.     {
  116.         $pendingLogArgs = [];
  117.         return $pendingLogArgs;
  118.     }
  119.     private function initArgs(Store $store$loggingData)
  120.     {
  121.         $receiver null;
  122.         $society null;
  123.         $societyGroup $store->getSocietyGroup();
  124.         $args = array(
  125.             "object_id"                    =>    $store->getId(),
  126.             "object_bundle"                =>    "Client",
  127.             "object_entity"                =>    "Store",
  128.             "object_display"            =>    $store->display(),
  129.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  130.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  131.             "society_group"                =>    $societyGroup,
  132.             "society"                    =>    $society,
  133.             "info"                        =>    $loggingData['info'],
  134.             "special_author"            =>    $loggingData['special_author'],
  135.         );
  136.         return $args;
  137.     }
  138. }