/**
  * @param ServiceManager $serviceManager
  * @return Form
  */
 public function setServiceManager(ServiceManager $serviceManager)
 {
     $this->serviceManager = $serviceManager;
     $this->entityManager = $serviceManager->get('doctrine.entitymanager.orm_default');
     $this->queryBuilder = $this->entityManager->createQueryBuilder();
     return $this;
 }
Exemple #2
0
 public function getUsersActives()
 {
     $lastKeepalive = new \DateTime("now");
     $lastKeepalive->modify("-" . $this->sessionLifeTime . " seconds");
     $query = $this->em->createQueryBuilder()->select('u')->from('CdiUser\\Entity\\User', 'u')->where('u.lastKeepalive > :lk ')->setParameter("lk", $lastKeepalive);
     $colUsers = $query->getQuery()->getResult();
     if ($colUsers) {
         return $colUsers;
     } else {
         return null;
     }
 }
 /**
  *
  * @param  Doctrine\ORM\EntityManager $em
  * @param  string                     $entityName
  * @param  OutputInterface            $output
  * @return integer
  */
 private function countSaveEntity($em, $entityName, $output)
 {
     $output->write("<info>Counting " . $entityName . "</info> ");
     $count = $em->createQueryBuilder()->select('count(entity.id)')->from($entityName, 'entity')->getQuery()->getSingleScalarResult();
     $output->writeln(" <info> Result : " . $count . "</info>");
     $output->writeln("<info>Saving count result to OjsJournalBundle:Sums");
     $this->saveSum($em, $entityName, $count);
     return $count;
 }
 /**
  * {@inheritdoc}
  */
 public function showMessages($queueName)
 {
     $results = [];
     if ($this->isExists($queueName)) {
         $qb = $this->em->createQueryBuilder();
         $qb->select('m.id, m.body, m.created, m.ended, m.failed')->from('Heri\\Bundle\\JobQueueBundle\\Entity\\Message', 'm')->leftJoin('m.queue', 'Queue')->where($qb->expr()->eq('Queue.name', ':name'))->setParameter('name', $queueName);
         $query = $qb->getQuery();
         $results = $query->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
     }
     return $results;
 }
 public function catalogo3Action()
 {
     $this->view->fabricantes = $this->_fabricante->findAll();
     $id = $this->_getParam('id', false);
     if ($id) {
         $this->view->id = $id;
         $this->view->fabricante = $this->_fabricante->find($id);
         $qb = $this->em->createQueryBuilder()->select('p, f')->from("\\Models\\Entity\\Producto", 'p')->leftJoin('p.Fabricante', 'f')->orderBy('p.name', 'ASC')->where('p.id > 25')->andWhere('f.id = ' . $id);
         $q = $qb->getQuery();
         $this->view->Productos25 = $q->execute();
         $this->view->Productos25Array = $q->getArrayResult();
     }
 }
 /**
  * Gets the Doctrine Query object to be used by the validator.
  * If no select object was supplied to the constructor,
  * then it will auto-generate one from the given table,
  * schema, field, and adapter options.
  *
  * @return Doctrine\ORM\Query The Query object which will be used
  */
 public function getQuery($value)
 {
     if (null === $this->_query) {
         $this->getEntityManager();
         $qb = $this->_em->createQueryBuilder();
         $qb->add('select', 'e')->add('from', $this->_entity . ' e');
         $where = null;
         if ($this->_exclude !== null) {
             if (is_array($this->_exclude)) {
                 $excludeClause = $qb->expr()->neq('e.' . $this->_exclude['field'], ':exclude');
                 $qb->setParameter('exclude', $this->_exclude['value']);
             } else {
                 $excludeClause = $qb->expr()->neq($this->_exclude);
             }
             $qb->add('where', $qb->expr()->andx($qb->expr()->eq('e.' . $this->_field, ':field'), $excludeClause));
         } else {
             $qb->add('where', $qb->expr()->eq('e.' . $this->_field, ':field'));
         }
         $qb->setParameter('field', $value);
         $qb->setMaxResults(1);
         $this->_query = $qb->getQuery();
     }
     return $this->_query;
 }
 /**
  * Return a Doctrine\Orm\QueryBuilder.
  *
  * @return Doctrine\Orm\QueryBuilder
  */
 protected function getQueryBuilder()
 {
     return $this->em->createQueryBuilder();
 }
Exemple #8
0
 /**
  * Construct the Doctrine query.
  *
  * @return Doctrine\ORM\Query
  */
 protected function _getQuery()
 {
     $qb = $this->em->createQueryBuilder()->select('e.' . $this->credentialField . ', e')->from($this->entityName, 'e')->where('e.' . $this->identityField . ' = ?1');
     return $qb->getQuery();
 }