src/Logging/Activity/AccessClientLog.php line 21

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/AccessClientLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\AccessClient\AccessClient;
  8. use App\Entity\AccessClient\AccessClientRecord;
  9. use App\Logging\Tools;
  10. use App\Services\LogTools;
  11. class AccessClientLog
  12. {
  13.     private array $pendingLogArgs = [];
  14.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsTools $tools)
  15.     {
  16.         $this->em $doctrine->getManager();
  17.         $this->logTools $logTools;
  18.         $this->tools $tools;
  19.     }
  20.     public function logCreation(AccessClient $accessClient)
  21.     {
  22.         $pendingLogArgs = [];
  23.         //----------------------------------------------------------------------
  24.         // Fetch eventual info stored in the object
  25.         $loggingData $this->logTools->handleLoggingData($accessClient);
  26.         $info $loggingData['info'];
  27.         $specialAuthor $loggingData['special_author'];
  28.         $ignore $loggingData['ignore'];
  29.         if ($ignore) return $pendingLogArgs;
  30.         //----------------------------------------------------------------------
  31.         // Init base log args
  32.         // This does not contain action
  33.         // $args = $this->initArgs($accessClient, $loggingData);
  34.         //----------------------------------------------------------------------
  35.         $action "access_client_add";
  36.         foreach ($accessClient->getAccessClientRecords() as $accessClientRecord)
  37.         {
  38.             $args $this->initArgs($accessClient$accessClientRecord$loggingData);
  39.             $args["action"] = $action;
  40.             $pendingLogArgs[] = $args;            
  41.         }
  42.         return $pendingLogArgs;
  43.     }
  44.     public function logChanges(AccessClient $accessClient$changes)
  45.     {
  46.         $pendingLogArgs = [];
  47.         //----------------------------------------------------------------------
  48.         // Fetch eventual info skeletond in the object
  49.         $loggingData $this->logTools->handleLoggingData($accessClient);
  50.         $info $loggingData['info'];
  51.         $specialAuthor $loggingData['special_author'];
  52.         $ignore $loggingData['ignore'];
  53.         if ($ignore) return $pendingLogArgs;
  54.         //----------------------------------------------------------------------
  55.         // Init base log args
  56.         // This does not contain action
  57.         // $args = $this->initArgs($accessClient, $loggingData);
  58.         //----------------------------------------------------------------------
  59.         $action "access_client_edit";
  60.         // This is triggered when we are actually changing the connected Address object
  61.         // The changes in the actual object are handled in AddressLog
  62.         $addressChanges = array(
  63.         );
  64.         $basicChanges = array(
  65.             "password",
  66.             "lostPwdCode",
  67.         );
  68.         $basicBoolChanges = array(
  69.             "isActive",
  70.             "denyEmail",
  71.         );
  72.         $dateChanges = array(
  73.             "activationDate",
  74.         );
  75.         $labelChanges = array(
  76.         );
  77.         // Method getLogLabel() should be defined for these objects/entities
  78.         $objectChanges = array(
  79.         );
  80.         foreach ($accessClient->getAccessClientRecords() as $accessClientRecord)
  81.         {
  82.             $args $this->initArgs($accessClient$accessClientRecord$loggingData);
  83.             // See what changed and log (members first)
  84.             foreach ($changes as $key => $change)
  85.             {
  86.                 // Something to skip ?
  87.                 if (false)
  88.                 {
  89.                     continue;
  90.                 }
  91.                 $name $this->logTools->camelToSnakeCase($key);
  92.                 $args["action"]    = $action."_".$name;
  93.                 $before $change[0];
  94.                 $after $change[1];
  95.                 if (in_array($key$addressChanges))
  96.                 {
  97.                     $pendingLogArgs[] = $this->tools->handleAddressChanges($args$before$after);
  98.                     continue;
  99.                 }
  100.                 if (in_array($key$basicChanges))
  101.                 {
  102.                     $args $this->tools->handleBasicChanges($args$before$after);
  103.                     if ($key == "password")
  104.                     {
  105.                         $args['old_value'] = null;
  106.                         $args['new_value'] = null;
  107.                     }
  108.                     $pendingLogArgs[] = $args;
  109.                     continue;
  110.                 }
  111.                 if (in_array($key$basicBoolChanges))
  112.                 {
  113.                     $args $this->tools->handleBasicBoolChanges($args$before$after);
  114.                     if ($key == "isActive")
  115.                     {
  116.                         if (!$before && $after$args['action'] = "access_client_activate";
  117.                         if ($before && !$after$args['action'] = "access_client_deactivate";
  118.                         $args['old_value'] = null;
  119.                         $args['new_value'] = null;
  120.                     }
  121.                     $pendingLogArgs[] = $args;
  122.                     continue;
  123.                 }
  124.                 if (in_array($key$dateChanges))
  125.                 {
  126.                     // dateChanges can be null
  127.                     $changeLogs $this->tools->handleDateChanges($args$before$after);
  128.                     if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  129.                     continue;
  130.                 }
  131.                 if (in_array($key$labelChanges))
  132.                 {
  133.                     $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  134.                     continue;
  135.                 }
  136.                 if (in_array($key$objectChanges))
  137.                 {
  138.                     $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  139.                     continue;
  140.                 }
  141.             }
  142.         }
  143.         return $pendingLogArgs;
  144.     }
  145.     public function logRemoval(AccessClient $accessClient)
  146.     {
  147.         $pendingLogArgs = [];
  148.         return $pendingLogArgs;
  149.     }
  150.     private function initArgs(AccessClient $accessClientAccessClientRecord $accessClientRecord$loggingData)
  151.     {
  152.         // Returns the Society of the AccessClient.humanResource
  153.         $society $accessClientRecord->getClient()->getSociety();
  154.         $societyGroup $accessClientRecord->getSocietyGroup();
  155.         $args = array(
  156.             "object_id"                    =>    $accessClient->getId(),
  157.             "object_bundle"                =>    "Activity",
  158.             "object_entity"                =>    "AccessClient",
  159.             "object_display"            =>    $accessClient->display(),
  160.             "society_group"                =>    $societyGroup,
  161.             "society"                    =>    $society,
  162.             "info"                        =>    $loggingData['info'],
  163.             "special_author"            =>    $loggingData['special_author'],
  164.         );
  165.         return $args;
  166.     }
  167. }