src/Logging/HR/RHForm/LeaveLog.php line 21

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/HR/RhForm/LeaveLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\HR\RHForm;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\HR\RhForm\Leave;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class LeaveLog
  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(Leave $rhFormChild)
  20.     {
  21.         // Logged in the main object
  22.         $pendingLogArgs = [];
  23.         return $pendingLogArgs;
  24.     }
  25.     public function logChanges(Leave $rhFormChild$changes)
  26.     {
  27.         $pendingLogArgs = [];
  28.         //----------------------------------------------------------------------
  29.         // Fetch eventual info skeletond in the object
  30.         $loggingData $this->logTools->handleLoggingData($rhFormChild);
  31.         $info $loggingData['info'];
  32.         $specialAuthor $loggingData['special_author'];
  33.         $ignore $loggingData['ignore'];
  34.         if ($ignore) return $pendingLogArgs;
  35.         //----------------------------------------------------------------------
  36.         // Init base log args
  37.         // This does not contain action
  38.         $args $this->initArgs($rhFormChild$loggingData);
  39.         //----------------------------------------------------------------------
  40.         $action "rhform_edit";
  41.         $basicChanges = array(
  42.             'info',
  43.             'accidentPlace',
  44.             'accidentType',
  45.             'accidentDetails',
  46.             'nbDays'
  47.         );
  48.         $basicBoolChanges = array(
  49.         );
  50.         $dateChanges = array(
  51.             'startDate',
  52.             'endDate',
  53.             'comebackDate',
  54.             'accidentDate',
  55.             'accidentHour',
  56.         );
  57.         $labelChanges = array(
  58.             "type",
  59.         );
  60.         // Method getLogLabel() should be defined for these objects/entities
  61.         $objectChanges = array(            
  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$basicChanges))
  76.             {
  77.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  78.                 continue;
  79.             }
  80.             if (in_array($key$basicBoolChanges))
  81.             {
  82.                 $pendingLogArgs[] = $this->tools->handleBasicBoolChanges($args$before$after);
  83.                 continue;
  84.             }
  85.             if (in_array($key$dateChanges))
  86.             {
  87.                 // dateChanges can be null
  88.                 $changeLogs $this->tools->handleDateChanges($args$before$aftertrue);
  89.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  90.                 continue;
  91.             }
  92.             if (in_array($key$labelChanges))
  93.             {
  94.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  95.                 continue;
  96.             }
  97.             if (in_array($key$objectChanges))
  98.             {
  99.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  100.                 continue;
  101.             }
  102.         }
  103.         return $pendingLogArgs;
  104.     }
  105.     public function logRemoval(Leave $rhFormChild)
  106.     {
  107.         $pendingLogArgs = [];
  108.         return $pendingLogArgs;
  109.     }
  110.     private function initArgs(Leave $rhFormChild$loggingData)
  111.     {
  112.         $rhForm $rhFormChild->getRhForm();
  113.         $society $rhForm->getSociety();
  114.         $societyGroup $rhForm->getSocietyGroup();
  115.         // Add HumanResource logging
  116.         $humanResource $rhForm->getHumanResource();
  117.         $args = array(
  118.             "object_id"                    =>    $rhForm->getId(),
  119.             "object_bundle"                =>    "HR",
  120.             "object_entity"                =>    "RHForm",
  121.             "object_display"            =>    $rhForm->display(),
  122.             "object_human_resource_id"        =>    $humanResource !== null $humanResource->getId() : null,
  123.             "object_human_resource_display"    =>    $humanResource !== null $humanResource->display() : null,
  124.             "society_group"                =>    $societyGroup,
  125.             "society"                    =>    $society,
  126.             "info"                        =>    $loggingData['info'],
  127.             "special_author"            =>    $loggingData['special_author'],
  128.         );
  129.         return $args;
  130.     }
  131. }