Last active
May 31, 2017 11:58
-
-
Save pikl-cz/5572b2e2b1cbd87fa4fe23ac0d3574cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$qb= $this->em->getRepository(DCE::class)->createQueryBuilder(); | |
$qb->select('dce') | |
->addSelect("COUNT(dc) amount") | |
->from($this->entityPath, 'dce') | |
->join('dce.discount_coupons', 'dc'); | |
if (!empty($filter)) { | |
if (isset($filter['title']) && !empty($filter['title'])) { | |
$qb->andWhere('dce.title LIKE :title') | |
->setParameter("title", '%' . addcslashes($filter['title'], '%_') . '%'); | |
} | |
if (isset($filter['amount']) && !empty($filter['amount'])) { | |
$qb->andWhere('amount ' . addcslashes($filter['amount_operator'], '%_') . ' :amount') | |
->setParameter("amount", (int) $filter['amount']); | |
} | |
if (isset($filter['is_valid'])) { | |
if ($filter['is_valid'] == 0) { | |
$qb->andWhere('dce.is_valid = 0'); | |
} elseif ($filter['is_valid'] == 1) { | |
$qb->andWhere('dce.is_valid = 1'); | |
} else { | |
$qb->andWhere('dce.is_valid IN (0,1)'); | |
} | |
} | |
if (isset($filter['date_created']) && !empty($filter['date_created']) && strtotime($filter['date_created']) !== false) { | |
$qb->andWhere('dce.date_created ' . addcslashes($filter['date_created_operator'], '%_') . ' :date_created') | |
->setParameter("date_created", DateTime::createFromFormat('d. m. Y', $filter['date_created'])->format('Y-m-d')); | |
} | |
} | |
if(isset($sort)) { | |
$qb->orderBy('dce.' . $sort, $by); | |
} | |
return $qb->getQuery(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment