src/Logging/Activity/ProjectNotebookItemLog.php line 18

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/ProjectNotebookItemLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use App\Entity\ProjectManager\Blueprint;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. use App\Entity\ProjectManager\ProjectNotebookItem;
  9. use App\Logging\Tools;
  10. use App\Services\LogTools;
  11. class ProjectNotebookItemLog
  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(ProjectNotebookItem $notebookItem)
  21.     {
  22.         $pendingLogArgs = [];
  23.         //----------------------------------------------------------------------
  24.         // Fetch eventual info stored in the object
  25.         $loggingData $this->logTools->handleLoggingData($notebookItem);
  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($notebookItem$loggingData);
  34.         //----------------------------------------------------------------------
  35.         $action "project_notebook_item_add";
  36.         $args["action"] = $action;
  37.         
  38.         $pendingLogArgs[] = $this->tools->handleProjectNotebookItemAdd($args$notebookItem);
  39.         // $pendingLogArgs[] = $args;
  40.         return $pendingLogArgs;
  41.     }
  42.     public function logChanges(ProjectNotebookItem $notebookItem$changes)
  43.     {
  44.         $pendingLogArgs = [];
  45.         //----------------------------------------------------------------------
  46.         // Fetch eventual info skeletond in the object
  47.         $loggingData $this->logTools->handleLoggingData($notebookItem);
  48.         $info $loggingData['info'];
  49.         $specialAuthor $loggingData['special_author'];
  50.         $ignore $loggingData['ignore'];
  51.         if ($ignore) return $pendingLogArgs;
  52.         //----------------------------------------------------------------------
  53.         // Init base log args
  54.         // This does not contain action
  55.         $args $this->initArgs($notebookItem$loggingData);
  56.         //----------------------------------------------------------------------
  57.         $action "project_notebook_item_edit";
  58.         $basicChanges = array(
  59.             "itemData",
  60.         );
  61.         // See what changed and log (members first)
  62.         foreach ($changes as $key => $change)
  63.         {
  64.             $name $this->logTools->camelToSnakeCase($key);
  65.             $args["action"]    = $action."_".$name;
  66.             $before $change[0];
  67.             $after $change[1];
  68.             if (in_array($key$basicChanges))
  69.             {
  70.                 if ($before == $after) continue;
  71.                 $pendingLogArgs[] = $this->tools->handleProjectNotebookItemUpdate($args$notebookItem$before$after);
  72.                 continue;
  73.             }
  74.         }
  75.         return $pendingLogArgs;
  76.     }
  77.     public function logRemoval(ProjectNotebookItem $notebookItem)
  78.     {
  79.         $pendingLogArgs = [];
  80.         //----------------------------------------------------------------------
  81.         // Fetch eventual info skeletond in the object
  82.         $loggingData $this->logTools->handleLoggingData($notebookItem);
  83.         $info $loggingData['info'];
  84.         $specialAuthor $loggingData['special_author'];
  85.         $ignore $loggingData['ignore'];
  86.         if ($ignore) return $pendingLogArgs;
  87.         //----------------------------------------------------------------------
  88.         // Init base log args
  89.         // This does not contain action
  90.         $args $this->initArgs($notebookItem$loggingData);
  91.         //----------------------------------------------------------------------
  92.         $args["action"] = "project_notebook_item_delete";
  93.         $pendingLogArgs[] = $args;
  94.         return $pendingLogArgs;
  95.     }
  96.     private function initArgs(ProjectNotebookItem $notebookItem$loggingData)
  97.     {
  98.         $notebook $notebookItem->getNotebook();
  99.         $societyGroup $notebook->getSocietyGroup();
  100.         $mission $notebook->getMission();
  101.         $society null;
  102.         $client null;
  103.         if ($mission !== null)
  104.         {
  105.             $client $mission->getReceiver();
  106.             $society $mission->getSociety();
  107.         }
  108.         $module null;
  109.         $itemCode $notebookItem->getItemCode();
  110.         $item Blueprint::getItemForCode($notebookItem->getItemCode());
  111.         if ($item !== null)
  112.         {
  113.             $module Blueprint::getModuleForCode($item['module_code']);
  114.         }        
  115.         $args = array(
  116.             "object_id"                    =>    $notebookItem->getId(),
  117.             "object_bundle"                =>    "ProjectManager",
  118.             "object_entity"                =>    "ProjectNotebookItem",
  119.             "object_display"            =>    $notebookItem->display(),
  120.             "society_group"                =>    $societyGroup,    
  121.             "society"                    =>    $society,
  122.             "object_client_id"            =>    $client !== null $client->getId() : null,
  123.             "object_client_display"        =>    $client !== null $client->getName() : null,
  124.             "object_mission_id"            =>    $mission !== null $mission->getId() : null,
  125.             "object_mission_display"    =>    $mission !== null $mission->getRef() : null,
  126.             
  127.             "project_notebook_id"       =>  $notebook !== null $notebook->getId() : null,
  128.             "module_code"               =>  $module !== null $module['code'] : null,
  129.             "module_display"            =>  $module !== null $module['label'] : null,
  130.             "info"                        =>    $loggingData['info'],
  131.             "special_author"            =>    $loggingData['special_author'],
  132.         );
  133.         return $args;
  134.     }
  135. }