src/Logging/Activity/EInvoicingInboundInvoiceNoteLog.php line 24

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/EInvoicingInboundInvoiceNoteLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\EInvoicing\EInvoicingInboundInvoiceNote;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. /**
  11.  * Activity log handler for the free-text notes of the received invoices.
  12.  *
  13.  * Plan.io Task #4683
  14.  */
  15. class EInvoicingInboundInvoiceNoteLog
  16. {
  17.     public function __construct(ManagerRegistry $doctrine, LogTools $logTools, Tools $tools)
  18.     {
  19.         $this->em = $doctrine->getManager();
  20.         $this->logTools = $logTools;
  21.         $this->tools = $tools;
  22.     }
  23.     public function logCreation(EInvoicingInboundInvoiceNote $note)
  24.     {
  25.         $pendingLogArgs = [];
  26.         //----------------------------------------------------------------------
  27.         // Fetch eventual info stored in the object
  28.         $loggingData = $this->logTools->handleLoggingData($note);
  29.         $ignore = $loggingData['ignore'];
  30.         if ($ignore) return $pendingLogArgs;
  31.         //----------------------------------------------------------------------
  32.         // Init base log args
  33.         // This does not contain action
  34.         $args = $this->initArgs($note, $loggingData);
  35.         //----------------------------------------------------------------------
  36.         $args["action"] = "einvoicing_inbound_invoice_note_add";
  37.         $pendingLogArgs[] = $args;
  38.         return $pendingLogArgs;
  39.     }
  40.     public function logChanges(EInvoicingInboundInvoiceNote $note, $changes)
  41.     {
  42.         $pendingLogArgs = [];
  43.         //----------------------------------------------------------------------
  44.         // Fetch eventual info stored in the object
  45.         $loggingData = $this->logTools->handleLoggingData($note);
  46.         $ignore = $loggingData['ignore'];
  47.         if ($ignore) return $pendingLogArgs;
  48.         //----------------------------------------------------------------------
  49.         // Init base log args
  50.         // This does not contain action
  51.         $args = $this->initArgs($note, $loggingData);
  52.         //----------------------------------------------------------------------
  53.         $action = "einvoicing_inbound_invoice_note_edit";
  54.         $basicChanges = array(
  55.             "info",
  56.         );
  57.         // See what changed and log (members first)
  58.         foreach ($changes as $key => $change)
  59.         {
  60.             $name = $this->logTools->camelToSnakeCase($key);
  61.             $args["action"]    = $action."_".$name;
  62.             $before = $change[0];
  63.             $after = $change[1];
  64.             if (in_array($key, $basicChanges))
  65.             {
  66.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args, $before, $after);
  67.                 continue;
  68.             }
  69.         }
  70.         return $pendingLogArgs;
  71.     }
  72.     public function logRemoval(EInvoicingInboundInvoiceNote $note)
  73.     {
  74.         $pendingLogArgs = [];
  75.         //----------------------------------------------------------------------
  76.         // Fetch eventual info stored in the object
  77.         $loggingData = $this->logTools->handleLoggingData($note);
  78.         $ignore = $loggingData['ignore'];
  79.         if ($ignore) return $pendingLogArgs;
  80.         //----------------------------------------------------------------------
  81.         // Init base log args
  82.         // This does not contain action
  83.         $args = $this->initArgs($note, $loggingData);
  84.         //----------------------------------------------------------------------
  85.         $args["action"] = "einvoicing_inbound_invoice_note_delete";
  86.         $pendingLogArgs[] = $args;
  87.         return $pendingLogArgs;
  88.     }
  89.     private function initArgs(EInvoicingInboundInvoiceNote $note, $loggingData)
  90.     {
  91.         $society = $note->getSociety();
  92.         $societyGroup = $note->getSocietyGroup();
  93.         $args = array(
  94.             "object_id"                    =>    $note->getId(),
  95.             "object_bundle"                =>    "EInvoicing",
  96.             "object_entity"                =>    "EInvoicingInboundInvoiceNote",
  97.             "object_display"            =>    $note->display(),
  98.             "society_group"                =>    $societyGroup,
  99.             "society"                    =>    $society,
  100.             "info"                        =>    $loggingData['info'],
  101.             "special_author"            =>    $loggingData['special_author'],
  102.         );
  103.         return $args;
  104.     }
  105. }