src/Service/Common/Owner/OwnerProvider.php line 38

  1. <?php
  2. namespace App\Service\Common\Owner;
  3. use App\Entity\UUID\Owners;
  4. use App\Model\Common\OwnerModel;
  5. use App\Model\Common\OwnerInterface;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Doctrine\ORM\NoResultException;
  8. use Doctrine\ORM\QueryBuilder;
  9. use Symfony\Component\PropertyAccess\PropertyAccessor;
  10. class OwnerProvider
  11. {
  12.     /**
  13.      * @var PropertyAccessor
  14.      */
  15.     private $pa;
  16.     /**
  17.      * @var \App\Service\Common\Owner\OwnerFactory
  18.      */
  19.     private $config;
  20.     /**
  21.      * @var EntityManagerInterface
  22.      */
  23.     private $em;
  24.     public function __construct(\App\Service\Common\Owner\OwnerFactory $ownerNewsConfigEntityManagerInterface $em)
  25.     {
  26.         $this->pa = new PropertyAccessor();
  27.         $this->config $ownerNewsConfig;
  28.         $this->em $em;
  29.     }
  30.     public function findOwner(OwnerInterface $owner): ?OwnerModel
  31.     {
  32.         if ($owner->getUuid()) {
  33.             return $this->findByUuid($owner->getUuid());
  34.         }
  35.         return null;
  36.     }
  37.     public function findByUuid(string $uuid): ?OwnerModel
  38.     {
  39.         try {
  40.             $type $this->em->getRepository(Owners::class)->findType($uuid);
  41. //                dump($type);
  42.             $cfg $this->config->get($type);
  43. //                dump($cfg);
  44.             $ent $this->em->getRepository($cfg->getClass())->{$cfg->getRepositorySingle()}($uuid);
  45.             if ($ent) {
  46.                 return new OwnerModel($ent$cfg->getRender());
  47.             }
  48.         } catch (NoResultException $ex) {
  49.             return null;
  50.         }
  51.         return null;
  52.     }
  53.     public function getTitles()
  54.     {
  55. //        return array_column($this->config->all(), 'title','name');
  56.         $res = [];
  57.         foreach ($this->config->all() as $key => $value) {
  58.             $res[$key] = $value['title'];
  59.         }
  60.         //dump($res);
  61.         return $res;
  62.     }
  63.     public function findAdminQb($type): QueryBuilder
  64.     {
  65.         $cfg $this->config->get($type);
  66.         return $this->em->getRepository($cfg->getClass())->{$cfg->getAdminListRepositoryMethod()}();
  67.     }
  68. }