src/Logging/Activity/AddressLog.php line 30

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/AddressLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Component\PropertyAccess\PropertyAccess;
  8. use App\Entity\Access;
  9. use App\Entity\Client\Individual;
  10. use App\Entity\Client\Store;
  11. use App\Entity\HR\Application\Application;
  12. use App\Entity\HR\HumanResource;
  13. use App\Entity\Location\Address;
  14. use App\Entity\Mission\Mission;
  15. use App\Entity\Platform\Command\Command;
  16. use App\Entity\Platform\Devis\Devis;
  17. use App\Entity\Platform\Invoice\Invoice;
  18. use App\Entity\Platform\Supplier;
  19. use App\Entity\SocietyGroup;
  20. use App\Logging\DeletionContextLogger;
  21. use App\Services\LogTools;
  22. class AddressLog
  23. {
  24.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsDeletionContextLogger $contextLogger)
  25.     {
  26.         $this->em $doctrine->getManager();
  27.         $this->logTools $logTools;
  28.         $this->contextLogger $contextLogger;
  29.     }
  30.     public function logCreation(Address $address)
  31.     {
  32.         return [];
  33.     }
  34.     public function logChanges(Address $address$changes)
  35.     {
  36.         // Try to identify owner of address
  37.         $logs $this->logApplication($address$changes);
  38.         if (!empty($logs))
  39.         {
  40.             return $logs;
  41.         }
  42.         $logs $this->logCommand($address$changes);
  43.         if (!empty($logs))
  44.         {
  45.             return $logs;
  46.         }
  47.         $logs $this->logDevis($address$changes);
  48.         if (!empty($logs))
  49.         {
  50.             return $logs;
  51.         }
  52.         $logs $this->logHumanResource($address$changes);
  53.         if (!empty($logs))
  54.         {
  55.             return $logs;
  56.         }
  57.         $logs $this->logIndividual($address$changes);
  58.         if (!empty($logs))
  59.         {
  60.             return $logs;
  61.         }
  62.         $logs $this->logInvoice($address$changes);
  63.         if (!empty($logs))
  64.         {
  65.             return $logs;
  66.         }
  67.         $logs $this->logMission($address$changes);
  68.         if (!empty($logs))
  69.         {
  70.             return $logs;
  71.         }
  72.         $logs $this->logSocietyGroup($address$changes);
  73.         if (!empty($logs))
  74.         {
  75.             return $logs;
  76.         }
  77.         $logs $this->logStore($address$changes);
  78.         if (!empty($logs))
  79.         {
  80.             return $logs;
  81.         }
  82.         $logs $this->logSupplier($address$changes);
  83.         if (!empty($logs))
  84.         {
  85.             return $logs;
  86.         }
  87.         // Nothing was found
  88.         return [];
  89.     }
  90.     public function logRemoval(Address $address)
  91.     {
  92.         return [];
  93.     }
  94.     public function logApplication(Address $address$changes)
  95.     {
  96.         $pendingLogArgs = [];
  97.         //----------------------------------------------------------------------
  98.         // Fetch eventual info stored in the object
  99.         $loggingData $this->logTools->handleLoggingData($address);
  100.         $info $loggingData['info'];
  101.         $specialAuthor $loggingData['special_author'];
  102.         $ignore $loggingData['ignore'];
  103.         if ($ignore) return $pendingLogArgs;
  104.         //----------------------------------------------------------------------
  105.         // Look for Devis
  106.         $action null;
  107.         $application $this->em->getRepository(Application::class)->findOneByAddress($address);
  108.         if ($application !== null)
  109.         {
  110.             $action "application_edit_address";
  111.         }
  112.         if ($action === null)
  113.         {
  114.             // The owner of the given address was not identified
  115.             return [];
  116.         }
  117.         // If we are here it means that we have an owner and an action
  118.         // Fill the common arguments
  119.         $args = array(
  120.             "action"                    =>    $action,
  121.             "object_id"                    =>    $application->getId(),
  122.             "object_bundle"                =>    "HR",
  123.             "object_entity"                =>    "Application",
  124.             "object_display"            =>    $application->getRef(),
  125.             "info"                        =>    $info,
  126.             "society_group"                =>    $application->getSocietyGroup(),
  127.             "society"                    =>    $application->getSociety(),
  128.             "special_author"            =>    $specialAuthor,
  129.         );
  130.         $values $this->computeAddressChanges($address$changes);
  131.         if ($values !== null)
  132.         {
  133.             $args["old_value"]    = $values["old"];
  134.             $args["new_value"]    = $values["new"];
  135.             $pendingLogArgs[] = $args;
  136.         }
  137.         return $pendingLogArgs;
  138.     }
  139.     public function logHumanResource(Address $address$changes)
  140.     {
  141.         $pendingLogArgs = [];
  142.         //----------------------------------------------------------------------
  143.         // Fetch eventual info stored in the object
  144.         $loggingData $this->logTools->handleLoggingData($address);
  145.         $info $loggingData['info'];
  146.         $specialAuthor $loggingData['special_author'];
  147.         $ignore $loggingData['ignore'];
  148.         if ($ignore) return $pendingLogArgs;
  149.         //----------------------------------------------------------------------
  150.         // Look for Devis
  151.         $action null;
  152.         $humanResource $this->em->getRepository(HumanResource::class)->findOneByAddress($address);
  153.         if ($humanResource !== null)
  154.         {
  155.             $action "human_resource_edit_address";
  156.         }
  157.         if ($action === null)
  158.         {
  159.             // The owner of the given address was not identified
  160.             return [];
  161.         }
  162.         // If we are here it means that we have an owner and an action
  163.         // Fill the common arguments
  164.         $args = array(
  165.             "action"                    =>    $action,
  166.             "object_id"                    =>    $humanResource->getId(),
  167.             "object_bundle"                =>    "HR",
  168.             "object_entity"                =>    "HumanResource",
  169.             "object_display"            =>    $humanResource->display(),
  170.             "object_human_resource_id"        =>    $humanResource !== null $humanResource->getId() : null,
  171.             "object_human_resource_display"    =>    $humanResource !== null $humanResource->display() : null,
  172.             
  173.             "info"                        =>    $info,
  174.             "society_group"                =>    $humanResource->getSocietyGroup(),
  175.             "society"                    =>    $humanResource->getSociety(),
  176.             "special_author"            =>    $specialAuthor,
  177.         );
  178.         $values $this->computeAddressChanges($address$changes);
  179.         if ($values !== null)
  180.         {
  181.             $args["old_value"]    = $values["old"];
  182.             $args["new_value"]    = $values["new"];
  183.             $pendingLogArgs[] = $args;
  184.         }
  185.         return $pendingLogArgs;
  186.     }
  187.     public function logIndividual(Address $address$changes)
  188.     {
  189.         $pendingLogArgs = [];
  190.         //----------------------------------------------------------------------
  191.         // Fetch eventual info stored in the object
  192.         $loggingData $this->logTools->handleLoggingData($address);
  193.         $info $loggingData['info'];
  194.         $specialAuthor $loggingData['special_author'];
  195.         $ignore $loggingData['ignore'];
  196.         if ($ignore) return $pendingLogArgs;
  197.         //----------------------------------------------------------------------
  198.         // Look for Individual
  199.         $action null;
  200.         $individual $this->em->getRepository(Individual::class)->findOneByAddress($address);
  201.         if ($individual !== null)
  202.         {
  203.             $action "individual_edit_address";
  204.         }
  205.         else
  206.         {
  207.             $individual $this->em->getRepository(Individual::class)->findOneByBillingAddress($address);
  208.             if ($individual !== null)
  209.             {
  210.                 $action "individual_edit_billing_address";
  211.             }
  212.         }
  213.         if ($action === null)
  214.         {
  215.             // The owner of the given address was not identified
  216.             return [];
  217.         }
  218.         // If we are here it means that we have an owner and an action
  219.         // Fill the common arguments
  220.         $args = array(
  221.             "action"                    =>    $action,
  222.             "object_id"                    =>    $individual->getId(),
  223.             "object_bundle"                =>    "Platform",
  224.             "object_entity"                =>    "Individual",
  225.             "object_display"            =>    $individual->display(),
  226.             "object_client_id"            =>    $individual->getClient()->getId(),
  227.             "object_client_display"        =>    $individual->getClient()->getName(),
  228.             "info"                        =>    $info,
  229.             "society_group"                =>    $individual->getSociety()->getGroup(),
  230.             "society"                    =>    $individual->getSociety(),
  231.             "special_author"            =>    $specialAuthor,
  232.         );
  233.         $values $this->computeAddressChanges($address$changes);
  234.         if ($values !== null)
  235.         {
  236.             $args["old_value"]    = $values["old"];
  237.             $args["new_value"]    = $values["new"];
  238.             $pendingLogArgs[] = $args;
  239.         }
  240.         return $pendingLogArgs;
  241.     }
  242.     public function logCommand(Address $address$changes)
  243.     {
  244.         $pendingLogArgs = [];
  245.         //----------------------------------------------------------------------
  246.         // Fetch eventual info stored in the object
  247.         $loggingData $this->logTools->handleLoggingData($address);
  248.         $info $loggingData['info'];
  249.         $specialAuthor $loggingData['special_author'];
  250.         $ignore $loggingData['ignore'];
  251.         if ($ignore) return $pendingLogArgs;
  252.         //----------------------------------------------------------------------
  253.         // Look for Devis
  254.         $action null;
  255.         $command $this->em->getRepository(Command::class)->findOneByInterventionAddress($address);
  256.         if ($command !== null)
  257.         {
  258.             $action "command_edit_intervention_address";
  259.         }
  260.         else
  261.         {
  262.             $command $this->em->getRepository(Command::class)->findOneByBillingAddress($address);
  263.             if ($command !== null)
  264.             {
  265.                 $action "command_edit_billing_address";
  266.             }
  267.             else
  268.             {
  269.                 $command $this->em->getRepository(Command::class)->findOneByDeliveryAddress($address);
  270.                 if ($command !== null)
  271.                 {
  272.                     $action "command_edit_delivery_address";
  273.                 }
  274.             }
  275.         }
  276.         if ($action === null)
  277.         {
  278.             // The owner of the given address was not identified
  279.             return [];
  280.         }
  281.         // If we are here it means that we have an owner and an action
  282.         $receiver $command->getReceiver();
  283.         // Fill the common arguments
  284.         $args = array(
  285.             "action"                    =>    $action,
  286.             "object_id"                    =>    $command->getId(),
  287.             "object_bundle"                =>    "Platform",
  288.             "object_entity"                =>    "Command",
  289.             "object_display"            =>    $command->getRef(),
  290.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  291.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  292.             "info"                        =>    $info,
  293.             "society_group"                =>    $command->getSociety()->getGroup(),
  294.             "society"                    =>    $command->getSociety(),
  295.             "special_author"            =>    $specialAuthor,
  296.         );
  297.         $values $this->computeAddressChanges($address$changes);
  298.         if ($values !== null)
  299.         {
  300.             $args["old_value"]    = $values["old"];
  301.             $args["new_value"]    = $values["new"];
  302.             $pendingLogArgs[] = $args;
  303.         }
  304.         return $pendingLogArgs;
  305.     }
  306.     public function logDevis(Address $address$changes)
  307.     {
  308.         $pendingLogArgs = [];
  309.         //----------------------------------------------------------------------
  310.         // Fetch eventual info stored in the object
  311.         $loggingData $this->logTools->handleLoggingData($address);
  312.         $info $loggingData['info'];
  313.         $specialAuthor $loggingData['special_author'];
  314.         $ignore $loggingData['ignore'];
  315.         if ($ignore) return $pendingLogArgs;
  316.         //----------------------------------------------------------------------
  317.         // Look for Devis
  318.         $action null;
  319.         $devis $this->em->getRepository(Devis::class)->findOneByInterventionAddress($address);
  320.         if ($devis !== null)
  321.         {
  322.             $action "devis_edit_intervention_address";
  323.         }
  324.         else
  325.         {
  326.             $devis $this->em->getRepository(Devis::class)->findOneByBillingAddress($address);
  327.             if ($devis !== null)
  328.             {
  329.                 $action "devis_edit_billing_address";
  330.             }
  331.         }
  332.         if ($action === null)
  333.         {
  334.             // The owner of the given address was not identified
  335.             return [];
  336.         }
  337.         // If we are here it means that we have an owner and an action
  338.         $receiver $devis->getReceiver();
  339.         // Fill the common arguments
  340.         $args = array(
  341.             "action"                    =>    $action,
  342.             "object_id"                    =>    $devis->getId(),
  343.             "object_bundle"                =>    "Platform",
  344.             "object_entity"                =>    "Devis",
  345.             "object_display"            =>    $devis->display(),
  346.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  347.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  348.             "info"                        =>    $info,
  349.             "society_group"                =>    $devis->getSociety()->getGroup(),
  350.             "society"                    =>    $devis->getSociety(),
  351.             "special_author"            =>    $specialAuthor,
  352.         );
  353.         $values $this->computeAddressChanges($address$changes);
  354.         if ($values !== null)
  355.         {
  356.             $args["old_value"]    = $values["old"];
  357.             $args["new_value"]    = $values["new"];
  358.             $pendingLogArgs[] = $args;
  359.         }
  360.         return $pendingLogArgs;
  361.     }
  362.     public function logInvoice(Address $address$changes)
  363.     {
  364.         $pendingLogArgs = [];
  365.         //----------------------------------------------------------------------
  366.         // Fetch eventual info stored in the object
  367.         $loggingData $this->logTools->handleLoggingData($address);
  368.         $info $loggingData['info'];
  369.         $specialAuthor $loggingData['special_author'];
  370.         $ignore $loggingData['ignore'];
  371.         if ($ignore) return $pendingLogArgs;
  372.         //----------------------------------------------------------------------
  373.         // Look for Devis
  374.         $action null;
  375.         $invoice $this->em->getRepository(Invoice::class)->findOneByInterventionAddress($address);
  376.         if ($invoice !== null)
  377.         {
  378.             $action "invoice_edit";
  379.             if ($invoice->isDraft())
  380.             {
  381.                 $action "invoice_draft_edit";
  382.             }
  383.             $action .= "_intervention_address";
  384.         }
  385.         else
  386.         {
  387.             $invoice $this->em->getRepository(Invoice::class)->findOneByBillingAddress($address);
  388.             if ($invoice !== null)
  389.             {
  390.                 $action "invoice_edit";
  391.                 if ($invoice->isDraft())
  392.                 {
  393.                     $action "invoice_draft_edit";
  394.                 }
  395.                 $action .= "_billing_address";
  396.             }
  397.         }
  398.         if ($invoice === null)
  399.         {
  400.             // The owner of the given address was not identified
  401.             return [];
  402.         }
  403.         // If we are here it means that we have an owner and an action
  404.         $receiver $invoice->getReceiver();
  405.         // Fill the common arguments
  406.         $args = array(
  407.             "action"                    =>    $action,
  408.             "object_id"                    =>    $invoice->getId(),
  409.             "object_bundle"                =>    "Platform",
  410.             "object_entity"                =>    "Invoice",
  411.             "object_display"            =>    $invoice->display(),
  412.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  413.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  414.             "info"                        =>    $info,
  415.             "society_group"                =>    $invoice->getSociety()->getGroup(),
  416.             "society"                    =>    $invoice->getSociety(),
  417.             "special_author"            =>    $specialAuthor,
  418.         );
  419.         $values $this->computeAddressChanges($address$changes);
  420.         if ($values !== null)
  421.         {
  422.             $args["old_value"]    = $values["old"];
  423.             $args["new_value"]    = $values["new"];
  424.             $pendingLogArgs[] = $args;
  425.         }
  426.         return $pendingLogArgs;
  427.     }
  428.     public function logMission(Address $address$changes)
  429.     {
  430.         $pendingLogArgs = [];
  431.         //----------------------------------------------------------------------
  432.         // Fetch eventual info stored in the object
  433.         $loggingData $this->logTools->handleLoggingData($address);
  434.         $info $loggingData['info'];
  435.         $specialAuthor $loggingData['special_author'];
  436.         $ignore $loggingData['ignore'];
  437.         if ($ignore) return $pendingLogArgs;
  438.         //----------------------------------------------------------------------
  439.         // Look for Devis
  440.         $action null;
  441.         $mission $this->em->getRepository(Mission::class)->findOneByInterventionAddress($address);
  442.         if ($mission !== null)
  443.         {
  444.             $action "mission_edit_intervention_address";
  445.         }
  446.         else
  447.         {
  448.             $mission $this->em->getRepository(Mission::class)->findOneByBillingAddress($address);
  449.             if ($mission !== null)
  450.             {
  451.                 $action "mission_edit_billing_address";
  452.             }
  453.         }
  454.         if ($mission === null)
  455.         {
  456.             // The owner of the given address was not identified
  457.             return [];
  458.         }
  459.         // If we are here it means that we have an owner and an action
  460.         $receiver $mission->getReceiver();
  461.         // Fill the common arguments
  462.         $args = array(
  463.             "action"                    =>    $action,
  464.             "object_id"                    =>    $mission->getId(),
  465.             "object_bundle"                =>    "Mission",
  466.             "object_entity"                =>    "Mission",
  467.             "object_display"            =>    $mission->display(),
  468.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  469.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  470.             "info"                        =>    $info,
  471.             "society_group"                =>    $mission->getSociety()->getGroup(),
  472.             "society"                    =>    $mission->getSociety(),
  473.             "special_author"            =>    $specialAuthor,
  474.         );
  475.         // Handle sharing
  476.         $societyGroupAuthor $mission->getSocietyGroupAuthor();
  477.         $societyGroupOwner $mission->getSocietyGroupOwner();
  478.         $societyAuthor $mission->getSociety();
  479.         $societyOwner $mission->getSocietyOwner();
  480.         $double false;
  481.         if (!$societyGroupAuthor->equals($societyGroupOwner))
  482.         {
  483.             $double true;
  484.             $argsBis $args;
  485.             $argsBis["society_group"] = $societyGroupOwner;
  486.             $argsBis["society"] = $societyOwner;
  487.         }
  488.         $values $this->computeAddressChanges($address$changes);
  489.         if ($values !== null)
  490.         {
  491.             $args["old_value"]    = $values["old"];
  492.             $args["new_value"]    = $values["new"];
  493.             $pendingLogArgs[] = $args;
  494.             if ($double)
  495.             {
  496.                 $argsBis["old_value"] = $args["old_value"];
  497.                 $argsBis["new_value"] = $args["new_value"];
  498.                 $pendingLogArgs[] = $argsBis;
  499.             }
  500.         }
  501.         return $pendingLogArgs;
  502.     }
  503.     public function logSocietyGroup(Address $address$changes)
  504.     {
  505.         $pendingLogArgs = [];
  506.         //----------------------------------------------------------------------
  507.         // Fetch eventual info stored in the object
  508.         $loggingData $this->logTools->handleLoggingData($address);
  509.         $info $loggingData['info'];
  510.         $specialAuthor $loggingData['special_author'];
  511.         $ignore $loggingData['ignore'];
  512.         if ($ignore) return $pendingLogArgs;
  513.         //----------------------------------------------------------------------
  514.         // Look for Store
  515.         $action null;
  516.         $societyGroup $this->em->getRepository(SocietyGroup::class)->findOneByAddress($address);
  517.         if ($societyGroup !== null)
  518.         {
  519.             $action "society_group_edit_address";
  520.         }
  521.         else
  522.         {
  523.             $societyGroup $this->em->getRepository(SocietyGroup::class)->findOneByBillingAddress($address);
  524.             if ($societyGroup !== null)
  525.             {
  526.                 $action "society_group_edit_billing_address";
  527.             }
  528.         }
  529.         if ($action === null)
  530.         {
  531.             // The owner of the given address was not identified
  532.             return [];
  533.         }
  534.         // If we are here it means that we have an owner and an action
  535.         // Fill the common arguments
  536.         $args = array(
  537.             "action"                    =>    $action,
  538.             "object_id"                    =>    $societyGroup->getId(),
  539.             "object_bundle"                =>    "Platform",
  540.             "object_entity"                =>    "SocietyGroup",
  541.             "object_display"            =>    $societyGroup->display(),
  542.             "info"                        =>    $info,
  543.             "society_group"                =>    $societyGroup,
  544.             "special_author"            =>    $specialAuthor,
  545.         );
  546.         $values $this->computeAddressChanges($address$changes);
  547.         if ($values !== null)
  548.         {
  549.             $args["old_value"]    = $values["old"];
  550.             $args["new_value"]    = $values["new"];
  551.             $pendingLogArgs[] = $args;
  552.         }
  553.         return $pendingLogArgs;
  554.     }
  555.     public function logStore(Address $address$changes)
  556.     {
  557.         $pendingLogArgs = [];
  558.         //----------------------------------------------------------------------
  559.         // Fetch eventual info stored in the object
  560.         $loggingData $this->logTools->handleLoggingData($address);
  561.         $info $loggingData['info'];
  562.         $specialAuthor $loggingData['special_author'];
  563.         $ignore $loggingData['ignore'];
  564.         if ($ignore) return $pendingLogArgs;
  565.         //----------------------------------------------------------------------
  566.         // Look for Store
  567.         $action null;
  568.         $store $this->em->getRepository(Store::class)->findOneByAddress($address);
  569.         if ($store !== null)
  570.         {
  571.             $action "store_change_default_address";
  572.         }
  573.         else
  574.         {
  575.             $store $this->em->getRepository(Store::class)->findOneByBillingAddress($address);
  576.             if ($store !== null)
  577.             {
  578.                 $action "store_change_default_billing_address";
  579.             }
  580.         }
  581.         if ($action === null)
  582.         {
  583.             // The owner of the given address was not identified
  584.             return [];
  585.         }
  586.         // If we are here it means that we have an owner and an action
  587.         // Fill the common arguments
  588.         $args = array(
  589.             "action"                    =>    $action,
  590.             "object_id"                    =>    $store->getId(),
  591.             "object_bundle"                =>    "Client",
  592.             "object_entity"                =>    "Store",
  593.             "object_display"            =>    $store->display(),
  594.             "info"                        =>    $info,
  595.             "society_group"                =>    $store->getSocietyGroup(),
  596.             "special_author"            =>    $specialAuthor,
  597.         );
  598.         $values $this->computeAddressChanges($address$changes);
  599.         if ($values !== null)
  600.         {
  601.             $args["old_value"]    = $values["old"];
  602.             $args["new_value"]    = $values["new"];
  603.             $pendingLogArgs[] = $args;
  604.         }
  605.         return $pendingLogArgs;
  606.     }
  607.     public function logSupplier(Address $address$changes)
  608.     {
  609.         $pendingLogArgs = [];
  610.         //----------------------------------------------------------------------
  611.         // Fetch eventual info stored in the object
  612.         $loggingData $this->logTools->handleLoggingData($address);
  613.         $info $loggingData['info'];
  614.         $specialAuthor $loggingData['special_author'];
  615.         $ignore $loggingData['ignore'];
  616.         if ($ignore) return $pendingLogArgs;
  617.         //----------------------------------------------------------------------
  618.         // Look for Store
  619.         $action null;
  620.         $supplier $this->em->getRepository(Supplier::class)->findOneByAddress($address);
  621.         if ($supplier !== null)
  622.         {
  623.             $action "supplier_edit_address";
  624.         }
  625.         else
  626.         {
  627.             $supplier $this->em->getRepository(Supplier::class)->findOneByBillingAddress($address);
  628.             if ($supplier !== null)
  629.             {
  630.                 $action "supplier_edit_billing_address";
  631.             }
  632.         }
  633.         if ($action === null)
  634.         {
  635.             // The owner of the given address was not identified
  636.             return [];
  637.         }
  638.         // If we are here it means that we have an owner and an action
  639.         // Fill the common arguments
  640.         $args = array(
  641.             "action"                    =>    $action,
  642.             "object_id"                    =>    $supplier->getId(),
  643.             "object_bundle"                =>    "Platform",
  644.             "object_entity"                =>    "Supplier",
  645.             "object_display"            =>    $supplier->display(),
  646.             "info"                        =>    $info,
  647.             "society_group"                =>    $supplier->getSocietyGroup(),
  648.             "society"                    =>    $supplier->getSociety(),
  649.             "special_author"            =>    $specialAuthor,
  650.         );
  651.         $values $this->computeAddressChanges($address$changes);
  652.         if ($values !== null)
  653.         {
  654.             $args["old_value"]    = $values["old"];
  655.             $args["new_value"]    = $values["new"];
  656.             $pendingLogArgs[] = $args;
  657.         }
  658.         return $pendingLogArgs;
  659.     }
  660.     // TODO : When all Address logging is done here
  661.     // remove this method from AddressTools
  662.     public function computeAddressChanges(Address $address$changesSet)
  663.     {
  664.         if (count($changesSet) < 1)
  665.             return null;
  666.         $propertyAccessor PropertyAccess::createPropertyAccessor();
  667.         $old = array();
  668.         $new = array();
  669.         $changesToWatch = array("address""complement""postalCode""town""country");
  670.         foreach ($changesSet as $key => $change)
  671.         {
  672.             if (in_array($key$changesToWatch) && $change[1] != null)
  673.             {
  674.                 $old[$key] = $change[0];
  675.                 $new[$key] = $change[1];
  676.             }
  677.         }
  678.         $oldValue "";
  679.         $newValue "";
  680.         foreach ($changesToWatch as $key => $property)
  681.         {
  682.             if (array_key_exists($property$old))
  683.             {
  684.                 $oldValue .= $old[$property];
  685.                 $newValue .= $new[$property];
  686.             }
  687.             else
  688.             {
  689.                 $oldValue .= $propertyAccessor->getValue($address$property);
  690.                 $newValue .= $propertyAccessor->getValue($address$property);
  691.             }
  692.             if ($key == 2)
  693.             {
  694.                 $oldValue substr($oldValue0, -1);
  695.                 $newValue substr($newValue0, -1);
  696.                 $oldValue .= ", ";
  697.                 $newValue .= ", ";
  698.             }
  699.             else
  700.             {
  701.                 $oldValue .= " ";
  702.                 $newValue .= " ";
  703.             }
  704.         }
  705.         // Did Something change ?
  706.         if ($oldValue === $newValue)
  707.         {
  708.             return null;
  709.         }
  710.         return array(
  711.             "old"    =>    $oldValue,
  712.             "new"    =>    $newValue,
  713.         );
  714.     }
  715. }