createQueryBuilder() public method

Creates a new Query\Builder instance that is preconfigured for this document name.
public createQueryBuilder ( ) : Builder
return Doctrine\ODM\MongoDB\Query\Builder $qb
示例#1
0
 public function findVisible($owner)
 {
     if (!$owner instanceof UserInterface) {
         return array();
     }
     $qb = $this->repo->createQueryBuilder()->field('owner.$id')->equals(new \MongoId($owner->getId()))->field('visibility')->equals(CalendarInterface::VISIBILITY_PUBLIC);
     return $qb->getQuery()->execute();
 }
 /**
  * @param LifecycleEventArgs $args
  */
 public function postPersist(LifecycleEventArgs $args)
 {
     $document = $args->getDocument();
     if (!$document instanceof Event) {
         return;
     }
     $location = $document->getPlace()->getLocation();
     $subscribers = $this->subscriberRepository->createQueryBuilder()->field('location')->near((double) $location->getLongitude(), (double) $location->getLatitude())->maxDistance(5 / 111.12)->getQuery()->execute();
     foreach ($subscribers as $subscriber) {
         $body = $this->templating->render('ApiBundle:Email:subscriber.html.twig', ['event' => $document]);
         $message = \Swift_Message::newInstance()->setSubject('Ping - New event on you area !')->setFrom('*****@*****.**')->setTo($subscriber->getEmail())->setBody($body, 'text/html');
         $this->mailer->send($message);
     }
 }
 protected function init(Request $request)
 {
     $this->request = $request;
     $this->baseUrl = 'http://' . $this->request->getHost() . $this->request->getBaseUrl() . $this->request->getPathInfo();
     $this->manager = $this->get('doctrine_mongodb')->getManager();
     $this->repository = $this->manager->getRepository('AppBundle:UserEvent');
     $this->queryBuilder = $this->repository->createQueryBuilder();
     $this->dbCount = $this->queryBuilder->getQuery()->execute()->count();
 }
示例#4
0
 /**
  * {@inheritDoc}
  *
  * @param Request      $request The request object
  * @param SecurityUser $user    SecurityUser Object
  *
  * @return array
  */
 public function findAll(Request $request, SecurityUser $user = null)
 {
     $pageNumber = $request->query->get('page', 1);
     $numberPerPage = (int) $request->query->get('perPage', $this->getDefaultLimit());
     $startAt = ($pageNumber - 1) * $numberPerPage;
     /** @var \Doctrine\ODM\MongoDB\Query\Builder $queryBuilder */
     $queryBuilder = $this->repository->createQueryBuilder();
     if ($this->filterByAuthUser && $user && $user->hasRole(SecurityUser::ROLE_USER)) {
         $queryBuilder->field($this->filterByAuthField)->equals($user->getUser()->getId());
     }
     // *** do we have an RQL expression, do we need to filter data?
     if ($request->attributes->get('hasRql', false)) {
         $queryBuilder = $this->doRqlQuery($queryBuilder, $request->attributes->get('rqlQuery'));
     } else {
         // @todo [lapistano]: seems the offset is missing for this query.
         /** @var \Doctrine\ODM\MongoDB\Query\Builder $qb */
         $queryBuilder->find($this->repository->getDocumentName());
     }
     // define offset and limit
     if (!array_key_exists('skip', $queryBuilder->getQuery()->getQuery())) {
         $queryBuilder->skip($startAt);
     } else {
         $startAt = (int) $queryBuilder->getQuery()->getQuery()['skip'];
     }
     if (!array_key_exists('limit', $queryBuilder->getQuery()->getQuery())) {
         $queryBuilder->limit($numberPerPage);
     } else {
         $numberPerPage = (int) $queryBuilder->getQuery()->getQuery()['limit'];
     }
     /**
      * add a default sort on id if none was specified earlier
      *
      * not specifying something to sort on leads to very weird cases when fetching references
      */
     if (!array_key_exists('sort', $queryBuilder->getQuery()->getQuery())) {
         $queryBuilder->sort('_id');
     }
     // run query
     $query = $queryBuilder->getQuery();
     $records = array_values($query->execute()->toArray());
     $totalCount = $query->count();
     $numPages = (int) ceil($totalCount / $numberPerPage);
     $page = (int) ceil($startAt / $numberPerPage) + 1;
     if ($numPages > 1) {
         $request->attributes->set('paging', true);
         $request->attributes->set('page', $page);
         $request->attributes->set('numPages', $numPages);
         $request->attributes->set('startAt', $startAt);
         $request->attributes->set('perPage', $numberPerPage);
         $request->attributes->set('totalCount', $totalCount);
     }
     return $records;
 }
 /**
  * {@inheritdoc}
  */
 public function deleteExpired()
 {
     $result = $this->repository->createQueryBuilder()->remove()->field('expiresAt')->lt(time())->getQuery(array('safe' => true))->execute();
     return $result['n'];
 }
示例#6
0
 public function findByRiaQuery(User $ria, $limit = null)
 {
     $qb = $this->repository->createQueryBuilder()->field('riaUserId')->equals($ria->getId())->field('isShowRia')->equals(true)->limit($limit)->sort('createdAt', 'desc');
     return $qb->getQuery();
 }
 /**
  * {@inheritdoc}
  */
 public function deleteExpired()
 {
     return $this->repository->createQueryBuilder()->findAndRemove()->field('expiresAt')->lt(time())->getQuery()->execute();
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public function getIterator()
 {
     return $this->repository->createQueryBuilder()->getQuery()->getIterator();
 }
 /**
  * {@inheritdoc}
  */
 public function count()
 {
     return $this->repository->createQueryBuilder()->getQuery()->count(true);
 }