src/Logging/HR/RHForm/RHFormLog.php line 17

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/HR/RHForm/RHFormLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\HR\RHForm;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\HR\RHForm\RHForm;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class RHFormLog
  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(RHForm $rhForm)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($rhForm);
  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($rhForm$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $action "rhform_add";
  35.         $args["action"] = $action;
  36.         $pendingLogArgs[] = $args;
  37.         return $pendingLogArgs;
  38.     }
  39.     public function logChanges(RHForm $rhForm$changes)
  40.     {
  41.         $pendingLogArgs = [];
  42.         //----------------------------------------------------------------------
  43.         // Fetch eventual info skeletond in the object
  44.         $loggingData $this->logTools->handleLoggingData($rhForm);
  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($rhForm$loggingData);
  53.         //----------------------------------------------------------------------
  54.         $action "rhform_edit";
  55.         $basicChanges = array(
  56.             'taskName',
  57.             'taskErrorInfo',
  58.         );
  59.         $basicBoolChanges = array(
  60.         );
  61.         $dateChanges = array(
  62.         );
  63.         $labelChanges = array(
  64.             "status",
  65.         );
  66.         // Method getLogLabel() should be defined for these objects/entities
  67.         $objectChanges = array(            
  68.         );
  69.         // See what changed and log (members first)
  70.         foreach ($changes as $key => $change)
  71.         {
  72.             // Something to skip ?
  73.             if (false)
  74.             {
  75.                 continue;
  76.             }
  77.             $name $this->logTools->camelToSnakeCase($key);
  78.             $args["action"]    = $action."_".$name;
  79.             $before $change[0];
  80.             $after $change[1];
  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.                 $pendingLogArgs[] = $this->tools->handleBasicBoolChanges($args$before$after);
  89.                 continue;
  90.             }
  91.             if (in_array($key$dateChanges))
  92.             {
  93.                 // dateChanges can be null
  94.                 $changeLogs $this->tools->handleDateChanges($args$before$after);
  95.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  96.                 continue;
  97.             }
  98.             if (in_array($key$labelChanges))
  99.             {
  100.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  101.                 continue;
  102.             }
  103.             if (in_array($key$objectChanges))
  104.             {
  105.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  106.                 continue;
  107.             }
  108.         }
  109.         return $pendingLogArgs;
  110.     }
  111.     public function logRemoval(RHForm $rhForm)
  112.     {
  113.         $pendingLogArgs = [];
  114.         return $pendingLogArgs;
  115.     }
  116.     private function initArgs(RHForm $rhForm$loggingData)
  117.     {
  118.         $society $rhForm->getSociety();
  119.         $societyGroup $rhForm->getSocietyGroup();
  120.         // Add HumanResource logging
  121.         $humanResource $rhForm->getHumanResource();
  122.         $args = array(
  123.             "object_id"                    =>    $rhForm->getId(),
  124.             "object_bundle"                =>    "HR",
  125.             "object_entity"                =>    "RHForm",
  126.             "object_display"            =>    $rhForm->display(),
  127.             "object_human_resource_id"        =>    $humanResource !== null $humanResource->getId() : null,
  128.             "object_human_resource_display"    =>    $humanResource !== null $humanResource->display() : null,
  129.             "society_group"                =>    $societyGroup,
  130.             "society"                    =>    $society,
  131.             "info"                        =>    $loggingData['info'],
  132.             "special_author"            =>    $loggingData['special_author'],
  133.         );
  134.         return $args;
  135.     }
  136. }