src/Logging/Activity/DocumentLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/DocumentLog.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\Webapp\Document;
  10. class DocumentLog
  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(Document $document)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($document);
  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($document$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $args["action"] = "document_add";
  35.         if ($document->getRfi() !== null)
  36.         {
  37.             $args['action'] = "rfi_add";
  38.         }
  39.         elseif ($document->getRfiGC() !== null)
  40.         {
  41.             $args['action'] = "rfi_gc_add";
  42.         }
  43.         elseif ($document->getAnomaly() !== null)
  44.         {
  45.             $args['action'] = "anomaly_add";
  46.         }
  47.         elseif ($document->getAnomalyGC() !== null)
  48.         {
  49.             $args['action'] = "anomaly_gc_add";
  50.         }
  51.         elseif ($document->getReport() !== null)
  52.         {
  53.             $args['action'] = "report_add";
  54.         }
  55.         elseif ($document->getKVisitReport() !== null)
  56.         {
  57.             $args['action'] = "kvisit_report_add";
  58.         }
  59.         $pendingLogArgs[] = $args;
  60.         return $pendingLogArgs;
  61.     }
  62.     public function logChanges(Document $document$changes)
  63.     {
  64.         $pendingLogArgs = [];
  65.         //----------------------------------------------------------------------
  66.         // Fetch eventual info stored in the object
  67.         $loggingData $this->logTools->handleLoggingData($document);
  68.         $info $loggingData['info'];
  69.         $specialAuthor $loggingData['special_author'];
  70.         $ignore $loggingData['ignore'];
  71.         if ($ignore) return $pendingLogArgs;
  72.         //----------------------------------------------------------------------
  73.         // Init base log args
  74.         // This does not contain action
  75.         $args $this->initArgs($document$loggingData);
  76.         //----------------------------------------------------------------------
  77.         $action "document_edit";
  78.         $args["action"] = $action;
  79.         foreach ($changes as $key => $change)
  80.         {
  81.             $before $change[0];
  82.             $after $change[1];
  83.             if ($key == "archived")
  84.             {
  85.                 $newValue $change[1];
  86.                 if ($newValue)
  87.                 {
  88.                     // Document has been archived
  89.                     $action "document_archive";
  90.                 }
  91.                 else
  92.                 {
  93.                     // Archiving has been undone
  94.                     $action "document_archive_undo";
  95.                 }
  96.                 $args["action"] = $action;
  97.                 $pendingLogArgs[] = $args;
  98.                 continue;
  99.             }
  100.             if ($key == "visibleToClient")
  101.             {
  102.                 $action "document_edit_visible_to_client";
  103.                 $args["action"] = $action;
  104.                 $pendingLogArgs[] = $args;
  105.                 continue;
  106.             }
  107.             if ($key == "ikeaSent")
  108.             {
  109.                 $ikeaAction "ikea_service_order_document_sent_to_ikea";
  110.                 $args["action"] = $ikeaAction;
  111.                 $args["new_value"] = $after;                
  112.                 $pendingLogArgs[] = $args;
  113.                 $ikeaArgs $this->tools->handleIkeaServiceOrder($after$document$ikeaAction$info$specialAuthor);
  114.                 foreach ($ikeaArgs as $argsItem)
  115.                 {
  116.                     $pendingLogArgs[] = $argsItem;
  117.                 }
  118.                 continue;
  119.             }
  120.         }
  121.         return $pendingLogArgs;
  122.     }
  123.     public function logRemoval(Document $document)
  124.     {
  125.         return [];
  126.     }
  127.     private function initArgs(Document $document$loggingData)
  128.     {
  129.         $receiver $document->getReceiver();
  130.         $society $document->getSociety();
  131.         $societyGroup $society->getSocietyGroup();
  132.         $mission $document->getMission();
  133.         $args = array(
  134.             "object_id"                    =>    $document->getId(),
  135.             "object_bundle"                =>    "Webapp",
  136.             "object_entity"                =>    "Document",
  137.             "object_display"            =>    $document->getRef(),
  138.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  139.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  140.             "object_mission_id"            =>    $mission !== null $mission->getId() : null,
  141.             "object_mission_display"    =>    $mission !== null $mission->getRef() : null,
  142.             
  143.             "society_group"                =>    $societyGroup,
  144.             "society"                    =>    $society,
  145.             "info"                        =>    $loggingData['info'],
  146.             "special_author"            =>    $loggingData['special_author'],
  147.         );
  148.         return $args;
  149.     }
  150. }
  151. /*
  152. // Handle sharing
  153. // If devis.mission.author != devis.mission.owner log invoice creation to both society groups
  154. $mission = $devis->getMission();
  155. $double = false;
  156. if ($mission !== null)
  157. {
  158.     $societyGroupAuthor = $mission->getSocietyGroupAuthor();
  159.     $societyGroupOwner = $mission->getSocietyGroupOwner();
  160.     if (!$societyGroupAuthor->equals($societyGroupOwner))
  161.     {
  162.         $double = true;
  163.     }
  164. }
  165. if ($double)
  166. {
  167.     // invoice.societyGroup is the invoice.mission.societyGroupOwner
  168.     // so we need to log to the invoice.mission.societyGroupAuthor
  169.     // and thus the society is the one of the mission
  170.     $argsBis = $args;
  171.     $argsBis["society_group"] = $societyGroupAuthor;
  172.     $argsBis["society"] = $mission->getSociety();
  173.     $pendingLogArgs[] = $argsBis;
  174. }
  175. */