<?php
namespace App\Repository;
use App\Entity\Offer;
class OfferRepository extends BaseRepository
{
public function getListAll($requestData)
{
$nameEntity = $this->getEntityName();
$queryBuilder = $this->createQueryBuilder($nameEntity);
$queryBuilder->andWhere($nameEntity . '.status = :status');
$queryBuilder->setParameter('status', Offer::STATUS_ACTIVE);
$queryBuilder->addOrderBy($nameEntity . '.createdDate', 'DESC');
if ($requestData) {
$this->setFilter($queryBuilder, $requestData);
}
$offers = $queryBuilder->getQuery()->getResult();
return $this->autoMapper->mapMultiple($offers, 'App\DTO\Offer\OfferOutput');
}
public function getBySlug($slug, $request)
{
$review = $request->get('review');
if ($review) {
$offer = $this->findOneBy([
'slug' => $slug
]);
} else {
$offer = $this->findOneBy([
'slug' => $slug,
'status' => Offer::STATUS_ACTIVE
]);
}
if (!$offer) {
return null;
}
return $this->autoMapper->map($offer, 'App\DTO\Offer\OfferOutput');
}
public function getById($id)
{
$offer = $this->findOneBy([
'id' => $id
]);
if (!$offer) return $offer;
return $this->autoMapper->map($offer, 'App\DTO\Offer\OfferOutput');
}
public function getListLasted($id = null)
{
$nameEntity = $this->getEntityName();
$queryBuilder = $this->createQueryBuilder($nameEntity);
if ($id) {
$queryBuilder->andWhere($nameEntity . '.id != :id');
$queryBuilder->setParameters(['id' => $id]);
}
$queryBuilder->andWhere($nameEntity . '.status = :status');
$queryBuilder->setParameter('status', Offer::STATUS_ACTIVE);
$queryBuilder->addOrderBy($nameEntity . '.id', 'DESC');
$queryBuilder->setMaxResults(6);
$jobs = $queryBuilder->getQuery()->getResult();
if (!$jobs) {
return $jobs;
}
return $this->autoMapper->mapMultiple($jobs, 'App\DTO\Offer\OfferOutputList');
}
public function getTotalJobActive()
{
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->executeQuery(
'select count(id) as total from offer where status = :status',
[
'status' => Offer::STATUS_ACTIVE
]
);
$result = $stmt->fetchOne();
return (int) $result;
}
}