Advertisement
andreybotanic

Untitled

Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. public function findAllWithPhoto()
  2.     {
  3.         return $qb = $this->createQueryBuilder('p')
  4.             ->join('App\Entity\Category', 'c', 'WITH', 'p.category = c.id')
  5.             ->select([
  6.                 'p.id',
  7.                 'p.name',
  8.                 'p.price',
  9.                 'CASE WHEN p.preview IS NULL THEN \'no-image-available.png\' ELSE concat(c.photoPrefix, \'/\', p.preview) END AS preview'
  10.             ])->getQuery()->getResult();
  11.     }
  12.  
  13.  
  14.  
  15. public function findPhotoByProduct(Product $product)
  16.     {
  17.         return $qb = $this->createQueryBuilder('p')
  18.             ->join('App\Entity\Product', 'prod', 'WITH', 'p.product = prod.id')
  19.             ->join('App\Entity\Category', 'c', 'WITH', 'prod.category = c.id')
  20.             ->select([
  21.                 'p.id',
  22.                 'CONCAT(c.photoPrefix, \'/\', p.fileNameSmall) AS fileNameSmall',
  23.                 'CONCAT(c.photoPrefix, \'/\', p.fileNameBig) AS fileNameBig'
  24.             ])
  25.             ->andWhere('p.product = :id')
  26.             ->setParameter('id', $product->getId())
  27.             ->getQuery()->getResult();
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement