src/Logging/Activity/ProjectNotebookLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/ProjectNotebookLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Logging\Tools;
  8. use App\Services\LogTools;
  9. use App\Entity\ProjectManager\ProjectNotebook;
  10. class ProjectNotebookLog
  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(ProjectNotebook $projectNotebook)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($projectNotebook);
  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($projectNotebook$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $action "project_notebook_add";
  35.         $args["action"] = $action;
  36.         $pendingLogArgs[] = $args;
  37.         return $pendingLogArgs;
  38.     }
  39.     public function logChanges(ProjectNotebook $projectNotebook$changes)
  40.     {
  41.         $pendingLogArgs = [];
  42.         //----------------------------------------------------------------------
  43.         // Fetch eventual info stored in the object
  44.         $loggingData $this->logTools->handleLoggingData($projectNotebook);
  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($projectNotebook$loggingData);
  53.         //----------------------------------------------------------------------
  54.         $action "project_notebook_edit";
  55.         $basicChanges = array(    
  56.             // "ikeaMethodVersion",        
  57.         );
  58.         $basicBoolChanges = array(
  59.             "visibleToClient",
  60.         );
  61.         $dateChanges = array(
  62.         );
  63.         $labelChanges = array(
  64.         );
  65.         // Method getLogLabel() should be defined for these objects/entities
  66.         $objectChanges = array(
  67.             "group",
  68.         );
  69.         // See what changed and log (members first)
  70.         foreach ($changes as $key => $change)
  71.         {
  72.             $name $this->logTools->camelToSnakeCase($key);
  73.             $args["action"]    = $action."_".$name;
  74.             $before $change[0];
  75.             $after $change[1];
  76.             // Handle Method Version
  77.             if ($key == "ikeaMethodVersion")
  78.             {
  79.                 $pendingLogArgs[] = $this->tools->handleProjectNotebookIkeaMethodVersion($args$before$after);
  80.                 continue;
  81.             }
  82.             if (in_array($key$basicChanges))
  83.             {
  84.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  85.                 continue;
  86.             }
  87.             if (in_array($key$basicBoolChanges))
  88.             {
  89.                 $pendingLogArgs[] = $this->tools->handleBasicBoolChanges($args$before$after);
  90.                 continue;
  91.             }
  92.             if (in_array($key$dateChanges))
  93.             {
  94.                 // dateChanges can be null
  95.                 $changeLogs $this->tools->handleDateChanges($args$before$after);
  96.                 if ($changeLogs !== null$pendingLogArgs[] = $changeLogs;
  97.                 continue;
  98.             }
  99.             if (in_array($key$labelChanges))
  100.             {
  101.                 $pendingLogArgs[] = $this->tools->handleLabelChanges($args$before$after);
  102.                 continue;
  103.             }
  104.             if (in_array($key$objectChanges))
  105.             {
  106.                 $pendingLogArgs[] = $this->tools->handleObjectChanges($args$before$after);
  107.                 continue;
  108.             }
  109.         }
  110.         return $pendingLogArgs;
  111.     }
  112.     public function logRemoval(ProjectNotebook $projectNotebook)
  113.     {
  114.         $pendingLogArgs = [];
  115.         //----------------------------------------------------------------------
  116.         // Fetch eventual info skeletond in the object
  117.         $loggingData $this->logTools->handleLoggingData($projectNotebook);
  118.         $info $loggingData['info'];
  119.         $specialAuthor $loggingData['special_author'];
  120.         $ignore $loggingData['ignore'];
  121.         if ($ignore) return $pendingLogArgs;
  122.         //----------------------------------------------------------------------
  123.         // Init base log args
  124.         // This does not contain action
  125.         $args $this->initArgs($projectNotebook$loggingData);
  126.         //----------------------------------------------------------------------
  127.         $args["action"] = "project_notebook_delete";
  128.         $pendingLogArgs[] = $args;
  129.         return $pendingLogArgs;
  130.     }
  131.     private function initArgs(ProjectNotebook $notebook$loggingData)
  132.     {
  133.         $receiver null;
  134.         $society null;
  135.         $societyGroup $notebook->getSocietyGroup();
  136.         $mission $notebook->getMission();
  137.         $society null;
  138.         $client null;
  139.         if ($mission !== null)
  140.         {
  141.             $client $mission->getReceiver();
  142.             $society $mission->getSociety();
  143.         }
  144.         $module null;
  145.         $item null;
  146.         $args = array(
  147.             "object_id"                    =>    $notebook->getId(),
  148.             "object_bundle"                =>    "ProjectManager",
  149.             "object_entity"                =>    "ProjectNotebook",
  150.             "object_display"            =>    $notebook->display(),
  151.             "society_group"                =>    $societyGroup,    
  152.             "society"                    =>    $society,
  153.             "object_client_id"            =>    $client !== null $client->getId() : null,
  154.             "object_client_display"        =>    $client !== null $client->getName() : null,
  155.             "object_mission_id"            =>    $mission !== null $mission->getId() : null,
  156.             "object_mission_display"    =>    $mission !== null $mission->getRef() : null,
  157.             
  158.             "project_notebook_id"       =>  $notebook !== null $notebook->getId() : null,
  159.             "module_code"               =>  $module !== null $module['code'] : null,
  160.             "module_display"            =>  $module !== null $module['label'] : null,
  161.             "info"                        =>    $loggingData['info'],
  162.             "special_author"            =>    $loggingData['special_author'],
  163.         );
  164.         return $args;
  165.     }
  166. }