createQueryBuilder('l') ->select('l.reference') ->where('l.reference LIKE :pattern') ->setParameter(':pattern', '%' . $pattern . '%') ->orderBy('l.reference', 'DESC') ->setMaxResults(1); return $qb->getQuery()->getOneOrNullResult(); } /** * @param $status * @return array */ public function findAllByStatusForRead($status) { $qb = $this->createQueryBuilder('l') ->where('l.status = :status') ->setParameter(':status', $status) ->orderBy('l.status') ->addOrderBy('l.reference', 'DESC'); return $qb->getQuery()->getResult(); } /** * @param $id * @return mixed * @throws \Doctrine\ORM\NonUniqueResultException */ public function findOneForAPIRead($id) { $qb = $this->createQueryBuilder('l') ->where('l.id = :id') ->setParameter(':id', $id); return $qb->getQuery()->getOneOrNullResult(); } /** * @param $id * @return mixed * @throws \Doctrine\ORM\NonUniqueResultException */ public function findOneForAPIUpdate($id) { $qb = $this->createQueryBuilder('l') ->where('l.status = :draft') ->orWhere('l.status = :current') ->andWhere('l.id = :id') ->setParameters(array( ':id' => $id, ':draft' => 'draft', ':current' => 'current' )); return $qb->getQuery()->getOneOrNullResult(); } /** * @param $id * @return mixed * @throws \Doctrine\ORM\NonUniqueResultException */ public function findOneForAPIDelete($id) { $qb = $this->createQueryBuilder('l') ->where('l.id = :id') ->andWhere('l.status = :draft') ->setParameters(array( ':id' => $id, ':draft' => 'draft' )); return $qb->getQuery()->getOneOrNullResult(); } }