src/Logging/Activity/Prospect/SurveyQuestionLog.php line 24

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Logging/Activity/Prospect/SurveyQuestionLog.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\Entity\Platform\Survey\SurveyQuestion;
  10. use App\Logging\DeletionContextLogger;
  11. use App\Logging\Tools;
  12. use App\Services\LogTools;
  13. class SurveyQuestionLog
  14. {
  15.     private array $pendingLogArgs = [];
  16.     public function __construct(ManagerRegistry $doctrineDeletionContextLogger $contextLoggerLogTools $logToolsTools $tools)
  17.     {
  18.         $this->em $doctrine->getManager();
  19.         $this->contextLogger $contextLogger;
  20.         $this->logTools $logTools;
  21.         $this->tools $tools;
  22.     }
  23.     public function logCreation(SurveyQuestion $surveyQuestion)
  24.     {
  25.         $pendingLogArgs = [];
  26.         return $pendingLogArgs;
  27.     }
  28.     public function logChanges(SurveyQuestion $surveyQuestion$changes)
  29.     {
  30.         // Mandatory conditions
  31.         $survey $surveyQuestion->getSurvey();
  32.         if ($survey === null) return [];
  33.         $prospect $survey->getProspect();
  34.         if ($prospect === null) return [];
  35.         if ($prospect->getIndividual() === null) return [];
  36.         $pendingLogArgs = [];
  37.         //----------------------------------------------------------------------
  38.         // Fetch eventual info skeletond in the object
  39.         $loggingData $this->logTools->handleLoggingData($surveyQuestion);
  40.         $info $loggingData['info'];
  41.         $specialAuthor $loggingData['special_author'];
  42.         $ignore $loggingData['ignore'];
  43.         if ($ignore) return $pendingLogArgs;
  44.         //----------------------------------------------------------------------
  45.         // Init base log args
  46.         // This does not contain action
  47.         $args $this->initArgs($survey$prospect$loggingData);
  48.         //----------------------------------------------------------------------
  49.         $action "prospect_edit_survey_question";
  50.         $basicChanges = array(
  51.             "answer",
  52.         );
  53.         // See what changed and log (members first)
  54.         foreach ($changes as $key => $change)
  55.         {
  56.             $name $this->logTools->camelToSnakeCase($key);
  57.             $args["action"]    = $action."_".$name;
  58.             $before $change[0];
  59.             $after $change[1];
  60.             if (in_array($key$basicChanges))
  61.             {
  62.                 $pendingLogArgs[] = $this->tools->handleBasicChanges($args$before$after);
  63.                 continue;
  64.             }
  65.         }
  66.         return $pendingLogArgs;
  67.     }
  68.     public function logRemoval(SurveyQuestion $surveyQuestion)
  69.     {
  70.         $pendingLogArgs = [];
  71.         return $pendingLogArgs;
  72.     }
  73.     private function initArgs(Survey $surveyClient $prospect$loggingData)
  74.     {
  75.         $objectEntity "Client.Prospect";
  76.         $receiver $prospect;
  77.         $individual $prospect->getIndividual();
  78.         $society $individual->getSociety();
  79.         $societyGroup $individual->getSocietyGroup();
  80.         $args = array(
  81.             "object_id"                    =>    $prospect->getId(),
  82.             "object_bundle"                =>    "Platform",
  83.             "object_entity"                =>    $objectEntity,
  84.             "object_display"            =>    $prospect->display(),
  85.             "object_client_id"            =>    $receiver !== null $receiver->getId() : null,
  86.             "object_client_display"        =>    $receiver !== null $receiver->getName() : null,
  87.             "society_group"                =>    $societyGroup,
  88.             "society"                    =>    $society,
  89.             "info"                        =>    $loggingData['info'],
  90.             "special_author"            =>    $loggingData['special_author'],
  91.         );
  92.         return $args;
  93.     }
  94. }