src/FlexApp/Service/AliasByConsLoginProvider.php line 25

Open in your IDE?
  1. <?php
  2. namespace FlexApp\Service;
  3. use FlexApp\Repository\ConsultantRepository;
  4. use Psr\Cache\InvalidArgumentException;
  5. use WebBundle\Exception\PortalHelperException;
  6. class AliasByConsLoginProvider
  7. {
  8.     private ConsSchedule $consSchedule;
  9.     /** @required */
  10.     public ConsultantRepository $consultantRepository;
  11.     public function __construct(ConsSchedule $consSchedule)
  12.     {
  13.         $this->consSchedule $consSchedule;
  14.     }
  15.     public function getAlias(string $consLogin) {
  16.         try {
  17.             $schedule $this->consSchedule->getSchedule() ?? [];
  18.             $consultData $schedule['result']['consultData'] ?? [];
  19.             foreach ($consultData as $val) {
  20.                 $val['pseudonym'] ??= 'T.E. Specialist';
  21.                 if ($consLogin === $val['login']) {
  22.                     return $val['pseudonym'];
  23.                 }
  24.             }
  25.             /** @var \FlexApp\Entity\ConsultantEntity $consEntity */
  26.             $consEntity $this->consultantRepository->findOneBy(['portalLogin' => $consLogin]);
  27.             if (!$consEntity) {
  28.                 return 'Support';
  29.             }
  30.             if (!$consEntity->getNameForChat()) {
  31.                 return 'T.E. Support';
  32.             }
  33.             return $consEntity->getNameForChat();
  34.         } catch (InvalidArgumentException $e) {
  35.             return 'TE Manager';
  36.         } catch (PortalHelperException $e) {
  37.             return 'TE Specialist';
  38.         }
  39.     }
  40. }