src/Logging/Activity/Prospect/SurveyLog.php line 19

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/Prospect/SurveyLog.php
  4. //----------------------------------------------------------------------
  5. namespace App\Logging\Activity\Prospect;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use App\Entity\Client\Client;
  8. use App\Entity\Platform\Survey\Survey;
  9. use App\Logging\DeletionContextLogger;
  10. use App\Logging\Tools;
  11. use App\Services\LogTools;
  12. class SurveyLog
  13. {
  14.     private array $pendingLogArgs = [];
  15.     public function __construct(ManagerRegistry $doctrine, DeletionContextLogger $contextLogger, LogTools $logTools, Tools $tools)
  16.     {
  17.         $this->em = $doctrine->getManager();
  18.         $this->contextLogger = $contextLogger;
  19.         $this->logTools = $logTools;
  20.         $this->tools = $tools;
  21.     }
  22.     public function logCreation(Survey $survey)
  23.     {
  24.         // Mandatory conditions
  25.         $prospect = $survey->getProspect();
  26.         if ($prospect === null) return [];
  27.         if ($prospect->getIndividual() === null) return [];
  28.         $pendingLogArgs = [];
  29.         //----------------------------------------------------------------------
  30.         // Fetch eventual info stored in the object
  31.         $loggingData = $this->logTools->handleLoggingData($survey);
  32.         $info = $loggingData['info'];
  33.         $specialAuthor = $loggingData['special_author'];
  34.         $ignore = $loggingData['ignore'];
  35.         if ($ignore) return $pendingLogArgs;
  36.         //----------------------------------------------------------------------
  37.         // Init base log args
  38.         // This does not contain action
  39.         $args = $this->initArgs($survey, $prospect, $loggingData);
  40.         //----------------------------------------------------------------------
  41.         $action = "prospect_add_survey";
  42.         $args["action"] = $action;
  43.         $args["new_value"] = $survey->display();
  44.         $pendingLogArgs[] = $args;
  45.         return $pendingLogArgs;
  46.     }
  47.     public function logChanges(Survey $survey, $changes)
  48.     {
  49.         // Mandatory conditions
  50.         $prospect = $survey->getProspect();
  51.         if ($prospect === null) return [];
  52.         if ($prospect->getIndividual() === null) return [];
  53.         $pendingLogArgs = [];
  54.         //----------------------------------------------------------------------
  55.         // Fetch eventual info skeletond in the object
  56.         $loggingData = $this->logTools->handleLoggingData($survey);
  57.         $info = $loggingData['info'];
  58.         $specialAuthor = $loggingData['special_author'];
  59.         $ignore = $loggingData['ignore'];
  60.         if ($ignore) return $pendingLogArgs;
  61.         //----------------------------------------------------------------------
  62.         // Init base log args
  63.         // This does not contain action
  64.         $args = $this->initArgs($survey, $prospect, $loggingData);
  65.         //----------------------------------------------------------------------
  66.         $action = "prospect_edit_survey";
  67.         $args["action"] = $action;
  68.         $pendingLogArgs[] = $args;
  69.         return $pendingLogArgs;
  70.     }
  71.     public function logRemoval(Survey $survey)
  72.     {
  73.         // Mandatory conditions
  74.         $cachedData = $this->contextLogger->getContext($survey);
  75.         if ($cachedData === null || empty($cachedData)) return [];
  76.         if (array_key_exists('prospect', $cachedData) && $cachedData['prospect'] !== null)
  77.         {
  78.             $prospect = $cachedData['prospect'];
  79.             if ($prospect->getIndividual() === null) return [];
  80.         }
  81.         $pendingLogArgs = [];
  82.         //----------------------------------------------------------------------
  83.         // Fetch eventual info skeletond in the object
  84.         $loggingData = $this->logTools->handleLoggingData($survey);
  85.         $info = $loggingData['info'];
  86.         $specialAuthor = $loggingData['special_author'];
  87.         $ignore = $loggingData['ignore'];
  88.         if ($ignore) return $pendingLogArgs;
  89.         //----------------------------------------------------------------------
  90.         // Init base log args
  91.         // This does not contain action
  92.         $args = $this->initArgs($survey, $prospect, $loggingData);
  93.         //----------------------------------------------------------------------
  94.         $args["action"] = "prospect_delete_survey";
  95.         $args["old_value"] = $survey->displayForLogDelete();
  96.         $pendingLogArgs[] = $args;
  97.         return $pendingLogArgs;
  98.     }
  99.     private function initArgs(Survey $survey, Client $prospect, $loggingData)
  100.     {
  101.         $objectEntity = "Client.Prospect";
  102.         $receiver = $prospect;
  103.         $individual = $prospect->getIndividual();
  104.         $society = $individual->getSociety();
  105.         $societyGroup = $individual->getSocietyGroup();
  106.         $args = array(
  107.             "object_id"                    =>    $prospect->getId(),
  108.             "object_bundle"                =>    "Platform",
  109.             "object_entity"                =>    $objectEntity,
  110.             "object_display"            =>    $prospect->display(),
  111.             "object_client_id"            =>    $receiver !== null ? $receiver->getId() : null,
  112.             "object_client_display"        =>    $receiver !== null ? $receiver->getName() : null,
  113.             "society_group"                =>    $societyGroup,
  114.             "society"                    =>    $society,
  115.             "info"                        =>    $loggingData['info'],
  116.             "special_author"            =>    $loggingData['special_author'],
  117.         );
  118.         return $args;
  119.     }
  120. }