src/Logging/Activity/IkeaServiceOrderLog.php line 20

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/IkeaServiceOrderLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Ikea\ServiceOrder;
  8. use App\Logging\Tools;
  9. use App\Services\LogTools;
  10. class IkeaServiceOrderLog
  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(ServiceOrder $serviceOrder)
  20.     {
  21.         $pendingLogArgs = [];
  22.         //----------------------------------------------------------------------
  23.         // Fetch eventual info stored in the object
  24.         $loggingData $this->logTools->handleLoggingData($serviceOrder);
  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($serviceOrder$loggingData);
  33.         //----------------------------------------------------------------------
  34.         $action "ikea_service_order_add";
  35.         $args["action"] = $action;
  36.         // Plan.io Task #3745
  37.         $status null;
  38.         if ($serviceOrder->getStatus() !== null)
  39.         {
  40.             $status $serviceOrder->getStatus()->getValue();
  41.             $args["new_value"] = $status;
  42.         }
  43.         $pendingLogArgs[] = $args;
  44.         return $pendingLogArgs;
  45.     }
  46.     public function logChanges(ServiceOrder $serviceOrder$changes)
  47.     {
  48.         $pendingLogArgs = [];
  49.         //----------------------------------------------------------------------
  50.         // Fetch eventual info stored in the object
  51.         $loggingData $this->logTools->handleLoggingData($serviceOrder);
  52.         $info $loggingData['info'];
  53.         $specialAuthor $loggingData['special_author'];
  54.         $ignore $loggingData['ignore'];
  55.         if ($ignore) return $pendingLogArgs;
  56.         //----------------------------------------------------------------------
  57.         // Init base log args
  58.         // This does not contain action
  59.         $args $this->initArgs($serviceOrder$loggingData);
  60.         //----------------------------------------------------------------------
  61.         $action "ikea_service_order_edit";
  62.         // This is triggered when we are actually changing the connected Address object
  63.         // The changes in the actual object are handled in AddressLog
  64.         $addressChanges = array(
  65.         );
  66.         $basicChanges = array(
  67.         );
  68.         $basicBoolChanges = array(
  69.         );
  70.         $dateChanges = array(
  71.             "statusSentDate",
  72.         );
  73.         $labelChanges = array(
  74.             "status",
  75.         );
  76.         // Method getLogLabel() should be defined for these objects/entities
  77.         $objectChanges = array(
  78.             "mission",
  79.             "society",
  80.         );
  81.         // See what changed and log (members first)
  82.         foreach ($changes as $key => $change)
  83.         {
  84.             // Something to skip ?
  85.             if (false)
  86.             {
  87.                 continue;
  88.             }
  89.             $name $this->logTools->camelToSnakeCase($key);
  90.             $args["action"]    = $action."_".$name;
  91.             $before $change[0];
  92.             $after $change[1];
  93.             if (in_array($key$addressChanges))
  94.             {
  95.                 $pendingLogArgs[] = $this->tools->handleAddressChanges($args$before$after);
  96.                 continue;
  97.             }
  98.             if (in_array($key$basicChanges))
  99.             {
  100.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  101.                 continue;
  102.             }
  103.             if (in_array($key$basicBoolChanges))
  104.             {
  105.                 $pendingLogArgs[] = $this->tools->handleBasicBoolChanges($args$before$after);
  106.                 continue;
  107.             }
  108.             if (in_array($key$dateChanges))
  109.             {
  110.                 // Display d/m/Y H:i => Add a fourth param true to handleDateChanges
  111.                 // dateChanges can be null
  112.                 $changeLogs $this->tools->handleDateChanges($args$before$aftertrue);
  113.                 if ($changeLogs !== null)
  114.                 {
  115.                     if ($key == "statusSentDate")
  116.                     {
  117.                         $changeLogs["action"] = "ikea_service_order_status_sent_to_ikea";
  118.                         if ($serviceOrder->getStatus() !== null)
  119.                         {
  120.                             $changeLogs["old_value"] = $serviceOrder->getStatus()->getValue();
  121.                             $changeLogs["new_value"] = $serviceOrder->getStatus()->getValue();
  122.                         }
  123.                     }
  124.                     $pendingLogArgs[] = $changeLogs;
  125.                 }
  126.                 continue;
  127.             }
  128.             if (in_array($key$labelChanges))
  129.             {
  130.                 if ($key == "status")
  131.                 {
  132.                     if (!empty($loggingData["action"]))
  133.                     {
  134.                         // Log Status Forced requires the author to be formated a certain way
  135.                         $args["action"] = $loggingData["action"];
  136.                         $args["special_author"] = "ikea_service_order";
  137.                     }
  138.                 }
  139.                 $changeLogs $this->tools->handleLabelChanges($args$before$after);
  140.                 $pendingLogArgs[] = $changeLogs;
  141.                 continue;
  142.             }
  143.             if (in_array($key$objectChanges))
  144.             {
  145.                 $changeLogs $this->tools->handleObjectChanges($args$before$after);
  146.                 if ($key == "mission")
  147.                 {
  148.                     $changeLogs["action"] = "ikea_service_order_link_to_mission";
  149.                 }
  150.                 $pendingLogArgs[] = $changeLogs;
  151.                 continue;
  152.             }
  153.         }
  154.         return $pendingLogArgs;
  155.     }
  156.     public function logRemoval(ServiceOrder $serviceOrder)
  157.     {
  158.         $pendingLogArgs = [];
  159.         return $pendingLogArgs;
  160.     }
  161.     private function initArgs(ServiceOrder $serviceOrder$loggingData)
  162.     {
  163.         $receiver $serviceOrder->getClient();
  164.         $society $serviceOrder->getSociety();
  165.         $societyGroup $serviceOrder->getSocietyGroup();
  166.         $mission $serviceOrder->getMission();
  167.         $args = array(
  168.             "object_id"                    =>    $serviceOrder->getId(),
  169.             "object_bundle"                =>    "Ikea",
  170.             "object_entity"                =>    "ServiceOrder",
  171.             "object_display"            =>    $serviceOrder->display(),
  172.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  173.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  174.             "object_mission_id"            =>    $mission !== null $mission->getId() : null,
  175.             "object_mission_display"    =>    $mission !== null $mission->getRef() : null,
  176.             
  177.             "society_group"                =>    $societyGroup,
  178.             "society"                    =>    $society,
  179.             "info"                        =>    $loggingData['info'],
  180.             "special_author"            =>    $loggingData['special_author'],
  181.         );
  182.         return $args;
  183.     }
  184. }