本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::select方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::select方法的具体用法?PHP QueryBuilder::select怎么用?PHP QueryBuilder::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: should_create_complex_query
/**
* @test
*/
public function should_create_complex_query()
{
$specification = $this->userSpecificationFactory->status('approved')->orX($this->userSpecificationFactory->status('declined')->andX($this->userSpecificationFactory->name('John')));
$this->queryBuilder->select('user')->from('User', 'user')->where($specification->expr())->setParameters($specification->parameters());
$this->assertEquals(['status_1' => 'approved', 'status_2' => 'declined', 'name_3' => 'John'], $specification->parameters());
$this->assertEquals('SELECT user FROM User user WHERE user.status = :status_1 OR (user.status = :status_2 AND user.name = :name_3)', $this->queryBuilder->getDQL());
}
示例2: searchOne
/**
* @param ChannelConditionInterface $condition
* @return ChannelInterface
*/
public function searchOne(ChannelConditionInterface $condition)
{
$this->qb = $this->em->createQueryBuilder();
$this->qb->select('ch')->from('CoreBundle:Channel', 'ch');
$this->initQueryBuilder($condition);
return $this->qb->getQuery()->getOneOrNullResult();
}
示例3: __construct
/**
* Constructor.
*
* @access public
* @param ORM\QueryBuilder $query
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
public function __construct(ORM\QueryBuilder $query)
{
$this->query = $query;
$this->oCountingQuery = clone $this->query;
$this->oCountingQuery->select('COUNT(DISTINCT t.id)');
$this->iCount = $this->getCountingQuery()->single();
}
示例4: __construct
/**
* Constructor
*
* @param EntityManager $manager
* @param string $class
*/
public function __construct(EntityManager $manager, $class)
{
$this->manager = $manager;
$this->metadata = $manager->getClassMetadata($class);
$this->qBuilder = $manager->createQueryBuilder();
$this->qBuilder->select('e')->from($class, 'e');
}
示例5: search
/**
* @param CompanyConditionInterface $condition
* @return Company[]
*/
public function search(CompanyConditionInterface $condition)
{
$this->qb = $this->em->createQueryBuilder();
$this->qb->select('co')->from('CoreBundle:Company', 'co');
$this->initQueryBuilder($condition);
$this->preparePagination($this->qb, $condition);
return $this->qb->getQuery()->getResult();
}
示例6: searchArticlesByTags
/**
* Return an article array by tag
* @param $strings
* @return array
*/
public function searchArticlesByTags($strings)
{
$strings = $this->setCleanRequest($strings);
$this->qb->select('t')->from('AppBundle:Tag', 't')->where('t.slug LIKE :strings')->addOrderBy('t.frequency', 'DESC')->setParameter('strings', $strings);
$q = $this->qb->getQuery();
$tags = $q->getResult();
$articlesArray = array();
foreach ($tags as $tag) {
$articles = $tag->getArticles();
foreach ($articles as $article) {
array_push($articlesArray, $article);
}
}
return $articlesArray;
}
示例7: buildCount
public function buildCount(QueryBuilder $queryBuilder) : Query
{
if (!empty($this->name)) {
$queryBuilder->where($queryBuilder->expr()->like('o.name.name', ':name'))->setParameter('name', '%' . $this->name . '%');
}
return $queryBuilder->select($queryBuilder->expr()->count('o.id'))->from(Organization::class, 'o')->leftJoin('o.organizationMembers', 'om')->leftJoin('o.owners', 'ow')->andWhere($queryBuilder->expr()->orX($queryBuilder->expr()->eq('om.userId', ':userId'), $queryBuilder->expr()->eq('ow.userId', ':userId')))->setParameter('userId', $this->userId->id())->getQuery();
}
示例8: homeAction
/**
* @route: blog_home
* Homepage controller
*/
public function homeAction()
{
// entity manager
$em = $this->getEm();
$qb = new QueryBuilder($em);
// dql query
$qb->select('p,c,t')
->from('Bundle\BlogBundle\Entity\Post', 'p')
->join('p.category', 'c')
->join('p.tags', 't')
->orderBy('p.date', 'DESC');
// array of objects
$posts = $qb->getQuery()->getResult();
$query = $em->createQuery('SELECT c,p FROM Bundle\BlogBundle\Entity\Category c JOIN c.posts p');
$categories = $query->getResult();
$query = $em->createQuery('SELECT t,p FROM Bundle\BlogBundle\Entity\Tag t JOIN t.posts p');
$tags = $query->getResult();
return $this->render('BlogBundle:Blog:homepage.html.twig', array(
'posts' => $posts,
'categories' => $categories,
'tags' => $tags
));
}
示例9: getFilteredCountQuery
/**
* Build the count of filtered query
*
* @return QueryBuilder
*/
public function getFilteredCountQuery()
{
$this->buildFilteredQuery();
$this->currentQueryBuilder->select('COUNT(DISTINCT ' . $this->getDistinct() . ')');
$this->currentQueryBuilder->resetDQLPart('orderBy');
return $this->currentQueryBuilder;
}
示例10: leftMenuAction
/**
* @extra:Route("/", name="_alf")
* @extra:Template()
*/
public function leftMenuAction()
{
// $catalog = new Catalogs();
// $catalog->setCategory('1');
// $catalog->setName('skarpety wpisane');
// $em = $this->get('doctrine.orm.entity_manager');
// $em->persist($catalog);
// $em->flush();
// $menu = $this->get('doctrine.orm.entity_manager')
// ->createQuery('SELECT c FROM AlfShopBundle:Catalogs c ORDER BY c.id DESC')
// ->getResult()
// ;
// $menu = array( array('name' => 'A'), array('name' => 'B'),array('name' => 'C'));
$em = $this->get('doctrine.orm.entity_manager');
$qb = new QueryBuilder($em);
$dql = $qb->select('c.name')->from('AlfShopBundle:Catalogs', 'c')->getQuery();
$menu = $dql->getResult();
$em = $this->get('doctrine.orm.entity_manager');
$qb = new QueryBuilder($em);
$dql = $qb->select('c')->from('AlfShopBundle:Catalogs', 'c');
$query = $em->createQuery($dql);
$adapter = $this->get('knplabs_paginator.adapter');
$adapter->setQuery($query);
$adapter->setDistinct(true);
$paginator = new \Zend\Paginator\Paginator($adapter);
$paginator->setCurrentPageNumber($this->get('request')->query->get('page', 1));
$paginator->setItemCountPerPage(2);
$paginator->setPageRange(5);
// $menu = $m ->getResult();
// $menu = $em->find('AlfShopBundle:Catalogs');
// $em->persist($menu);
// $em->flush();
// $menu = array('A', 'B');
return $this->render('AlfShopBundle:Shop:leftMenu.html.twig', array('menuList' => $paginator, 'paginator' => $paginator));
}
示例11: buildDataRequestQuery
/**
* Builds the query for the given data request object
*
* @access public
* @param \Zepi\DataSource\Core\Entity\DataRequest $dataRequest
* @param \Doctrine\ORM\QueryBuilder $queryBuilder
* @param string $entity
* @param string $tableCode
*/
public function buildDataRequestQuery(DataRequest $dataRequest, QueryBuilder $queryBuilder, $entity, $tableCode)
{
$queryBuilder->select($tableCode)->from($entity, $tableCode);
$hasWhere = false;
$i = 1;
foreach ($dataRequest->getFilters() as $filter) {
$whereQuery = $tableCode . '.' . $filter->getFieldName() . ' ' . $filter->getMode() . ' :' . $i;
if ($hasWhere) {
$queryBuilder->andWhere($whereQuery);
} else {
$queryBuilder->where($whereQuery);
$hasWhere = true;
}
$queryBuilder->setParameter($i, $filter->getNeededValue());
$i++;
}
// Sorting
if ($dataRequest->hasSorting()) {
$mode = 'ASC';
if (in_array($dataRequest->getSortByDirection(), array('ASC', 'DESC'))) {
$mode = $dataRequest->getSortByDirection();
}
$queryBuilder->orderBy($tableCode . '.' . $dataRequest->getSortBy(), $mode);
}
// Offset
if ($dataRequest->hasRange()) {
$queryBuilder->setFirstResult($dataRequest->getOffset());
$queryBuilder->setMaxResults($dataRequest->getNumberOfEntries());
}
}
示例12: implement
public function implement(DoctrineQueryBuilder $queryBuilder)
{
if (!$this->getValue()) {
return $queryBuilder;
}
$queryBuilder->select('COUNT(' . QueryBuilder::DEFAULT_ALIAS . '.id)');
}
示例13: getQueryBuilder
public function getQueryBuilder()
{
if (!$this->queryBuilder) {
$this->queryBuilder = $this->em->createQueryBuilder();
$this->queryBuilder->select('root')->from($this->getClassMetadata()->getName(), 'root');
}
return $this->queryBuilder;
}
示例14: selectListQuery
/**
* Helper function which sets the fromPath and the selectPath for the order list query.
* @param \Doctrine\ORM\QueryBuilder $builder
* @return \Doctrine\ORM\QueryBuilder
*/
protected function selectListQuery(\Doctrine\ORM\QueryBuilder $builder)
{
//select the different entities
$builder->select(array('documents.id as id', 'documents.date as date', 'documents.typeId as typeId', 'documents.customerId as customerId', 'documents.orderId as orderId', 'documents.amount as amount', 'documents.documentId as documentId', 'documents.hash as hash', 'type.name as typeName'));
//join the required tables for the order list
$builder->from('Shopware\\Models\\Order\\Document\\Document', 'documents')->join('documents.type', 'type');
return $builder;
}
示例15: testAddDatePartsSelect
/**
* @dataProvider addDatePartsSelectProvider
*/
public function testAddDatePartsSelect($start, $end, $expects)
{
$start = new \DateTime($start, new \DateTimeZone('UTC'));
$end = new \DateTime($end, new \DateTimeZone('UTC'));
$queryBuilder = new QueryBuilder($this->getTestEntityManager());
$queryBuilder->select('id')->from('Oro\\Bundle\\DashboardBundle\\Tests\\Unit\\Fixtures\\FirstTestBundle\\Entity\\TestEntity', 't');
$this->helper->addDatePartsSelect($start, $end, $queryBuilder, 't.createdAt');
$this->assertEquals($expects, $queryBuilder->getDQL());
}