src/AppRemix/Logging/Objects/SocietySettingsLog.php line 24

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/AppRemix/Logging/Objects/SocietySettingsLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\AppRemix\Logging\Objects;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\AppRemix\Entity\SocietySettings;
  8. use App\AppRemix\Logging\Tools;
  9. use App\Services\LogTools;
  10. /**
  11.  * Activity log for a tenant's SocietySettings (the devis and invoice clauses).
  12.  */
  13. class SocietySettingsLog
  14. {
  15.     private array $pendingLogArgs = [];
  16.     public function __construct(ManagerRegistry $doctrine, LogTools $logTools, Tools $tools)
  17.     {
  18.         $this->em = $doctrine->getManager();
  19.         $this->logTools = $logTools;
  20.         $this->tools = $tools;
  21.     }
  22.     public function logCreation(SocietySettings $settings)
  23.     {
  24.         $pendingLogArgs = [];
  25.         //----------------------------------------------------------------------
  26.         // Fetch eventual info stored in the object
  27.         $loggingData = $this->logTools->handleLoggingData($settings);
  28.         $info = $loggingData['info'];
  29.         $ignore = $loggingData['ignore'];
  30.         if ($ignore) return $pendingLogArgs;
  31.         //----------------------------------------------------------------------
  32.         // Init base log args
  33.         // This does not contain action
  34.         $args = $this->initArgs($settings, $loggingData);
  35.         //----------------------------------------------------------------------
  36.         $action = "society_settings_add";
  37.         $args["action"] = $action;
  38.         $pendingLogArgs[] = $args;
  39.         return $pendingLogArgs;
  40.     }
  41.     public function logChanges(SocietySettings $settings, $changes)
  42.     {
  43.         $pendingLogArgs = [];
  44.         //----------------------------------------------------------------------
  45.         // Fetch eventual info stored in the object
  46.         $loggingData = $this->logTools->handleLoggingData($settings);
  47.         $info = $loggingData['info'];
  48.         $ignore = $loggingData['ignore'];
  49.         if ($ignore) return $pendingLogArgs;
  50.         //----------------------------------------------------------------------
  51.         // Init base log args
  52.         // This does not contain action
  53.         $args = $this->initArgs($settings, $loggingData);
  54.         //----------------------------------------------------------------------
  55.         $action = "society_settings_edit";
  56.         // No json column: both clauses are plain text and go through handleBasicChanges().
  57.         $jsonChanges = array(
  58.         );
  59.         $basicChanges = array(
  60.             "devisClause",
  61.             "invoiceClause",
  62.         );
  63.         // See what changed and log (members first)
  64.         foreach ($changes as $key => $change)
  65.         {
  66.             // Something to skip ?
  67.             if (false)
  68.             {
  69.                 continue;
  70.             }
  71.             $name = $this->logTools->camelToSnakeCase($key);
  72.             $args["action"]    = $action."_".$name;
  73.             $before = $change[0];
  74.             $after = $change[1];
  75.             if (in_array($key, $jsonChanges))
  76.             {
  77.                 $pendingLogArgs[] = $this->tools->handleJsonChanges($args, $before, $after);
  78.                 continue;
  79.             }
  80.             if (in_array($key, $basicChanges))
  81.             {
  82.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
  83.                 continue;
  84.             }
  85.         }
  86.         return $pendingLogArgs;
  87.     }
  88.     public function logRemoval(SocietySettings $settings)
  89.     {
  90.         $pendingLogArgs = [];
  91.         return $pendingLogArgs;
  92.     }
  93.     private function initArgs(SocietySettings $settings, $loggingData)
  94.     {
  95.         $args = array(
  96.             "object_id"                    =>    $settings->getId(),
  97.             "object_entity"                =>    "SocietySettings",
  98.             "object_display"            =>    $settings->display(),
  99.             "society"                    =>    $settings->getSociety(),
  100.             "info"                        =>    $loggingData['info'],
  101.         );
  102.         return $args;
  103.     }
  104. }