src/AppRemix/Logging/Objects/MissionLog.php line 21

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/AppRemix/Logging/MissionLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\AppRemix\Logging\Objects;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\AppRemix\Entity\Mission;
  8. use App\AppRemix\Logging\Tools;
  9. use App\Services\LogTools;
  10. class MissionLog
  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(Mission $mission)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData = $this->logTools->handleLoggingData($mission);
  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($mission, $loggingData);
  32.         //----------------------------------------------------------------------
  33.         $action = "mission_add";
  34.         $args["action"] = $action;
  35.         $pendingLogArgs[] = $args;
  36.         return $pendingLogArgs;
  37.     }
  38.     public function logChanges(Mission $mission, $changes)
  39.     {
  40.         $pendingLogArgs = [];
  41.         //----------------------------------------------------------------------
  42.         // Fetch eventual info stored in the object
  43.         $loggingData = $this->logTools->handleLoggingData($mission);
  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($mission, $loggingData);
  51.         //----------------------------------------------------------------------
  52.         $action = "mission_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.             "interventionAddress",
  57.         );
  58.         $basicChanges = array(
  59.             "title",
  60.             "clientName",
  61.             "clientEmail",
  62.             "clientPhone",
  63.             "interventionAddress",
  64.             "archived",
  65.         );
  66.         // See what changed and log (members first)
  67.         foreach ($changes as $key => $change)
  68.         {
  69.             // Something to skip ?
  70.             if (false)
  71.             {
  72.                 continue;
  73.             }
  74.             $name = $this->logTools->camelToSnakeCase($key);
  75.             $args["action"]    = $action."_".$name;
  76.             $before = $change[0];
  77.             $after = $change[1];
  78.             if (in_array($key, $jsonChanges))
  79.             {
  80.                 $pendingLogArgs[] = $this->tools->handleJsonChanges($args, $before, $after);
  81.                 continue;
  82.             }
  83.             if (in_array($key, $basicChanges))
  84.             {
  85.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
  86.                 continue;
  87.             }
  88.         }
  89.         return $pendingLogArgs;
  90.     }
  91.     public function logRemoval(Mission $mission)
  92.     {
  93.         $pendingLogArgs = [];
  94.         return $pendingLogArgs;
  95.     }
  96.     private function initArgs(Mission $mission, $loggingData)
  97.     {
  98.         $args = array(
  99.             "object_id"                    =>    $mission->getId(),            
  100.             "object_entity"                =>    "Mission",
  101.             "object_display"            =>    $mission->display(),
  102.             
  103.             "society"                    =>    $mission->getSociety(),
  104.             "info"                        =>    $loggingData['info'],            
  105.         );
  106.         return $args;
  107.     }
  108. }