src/Repository/OfferRepository.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Offer;
  4. class OfferRepository extends BaseRepository
  5. {
  6.     public function getListAll($requestData)
  7.     {
  8.         $nameEntity $this->getEntityName();
  9.         $queryBuilder $this->createQueryBuilder($nameEntity);
  10.         $queryBuilder->andWhere($nameEntity '.status = :status');
  11.         $queryBuilder->setParameter('status'Offer::STATUS_ACTIVE);
  12.         $queryBuilder->addOrderBy($nameEntity '.createdDate''DESC');
  13.         if ($requestData) {
  14.             $this->setFilter($queryBuilder$requestData);
  15.         }
  16.         $offers $queryBuilder->getQuery()->getResult();
  17.         return $this->autoMapper->mapMultiple($offers'App\DTO\Offer\OfferOutput');
  18.     }
  19.     public function getBySlug($slug$request)
  20.     {
  21.         $review $request->get('review');
  22.         if ($review) {
  23.             $offer $this->findOneBy([
  24.                 'slug' => $slug
  25.             ]);
  26.         } else {
  27.             $offer $this->findOneBy([
  28.                 'slug' => $slug,
  29.                 'status' => Offer::STATUS_ACTIVE
  30.             ]);
  31.         }
  32.         if (!$offer) {
  33.             return null;
  34.         }
  35.         return $this->autoMapper->map($offer'App\DTO\Offer\OfferOutput');
  36.     }
  37.     public function getById($id)
  38.     {
  39.         $offer $this->findOneBy([
  40.             'id' => $id
  41.         ]);
  42.         if (!$offer) return $offer;
  43.         return $this->autoMapper->map($offer'App\DTO\Offer\OfferOutput');
  44.     }
  45.     public function getListLasted($id null)
  46.     {
  47.         $nameEntity $this->getEntityName();
  48.         $queryBuilder $this->createQueryBuilder($nameEntity);
  49.         if ($id) {
  50.             $queryBuilder->andWhere($nameEntity '.id != :id');
  51.             $queryBuilder->setParameters(['id' => $id]);
  52.         }
  53.         $queryBuilder->andWhere($nameEntity '.status = :status');
  54.         $queryBuilder->setParameter('status'Offer::STATUS_ACTIVE);
  55.         $queryBuilder->addOrderBy($nameEntity '.id''DESC');
  56.         $queryBuilder->setMaxResults(6);
  57.         $jobs $queryBuilder->getQuery()->getResult();
  58.         if (!$jobs) {
  59.             return $jobs;
  60.         }
  61.         return $this->autoMapper->mapMultiple($jobs'App\DTO\Offer\OfferOutputList');
  62.     }
  63.     public function getTotalJobActive()
  64.     {
  65.         $conn $this->getEntityManager()->getConnection();
  66.         $stmt $conn->executeQuery(
  67.             'select count(id) as total from offer where status = :status',
  68.             [
  69.                 'status' => Offer::STATUS_ACTIVE
  70.             ]
  71.         );
  72.         $result $stmt->fetchOne();
  73.         return (int) $result;
  74.     }
  75. }