src/Logging/Activity/ClientLog.php line 24

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/ClientLog.php
  4. // Used only for Prospect conversion / edit for now
  5. // All other events are logged by either IndividualLog or StoreLog
  6. //----------------------------------------------------------------------
  7. namespace App\Logging\Activity;
  8. use Doctrine\Persistence\ManagerRegistry;
  9. use App\Entity\Client\Client;
  10. use App\Entity\Client\Individual;
  11. use App\Logging\Tools;
  12. use App\Services\LogTools;
  13. class ClientLog
  14. {
  15.     private array $pendingLogArgs = [];
  16.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsTools $tools)
  17.     {
  18.         $this->em $doctrine->getManager();
  19.         $this->logTools $logTools;
  20.         $this->tools $tools;
  21.     }
  22.     public function logCreation(Client $client)
  23.     {
  24.         $pendingLogArgs = [];
  25.         return $pendingLogArgs;
  26.     }
  27.     public function logChanges(Client $client$changes)
  28.     {
  29.         $individual $client->getIndividual();
  30.         if ($individual === null) return [];
  31.         $pendingLogArgs = [];
  32.         //----------------------------------------------------------------------
  33.         // Fetch eventual info stored in the object
  34.         $loggingData $this->logTools->handleLoggingData($client);
  35.         $info $loggingData['info'];
  36.         $specialAuthor $loggingData['special_author'];
  37.         $ignore $loggingData['ignore'];
  38.         if ($ignore) return $pendingLogArgs;
  39.         //----------------------------------------------------------------------
  40.         // Init base log args
  41.         // This does not contain action
  42.         $args $this->initArgs($client$individual$loggingData);
  43.         //----------------------------------------------------------------------
  44.         $action "prospect_edit";
  45.         // This is triggered when we are actually changing the connected Address object
  46.         // The changes in the actual object are handled in AddressLog
  47.         $addressChanges = array(
  48.         );
  49.         $basicChanges = array(
  50.             "commercialConditions",
  51.         );
  52.         $basicBoolChanges = array(
  53.             "prospect",
  54.         );
  55.         $dateChanges = array(
  56.             "relaunchDate",
  57.             "contractExpiryDate",
  58.         );
  59.         $labelChanges = array(
  60.         );
  61.         // Method getLogLabel() should be defined for these objects/entities
  62.         $objectChanges = array(
  63.         );
  64.         // See what changed and log (members first)
  65.         foreach ($changes as $key => $change)
  66.         {
  67.             // Something to skip ?
  68.             if (false)
  69.             {
  70.                 continue;
  71.             }
  72.             $name $this->logTools->camelToSnakeCase($key);
  73.             $args["action"]    = $action."_".$name;
  74.             $before $change[0];
  75.             $after $change[1];
  76.             if (in_array($key$addressChanges))
  77.             {
  78.                 $pendingLogArgs[] = $this->tools->handleAddressChanges($args$before$after);
  79.                 continue;
  80.             }
  81.             if (in_array($key$basicChanges))
  82.             {
  83.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  84.                 continue;
  85.             }
  86.             if (in_array($key$basicBoolChanges))
  87.             {
  88.                 $args $this->tools->handleBasicBoolChanges($args$before$after);
  89.                 $args["action"] = "prospect_convert_to_client";
  90.                 $args["old_value"] = null;
  91.                 $args["new_value"] = null;
  92.                 $pendingLogArgs[] = $args;
  93.                 continue;
  94.             }
  95.             if (in_array($key$dateChanges))
  96.             {
  97.                 // Display d/m/Y H:i => Add a fourth param true to handleDateChanges
  98.                 // dateChanges can be null
  99.                 $changeLogs $this->tools->handleDateChanges($args$before$after);
  100.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  101.                 continue;
  102.             }
  103.             if (in_array($key$labelChanges))
  104.             {
  105.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  106.                 continue;
  107.             }
  108.             if (in_array($key$objectChanges))
  109.             {
  110.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  111.                 continue;
  112.             }
  113.         }
  114.         return $pendingLogArgs;
  115.     }
  116.     public function logRemoval(Client $client)
  117.     {
  118.         $pendingLogArgs = [];
  119.         return $pendingLogArgs;
  120.     }
  121.     private function initArgs(Client $clientIndividual $individual$loggingData)
  122.     {
  123.         $objectEntity "Client.Prospect";
  124.         $receiver $client;
  125.         $society $individual->getSociety();
  126.         $societyGroup $society->getSocietyGroup();
  127.         $args = array(
  128.             "object_id"                    =>    $individual->getId(),
  129.             "object_bundle"                =>    "Platform",
  130.             "object_entity"                =>    $objectEntity,
  131.             "object_display"            =>    $individual->displayForLogging(),
  132.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  133.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  134.             "society_group"                =>    $societyGroup,
  135.             "society"                    =>    $society,
  136.             "info"                        =>    $loggingData['info'],
  137.             "special_author"            =>    $loggingData['special_author'],
  138.         );
  139.         return $args;
  140.     }
  141. }