src/Services/AccessClient/AccessClientTools.php line 48

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Services/AccessClient/AccessClientTools.php
  4. //----------------------------------------------------------------------
  5. namespace App\Services\AccessClient;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  9. use App\Entity\Access;
  10. use App\Entity\AccessClient\AccessClientAddress;
  11. use App\Entity\AccessClient\AccessClient;
  12. use App\Entity\AccessClient\AccessClientRecord;
  13. use App\Entity\Client\Client;
  14. use App\Entity\Client\Individual;
  15. use App\Entity\Client\Title;
  16. use App\Entity\Common\Attachment;
  17. use App\Entity\Ding\Notification;
  18. use App\Entity\Ding\NotificationType;
  19. use App\Entity\Mission\Mission;
  20. use App\Entity\Planning\Task;
  21. use App\Entity\Platform\Devis\Devis;
  22. use App\Entity\Platform\Invoice\Invoice;
  23. use App\Entity\Platform\Note;
  24. use App\Entity\Platform\Phone;
  25. use App\Entity\Platform\PhoneLabel;
  26. use App\Entity\Platform\Society;
  27. use App\Entity\ProjectManager\ProjectNotebook;
  28. use App\Entity\SocietyGroup;
  29. use App\Entity\Webapp\Document;
  30. use App\Services\Config\OptionConfigTools;
  31. use App\Services\LogTools;
  32. use App\Services\Security\PasswordTools;
  33. class AccessClientTools
  34. {
  35.     public function __construct(ManagerRegistry $doctrineLogTools $logToolsTranslatorInterface $translator,
  36.         UserPasswordHasherInterface $passwordHasherPasswordTools $passwordTools,
  37.         OptionConfigTools $optionConfigTools)
  38.     {
  39.         $this->em $doctrine->getManager();
  40.         $this->logTools $logTools;
  41.         $this->translator $translator;
  42.         $this->optionConfigTools $optionConfigTools;
  43.         $this->passwordHasher $passwordHasher;
  44.         $this->passwordTools $passwordTools;
  45.     }
  46.     /**
  47.      * Returns TRUE if an AccessClientRecord exists for
  48.      * the given Client AND the Client's SocietyGroup
  49.      * and the corresponding AccessClient is active
  50.      *
  51.      * If an AccessClientRecord exists for another Client
  52.      * having the same email, this method returns FALSE
  53.      */
  54.     public function accessClientIsActiveForClient(Client $client)
  55.     {
  56.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  57.         if ($accessClientRecord === null)
  58.         {
  59.             return false;
  60.         }
  61.         $accessClient $accessClientRecord->getAccessClient();
  62.         if ($accessClient === null)
  63.         {
  64.             return false;
  65.         }
  66.         if ($accessClient->isActive())
  67.         {
  68.             return true;
  69.         }
  70.         return false;
  71.     }
  72.     /**
  73.      * Returns TRUE if an AccessClientRecord exists for
  74.      * the given Client AND the Client's SocietyGroup
  75.      *
  76.      * The corresponding AccessClient can be active or not,
  77.      * the method will still return true.
  78.      *
  79.      * If an AccessClientRecord exists for another Client
  80.      * having the same email, this method returns FALSE
  81.      */
  82.     public function clientHasAccessClient(Client $client)
  83.     {
  84.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  85.         if ($accessClientRecord !== null)
  86.         {
  87.             if ($accessClientRecord->getAccessClient() !== null)
  88.             {
  89.                 return true;
  90.             }
  91.         }
  92.         return false;
  93.     }
  94.     /**
  95.      * Returns TRUE if an AccessClientRecord exists for
  96.      * the given Mission's Receiver (Client) AND the Receiver's SocietyGroup
  97.      *
  98.      * The corresponding AccessClient can be active or not,
  99.      * the method will still return true.
  100.      *
  101.      * If an AccessClientRecord exists for another Receiver
  102.      * having the same email, this method returns FALSE
  103.      */
  104.     public function missionHasAccessClient(Mission $mission)
  105.     {
  106.         $receiver $mission->getReceiver();
  107.         if ($receiver === null)
  108.         {
  109.             return false;
  110.         }
  111.         return $this->clientHasAccessClient($receiver);
  112.     }
  113.     /**
  114.      * Returns the corresponding AccessClientRecord and AccessClient
  115.      * for the given Client
  116.      *
  117.      * This method will ALWAYS return an array
  118.      * having two keys :
  119.      *        accessClient
  120.      *        accessClientRecord
  121.      *
  122.      * If no AccessClientRecord has been found,
  123.      * both array entries are null (but keys still exist)
  124.      */
  125.     public function getDataForClient(Client $client)
  126.     {
  127.         // This is specific to a certain Client for a certain SocietyGroup
  128.         // This can be null,
  129.         // but that does not mean that there is not some other AccessClientRecord for the same email address
  130.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  131.         if ($accessClientRecord !== null)
  132.         {
  133.             $accessClient $accessClientRecord->getAccessClient();
  134.             // No need to go any further
  135.             return array(
  136.                 'accessClient'            =>    $accessClient,
  137.                 'accessClientRecord'    =>    $accessClientRecord,
  138.             );
  139.         }
  140.         // No record found for this particular client
  141.         // ... so look for an AccessClient with this email
  142.         if (!empty($client->getEmail()))
  143.         {
  144.             $accessClient $this->em->getRepository(AccessClient::class)->findOneByEmail($client->getEmail());
  145.             if ($accessClient !== null)
  146.             {
  147.                 // No need to go any further
  148.                 return array(
  149.                     'accessClient'            =>    $accessClient,
  150.                     'accessClientRecord'    =>    null,
  151.                 );
  152.             }
  153.         }
  154.         // All hope is lost
  155.         return array(
  156.             'accessClient'            =>    null,
  157.             'accessClientRecord'    =>    null,
  158.         );
  159.     }
  160.     /**
  161.      * Returns the corresponding AccessClientRecord and AccessClient for the given Client
  162.      *
  163.      * Find only from record, find by email can cause issue during merge process
  164.      *
  165.      * Plan.io Task #4392
  166.      */
  167.     public function getDataForMergeIndividual(Client $client)
  168.     {
  169.         $output = array(
  170.             'accessClient'            =>    null,
  171.             'accessClientRecord'    =>    null,
  172.         );
  173.         // This is specific to a certain Client for a certain SocietyGroup
  174.         // This can be null,
  175.         // but that does not mean that there is not some other AccessClientRecord for the same email address
  176.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  177.         if ($accessClientRecord === null)
  178.         {
  179.             return $output;
  180.         }
  181.         $accessClient $accessClientRecord->getAccessClient();
  182.         $output['accessClient'] = $accessClient;
  183.         $output['accessClientRecord'] = $accessClientRecord;
  184.         return $output;
  185.     }
  186.     /**
  187.      * Returns the corresponding clients and individuals
  188.      * for the given AccessClient
  189.      *
  190.      * If data is found, the method will return an array having two keys :
  191.      *        clients
  192.      *        individuals
  193.      *
  194.      * Returns NULL in case of error,
  195.      * which should never occur, since an AccessClient should always have
  196.      * at least one AccessClientRecord corresponding to a Client
  197.      */
  198.     public function getDataForAccessClient(AccessClient $accessClient)
  199.     {
  200.         if ($accessClient->getAccessClientRecords()->count() < 1)
  201.         {
  202.             // This should not happen
  203.             $this->logTools->errorlog("No AccessClientRecord found for AccessClient ".$accessClient->displayForLog());
  204.             return null;
  205.         }
  206.         $clients = array();
  207.         $individuals = array();
  208.         foreach ($accessClient->getAccessClientRecords() as $record)
  209.         {
  210.             $societyGroup $record->getSocietyGroup();
  211.             if ($societyGroup === null)
  212.             {
  213.                 // This should not happen
  214.                 $this->logTools->errorlog("SocietyGroup is null for AccessClientRecord ".$record->displayForLog());
  215.                 return null;
  216.             }
  217.             $client $record->getClient();
  218.             if ($client === null)
  219.             {
  220.                 // This should not happen
  221.                 $this->logTools->errorlog("Client is null for AccessClientRecord ".$record->displayForLog());
  222.                 return null;
  223.             }
  224.             // Only Individuals for now
  225.             $individual $client->getIndividual();
  226.             if ($individual === null)
  227.             {
  228.                 // This should not happen
  229.                 $this->logTools->errorlog("Individual is null for Client ".$client->displayForLog());
  230.                 return null;
  231.             }
  232.             $clients[] = $client;
  233.             $individuals[] = $individual;
  234.         }
  235.         return array(
  236.             'clients'            =>    $clients,
  237.             'individuals'        =>    $individuals,
  238.         );
  239.     }
  240.     /**
  241.      * Returns all the missions having as Receivers
  242.      * the Clients associated with the given AccessClient
  243.      */
  244.     public function getMissionsForAccessClient(AccessClient $accessClient)
  245.     {
  246.         $missions = array();
  247.         foreach ($accessClient->getAccessClientRecords() as $record)
  248.         {
  249.             $client $record->getClient();
  250.             if ($client === null) continue;
  251.             $clientMissions $this->em->getRepository(Mission::class)->findByReceiver($client);
  252.             if (!empty($clientMissions))
  253.             {
  254.                 $missions array_merge($missions$clientMissions);
  255.             }
  256.         }
  257.         return $missions;
  258.     }
  259.     public function areLinked(Client $clientAccessClient $accessClient)
  260.     {
  261.         foreach ($accessClient->getAccessClientRecords() as $record)
  262.         {
  263.             if ($client->equals($record->getClient()))
  264.             {
  265.                 return true;
  266.             }
  267.         }
  268.         return false;
  269.     }
  270.     // We need to be able to decide if a user belonging to a given SocietyGroup
  271.     // can make an object visble to the Client (via the Client Platform) or not.
  272.     //         => User trying to share and Author of object belongs to the same SocietyGroup
  273.     //        => SocietyGroup = User.SocietyGroup
  274.     // Make visble condition : societyGroup == object.author.societyGroup
  275.     public function canBeMadeVisible($objectSocietyGroup $societyGroup)
  276.     {
  277.         if (!($object instanceof Attachment) &&
  278.             !($object instanceof Devis) &&
  279.             !($object instanceof Document) &&
  280.             !($object instanceof Invoice) &&
  281.             !($object instanceof Task) &&
  282.             !($object instanceof ProjectNotebook))
  283.         {
  284.             return false;
  285.         }
  286.         // Get the SocietyGroup that has created this object
  287.         $author $object->getAuthor();
  288.         if ($author === null)
  289.         {
  290.             // All "error" cases should return true
  291.             // it means that nothing can be decided, so take a permissive approach
  292.             return true;
  293.         }
  294.         $objectSocietyGroupAuthor $author->getSocietyGroup();
  295.         if ($objectSocietyGroupAuthor === null)
  296.         {
  297.             // All "error" cases should return true
  298.             // it means that nothing can be decided, so take a permissive approach
  299.             return true;
  300.         }
  301.         if ($societyGroup->equals($objectSocietyGroupAuthor))
  302.         {
  303.             return true;
  304.         }
  305.         return false;
  306.     }
  307.     // Return values
  308.     //    accessClient        =>    Created or existing AccessClient
  309.     //    accessClientRecord    =>    The AccessClientRecord we created for the Client $client
  310.     //    newAccessClient        =>    We need to know if the AccessClient already existed (send activation email)
  311.     public function createAccessClientData(Client $client)
  312.     {
  313.         $badOutput = array(
  314.             'accessClient'            =>    null,
  315.             'accessClientRecord'    =>    null,
  316.             'newAccessClient'    =>    null,
  317.         );
  318.         // $badOutput['error'] = "access_client_record_already_exists";
  319.         // return $badOutput;
  320.         // Individuals only for now at least
  321.         if ($client->getIndividual() === null)
  322.         {
  323.             $badOutput['error'] = "client_is_not_an_individual";
  324.             return $badOutput;
  325.         }
  326.         // Just in case
  327.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  328.         if ($accessClientRecord !== null)
  329.         {
  330.             $badOutput['error'] = "access_client_record_already_exists";
  331.             return $badOutput;
  332.         }
  333.         // No email, no game
  334.         $email $client->getEmail();
  335.         if (empty($email))
  336.         {
  337.             $badOutput['error'] = "client_email_is_empty";
  338.             return $badOutput;
  339.         }
  340.         // All looks good
  341.         $societyGroup $client->getSocietyGroup();
  342.         $individual $client->getIndividual();
  343.         // Do we already have an AccessClient ?
  344.         $newAccessClient false;
  345.         $accessClient $this->em->getRepository(AccessClient::class)->findOneByEmail($email);
  346.         if ($accessClient === null)
  347.         {
  348.             // Hold that thought ;)
  349.             $newAccessClient true;
  350.             // Nope => Create it
  351.             $accessClient = new AccessClient();
  352.             $accessClient->setEmail($email);
  353.             $accessClient->addRole('ROLE_CLIENT');
  354.             $accessClient->setName($client->getName());
  355.             // Generate password
  356.             $pass $this->passwordTools->generatePassword(10);
  357.             // Encode the password
  358.             $encoded_password $this->passwordHasher->hashPassword($accessClient$pass);
  359.             $accessClient->setPassword($encoded_password);
  360.             // Activation code for access
  361.             $code $this->passwordTools->generateUniqueActivationCode();
  362.             $accessClient->setActivationCode($code);
  363.             // Create Addresses
  364.             $this->createAddresses($individual$accessClient);
  365.         }
  366.         // Now create the AccessClientRecord
  367.         $accessClientRecord = new AccessClientRecord();
  368.         $accessClientRecord->setClient($client);
  369.         $accessClientRecord->setSocietyGroup($societyGroup);
  370.         // $accessClientRecord->setAccessClient($accessClient);
  371.         // Respect Bidirectional Owing side in order to have logging
  372.         $accessClient->addAccessClientRecord($accessClientRecord);
  373.         $this->em->persist($accessClientRecord);
  374.         $this->em->persist($accessClient);
  375.         return array(
  376.             'accessClient'            =>    $accessClient,
  377.             'accessClientRecord'    =>    $accessClientRecord,
  378.             'newAccessClient'        =>    $newAccessClient,
  379.             'error'                    =>    null,
  380.         );
  381.     }
  382.     public function createAccessClientDataForTask(Task $task)
  383.     {
  384.         $badOutput = array(
  385.             'accessClient'            =>    null,
  386.             'accessClientRecord'    =>    null,
  387.             'newAccessClient'        =>    null,
  388.         );
  389.         if ($task->getMission() === null)
  390.         {
  391.             // Nothing to do here
  392.             // This is not logged and not displayed (for now)
  393.             $badOutput['error'] = "unknown_error";
  394.             return $badOutput;
  395.         }
  396.         $mission $task->getMission();
  397.         if ($mission->getReceiver() === null)
  398.         {
  399.             // Nothing to do here
  400.             // This is not logged and not displayed (for now)
  401.             $badOutput['error'] = "unknown_error";
  402.             return $badOutput;
  403.         }
  404.         $client $mission->getReceiver();
  405.         // Handle Sharing correctly
  406.         // Each SocietyGroup decides for its own Clients
  407.         //    => SocietyGroup is the one of the Client, not the Mission
  408.         $societyGroup $client->getSocietyGroup();
  409.         if ($societyGroup === null)
  410.         {
  411.             // Nothing to do here
  412.             // This is not logged and not displayed (for now)
  413.             $badOutput['error'] = "unknown_error";
  414.             return $badOutput;
  415.         }
  416.         // Auto Option Activated ?
  417.         if (!$this->optionConfigTools->isActive_ClientAccountAuto($societyGroup))
  418.         {
  419.             // Nope => Nothing to do here
  420.             // This is not logged and not displayed (for now)
  421.             $badOutput['error'] = "client_account_auto_option_not_active";
  422.             return $badOutput;
  423.         }
  424.         // Does the AccessClientRecord already exist ?
  425.         $accessClientRecord $this->em->getRepository(AccessClientRecord::class)->findOneByClient($client);
  426.         if ($accessClientRecord !== null)
  427.         {
  428.             // All is good => Bye ;)
  429.             return array(
  430.                 'accessClient'            =>    $accessClientRecord->getAccessClient(),
  431.                 'accessClientRecord'    =>    $accessClientRecord,
  432.                 'newAccessClient'        =>    false,
  433.                 'error'                    =>    null,
  434.             );
  435.         }
  436.         // Create the AccessClientRecord and, if needed, the AccessClient
  437.         // The method checks
  438.         //    - client is individual
  439.         //    - client has a non empty email address
  440.         //    - no AccessClientRecord already exsist
  441.         $data $this->createAccessClientData($client);
  442.         if ($data['error'] === null)
  443.         {
  444.             // All went well
  445.             return $data;
  446.         }
  447.         // If we are here it means that something went wrong
  448.         // Update output error
  449.         $badOutput['error'] = $data['error'];
  450.         // Output info in various forms to users
  451.         $error $this->translator->trans($data['error']);
  452.         $this->logTools->errorLog($error);
  453.         // Create a note
  454.         $body $this->translator->trans('note_body_create_access_client_from_task_failed');
  455.         $body .= " : ";
  456.         $body .= $error;
  457.         $author $this->em->getRepository(Access::class)->findOneByEmail(Access::REKAPP);
  458.         $note = new Note();
  459.         $note->setClient($client);
  460.         $note->setMission($mission);
  461.         $note->setAuthor($author);
  462.         $note->setVisibleToClient(false);
  463.         $note->setReadonly(false);
  464.         $note->setBody($body);
  465.         $this->em->persist($note);
  466.         // Create a notification for the Client's Manager
  467.         $title $this->translator->trans('note_title_create_access_client_from_task_failed');
  468.         $body $this->translator->trans('note_body_create_access_client_from_task_failed');
  469.         $body .= " : ";
  470.         $body .= $error;
  471.         $body .= " : ";
  472.         $body .= $client->getName();
  473.         $type $this->em->getRepository(NotificationType::class)
  474.             ->findOneBy(array(
  475.                 'dev'        =>    0,
  476.                 'warning'        =>    1,
  477.             ));
  478.         $notification = new Notification();
  479.         $notification->setType($type);
  480.         $notification->setSocietyGroup($societyGroup);
  481.         $notification->setSociety($client->getSociety());
  482.         $notification->setAccess($client->getManager());
  483.         $notification->setTitle($title);
  484.         $notification->setBody($body);
  485.         $this->em->persist($notification);
  486.         // TODO #4327
  487.         // Move this to the NotificationTools service
  488.         return $badOutput;
  489.     }
  490.     private function createAddresses(Individual $individualAccessClient $accessClient)
  491.     {
  492.         // Create its two main addresses
  493.         $interventionAddress $individual->getAddress();
  494.         $billingAddress $individual->getBillingAddress();
  495.         $addresses = [];
  496.         if ($interventionAddress !== null)
  497.         {
  498.             // Create the first one
  499.             $address = new AccessClientAddress();
  500.             $address->initFrom($interventionAddress);
  501.             $addresses[] = $address;
  502.             if ($billingAddress !== null)
  503.             {
  504.                 if ($billingAddress->differsInValue($interventionAddress))
  505.                 {
  506.                     // Create the second one
  507.                     $secondAddress = new AccessClientAddress();
  508.                     $secondAddress->initFrom($billingAddress);
  509.                     $addresses[] = $secondAddress;
  510.                 }
  511.             }
  512.         }
  513.         else
  514.         {
  515.             // Intervention Address is null
  516.             if ($billingAddress !== null)
  517.             {
  518.                 // Create the only one
  519.                 $address = new AccessClientAddress();
  520.                 $address->initFrom($billingAddress);
  521.                 $address->setAccessClient($accessClient);
  522.                 $addresses[] = $address;
  523.             }
  524.         }
  525.         if (count($addresses))
  526.         {
  527.             $addresses[0]->setIntervention(1);
  528.             if (count($addresses) == 2)
  529.             {
  530.                 $addresses[1]->setBilling(1);
  531.             }
  532.             else
  533.             {
  534.                 $addresses[0]->setBilling(1);
  535.             }
  536.         }
  537.         foreach ($addresses as $key => $address)
  538.         {
  539.             $address->setAccessClient($accessClient);
  540.             $this->em->persist($address);
  541.         }
  542.     }
  543.     // This is called when an Individual is modified on the Platform OR the ClientPlatform
  544.     // Individual $individual is the object holding the source data
  545.     public function syncIndividualData(Individual $individual)
  546.     {
  547.         // Get the corresponding Client
  548.         $client $individual->getClient();
  549.         if ($client === null)
  550.         {
  551.             return false;
  552.         }
  553.         // Does it have an AccessClient ?
  554.         $accessClientData $this->getDataForClient($client);
  555.         if ($accessClientData['accessClient'] === null)
  556.         {
  557.             // Nothing do do here
  558.             return true;
  559.         }
  560.         $accessClient $accessClientData['accessClient'];
  561.         $accessClientRecords $accessClient->getAccessClientRecords();
  562.         // Is this Client the only AccessClientRecord ?
  563.         if (count($accessClientRecords) == 1)
  564.         {
  565.             // Nothing do do here
  566.             return true;
  567.         }
  568.         // More than one AccessClientRecord => Do some update
  569.         // Get all related Individuals
  570.         $accessClientData $this->getDataForAccessClient($accessClient);
  571.         if ($accessClientData === null)
  572.         {
  573.             return false;
  574.         }
  575.         $individuals $accessClientData['individuals'];
  576.         if (empty($individuals))
  577.         {
  578.             return false;
  579.         }
  580.         // Check all fields that may have been changed by the AccessClient
  581.         $firstname $individual->getFirstname();
  582.         $lastname $individual->getLastname();
  583.         $company $individual->getCompany();
  584.         $phone $individual->getPhone();
  585.         $email $individual->getEmail();
  586.         $title $individual->getTitle();
  587.         $titleCode null;
  588.         // Title is tricky :)
  589.         // Title is Something that belongs to each SocietyGroup
  590.         // So we need to look for an equivalent
  591.         // Use codes
  592.         if ($title !== null)
  593.         {
  594.             $titleCode $title->getCode();
  595.         }
  596.         foreach ($individuals as $item)
  597.         {
  598.             if ($individual->equals($item))
  599.             {
  600.                 // Do not self update :)
  601.                 continue;
  602.             }
  603.             if ($item->getFirstname() != $firstname)    $item->setFirstname($firstname);
  604.             if ($item->getLastname() != $lastname)        $item->setLastname($lastname);
  605.             if ($item->getCompany() != $company)        $item->setCompany($company);
  606.             if ($item->getEmail() != $email)            $item->setEmail($email);
  607.             // Update phone field
  608.             // Also update the main phoneline of the client
  609.             if ($item->getPhone() != $phone)
  610.             {
  611.                 $item->setPhone($phone);
  612.                 $this->syncIndividualPhoneObject($item);
  613.             }
  614.             // Apply update on title if needed
  615.             if ($item->getTitle() === null || $titleCode === null || $item->getTitle()->getCode() != $titleCode)
  616.             {
  617.                 $newTitle null;
  618.                 if ($titleCode !== null)
  619.                 {
  620.                     $newTitle $this->em->getRepository(Title::class)->findOneBy(array(
  621.                         'societyGroup'        =>    $item->getSocietyGroup(),
  622.                         'code'                =>    $titleCode,
  623.                     ));
  624.                 }
  625.                 // If not found, get n/c one
  626.                 if ($newTitle === null)
  627.                 {
  628.                     $newTitle $this->em->getRepository(Title::class)->findOneBy(array(
  629.                         'societyGroup'        =>    $item->getSocietyGroup(),
  630.                         'code'                =>    Title::CODE_NC,
  631.                     ));
  632.                 }
  633.                 if ($newTitle !== null)
  634.                 {
  635.                     $item->setTitle($newTitle);
  636.                 }
  637.             }
  638.             // Client prePersist / preUpdate event is not called
  639.             // So trigger updateName manualy
  640.             if ($item->getClient() !== null)
  641.             {
  642.                 $item->getClient()->updateName();
  643.             }
  644.         }
  645.         return true;
  646.     }
  647.     public function syncIndividualPhoneObject(Individual $individual)
  648.     {
  649.         $phoneDefaultLabel $this->em->getRepository(PhoneLabel::class)->findOneBy(array(
  650.             'societyGroup'    => $individual->getSocietyGroup(),
  651.             'defaultValue'    =>    1,
  652.         ));
  653.         $phone $this->em->getRepository(Phone::class)->findOneBy(array(
  654.             'individual'    =>    $individual,
  655.             'label'            =>    $phoneDefaultLabel,
  656.         ));
  657.         if ($phone !== null)
  658.         {
  659.             $phone->setNumber($individual->getPhone());
  660.         }
  661.     }
  662.     /**
  663.      * Plan.io Task #4408
  664.      * @usedBy \App\Controller\Security\SecurityController\activation
  665.      */
  666.     public function activateCommercialConsentForAccessClient(AccessClient $accessClient)
  667.     {
  668.         $records $accessClient->getAccessClientRecords();
  669.         foreach($records as $rec)
  670.         {
  671.             $client $rec->getClient();
  672.             if ($client === null || $client->getIndividual() === null)
  673.             {
  674.                 continue;
  675.             }
  676.             $individual $client->getIndividual();
  677.             $individual->setCommercialConsent(true);
  678.             $individual->setCommercialConsentDeactivationDate(null);
  679.             $individual->setLoggingData([
  680.                 "info" => $this->translator->trans('activation_source'),
  681.             ]);
  682.         }
  683.     }
  684. }