src/Repository/PageBlockRepository.php line 62

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Repository;
  4. use App\Entity\PageBlock;
  5. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. /**
  8.  * @method PageBlock|null find($id, $lockMode = null, $lockVersion = null)
  9.  * @method PageBlock|null findOneBy(array $criteria, array $orderBy = null)
  10.  * @method PageBlock[]    findAll()
  11.  * @method PageBlock[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  12.  */
  13. class PageBlockRepository extends ServiceEntityRepository
  14. {
  15.     public function __construct(ManagerRegistry $registry)
  16.     {
  17.         parent::__construct($registryPageBlock::class);
  18.     }
  19.     public function findByPage($value)
  20.     {
  21.         return $this->createQueryBuilder('bp')
  22.             ->addSelect('bl')// block
  23.             ->addSelect('p')// page
  24.             ->addSelect('b_i')// blockitem
  25.             ->addSelect('i')// item
  26.             ->addSelect('bc')// block children
  27.             ->addSelect('chi')// children
  28.             ->leftJoin('bp.block''bl')
  29.             ->leftJoin('bp.page''p')
  30.             ->leftJoin('bl.blockItem''b_i')
  31.             ->leftJoin('b_i.item''i')
  32.             ->leftJoin('bp.pageBlock''bc')
  33.             ->leftJoin('bc.children''chi')
  34.             ->andWhere('bp.page = :val')
  35.             ->setParameter('val'$value)
  36.             ->orderBy('bp.itemOrder''ASC')
  37.             ->getQuery()
  38.             ->getResult()
  39.         ;
  40.     }
  41.     public function findFromBlockPage()
  42.     {
  43.         return $this->createQueryBuilder('bp')
  44.             ->addSelect('bl')// block
  45.             ->addSelect('p')// page
  46.             ->leftJoin('bp.block''bl')
  47.             ->leftJoin('bp.page''p')
  48.             ->orderBy('bp.itemOrder''ASC')
  49.             ->getQuery()
  50.             ->getResult()
  51.         ;
  52.     }
  53.     // for front
  54.     public function getbyNameByBlockType(string $slugstring $locale)
  55.     {
  56.         return $this->createQueryBuilder('bp')
  57.             ->addSelect('p')// page
  58.             ->addSelect('bl')// block
  59.             ->leftJoin('bp.page''p')
  60.             ->leftJoin('bp.block''bl')
  61.             ->where('p.slug = :slug')
  62.             ->setParameter('slug'$slug)
  63.             ->andWhere('bp.block IS NOT NULL')
  64.             ->andWhere('p.type = :type')
  65.             ->setParameter('type'$slug)
  66.             ->andWhere('bp.jsonData LIKE :locale')
  67.             ->setParameter('locale''%"lang_block":"'.$locale.'"%')
  68.             ->orderBy('bp.itemOrder''ASC')
  69.             ->getQuery()
  70.             ->getResult();
  71.     }
  72.     public function getByPageNameBy($nameint $locale null)
  73.     {
  74.         $qb $this->createQueryBuilder('bp')
  75.             ->addSelect('p')// page
  76.             ->addSelect('bl')// block
  77.             ->addSelect('c')// content
  78.             ->leftJoin('bp.page''p')
  79.             ->leftJoin('bp.block''bl')
  80.             ->leftJoin('bp.contents''c')
  81.             ->where('p.name = :name')
  82.             ->setParameter('name'$name);
  83.         if ($locale) {
  84.             $qb
  85.                 ->andWhere('c.language = :lang')
  86.                 ->setParameter('lang'$locale);
  87.         }
  88.         return
  89.             $qb
  90.                 ->getQuery()
  91.                 ->getResult()
  92.         ;
  93.     }
  94. }