本文整理汇总了PHP中Doctrine\ORM\QueryBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder类的具体用法?PHP QueryBuilder怎么用?PHP QueryBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QueryBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: buildQuery
/**
* {@inheritDoc}
*/
public function buildQuery(QueryBuilder $qb, array $query)
{
if (isset($query['owner_id'])) {
$userAlias = $this->createAlias();
$qb->innerJoin('Omeka\\Entity\\Property.owner', $userAlias);
$qb->andWhere($qb->expr()->eq("{$userAlias}.id", $this->createNamedParameter($qb, $query['owner_id'])));
}
if (isset($query['vocabulary_id'])) {
$vocabularyAlias = $this->createAlias();
$qb->innerJoin('Omeka\\Entity\\Property.vocabulary', $vocabularyAlias);
$qb->andWhere($qb->expr()->eq("{$vocabularyAlias}.id", $this->createNamedParameter($qb, $query['vocabulary_id'])));
}
if (isset($query['vocabulary_namespace_uri'])) {
$vocabularyAlias = $this->createAlias();
$qb->innerJoin('Omeka\\Entity\\Property.vocabulary', $vocabularyAlias);
$qb->andWhere($qb->expr()->eq("{$vocabularyAlias}.namespaceUri", $this->createNamedParameter($qb, $query['vocabulary_namespace_uri'])));
}
if (isset($query['vocabulary_prefix'])) {
$vocabularyAlias = $this->createAlias();
$qb->innerJoin('Omeka\\Entity\\Property.vocabulary', $vocabularyAlias);
$qb->andWhere($qb->expr()->eq("{$vocabularyAlias}.prefix", $this->createNamedParameter($qb, $query['vocabulary_prefix'])));
}
if (isset($query['local_name'])) {
$qb->andWhere($qb->expr()->eq("Omeka\\Entity\\Property.localName", $this->createNamedParameter($qb, $query['local_name'])));
}
if (isset($query['term']) && $this->isTerm($query['term'])) {
list($prefix, $localName) = explode(':', $query['term']);
$vocabularyAlias = $this->createAlias();
$qb->innerJoin('Omeka\\Entity\\Property.vocabulary', $vocabularyAlias);
$qb->andWhere($qb->expr()->eq("{$vocabularyAlias}.prefix", $this->createNamedParameter($qb, $prefix)));
$qb->andWhere($qb->expr()->eq("Omeka\\Entity\\Property.localName", $this->createNamedParameter($qb, $localName)));
}
}
开发者ID:patrova,项目名称:omeka-s,代码行数:36,代码来源:PropertyAdapter.php
示例2: buildQuery
/**
* Build the query.
*
* @param QueryBuilder &$qb
* @param array $parameters
*
* @return QueryBuilder
*/
public function buildQuery(QueryBuilder $qb, array $parameters)
{
//Handle single tag
if (!is_array($parameters['tags'])) {
$parameters['tags'] = [$parameters['tags']];
}
//clean the parameters from the blank value
foreach ($parameters['tags'] as $index => $parameter) {
//the blank value is removed
if ($parameter === '') {
unset($parameters['tags'][$index]);
}
}
if (count($parameters['tags']) > 0) {
if (array_key_exists('strict', $parameters)) {
$repository = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article');
foreach ($parameters['tags'] as $index => $tag) {
$parameter = ':tag' . $index;
$subquery = $repository->createQueryBuilder('article_' . $index)->join('article_' . $index . '.tags', 'tag_' . $index)->where('tag_' . $index . ' = ' . $parameter);
$qb->andWhere($qb->expr()->in('main_item', $subquery->getDql()))->setParameter($parameter, $tag);
}
} else {
$qb = $qb->join('main_item.tags', 't')->andWhere('t.id IN (:tags)')->setParameter('tags', $parameters['tags']);
}
}
return $qb;
}
开发者ID:victoire,项目名称:victoire,代码行数:35,代码来源:TagFilter.php
示例3: assertValidQueryBuilder
protected function assertValidQueryBuilder(QueryBuilder $qb, $expectedDql)
{
$dql = $qb->getDql();
$q = $qb->getQuery();
$this->assertEquals($expectedDql, $dql);
}
开发者ID:roverwolf,项目名称:doctrine2,代码行数:7,代码来源:QueryBuilderTest.php
示例4: hasOrderByOnToManyJoin
/**
* Determines whether the query builder has ORDER BY on entity joined through
* to-many association.
*
* @param QueryBuilder $queryBuilder
* @param ManagerRegistry $managerRegistry
*
* @return bool
*/
public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, ManagerRegistry $managerRegistry)
{
if (empty($orderByParts = $queryBuilder->getDQLPart('orderBy')) || empty($joinParts = $queryBuilder->getDQLPart('join'))) {
return false;
}
$orderByAliases = [];
foreach ($orderByParts as $orderBy) {
$parts = QueryNameGenerator::getOrderByParts($orderBy);
foreach ($parts as $part) {
if (false !== ($pos = strpos($part, '.'))) {
$alias = substr($part, 0, $pos);
$orderByAliases[$alias] = true;
}
}
}
if (!empty($orderByAliases)) {
foreach ($joinParts as $rootAlias => $joins) {
foreach ($joins as $join) {
$alias = QueryNameGenerator::getJoinAlias($join);
if (isset($orderByAliases[$alias])) {
$relationship = QueryNameGenerator::getJoinRelationship($join);
$relationshipParts = explode('.', $relationship);
$parentAlias = $relationshipParts[0];
$association = $relationshipParts[1];
$parentMetadata = QueryNameGenerator::getClassMetadataFromJoinAlias($parentAlias, $queryBuilder, $managerRegistry);
if ($parentMetadata->isCollectionValuedAssociation($association)) {
return true;
}
}
}
}
}
return false;
}
开发者ID:akomm,项目名称:DunglasApiBundle,代码行数:43,代码来源:QueryChecker.php
示例5: modify
/**
* @param QueryBuilder $qb
* @param string $dqlAlias
*/
public function modify(QueryBuilder $qb, $dqlAlias)
{
if ($this->dqlAlias !== null) {
$dqlAlias = $this->dqlAlias;
}
$qb->groupBy(sprintf('%s.%s', $dqlAlias, $this->field));
}
开发者ID:kgilden,项目名称:Doctrine-Specification,代码行数:11,代码来源:GroupBy.php
示例6: apply
/**
* {@inheritdoc}
*
* Orders collection by properties. The order of the ordered properties is the same as the order specified in the
* query.
* For each property passed, if the resource does not have such property or if the order value is different from
* `asc` or `desc` (case insensitive), the property is ignored.
*/
public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder)
{
$request = $this->requestStack->getCurrentRequest();
if (null === $request) {
return;
}
$properties = $this->extractProperties($request);
foreach ($properties as $property => $order) {
if (!$this->isPropertyEnabled($property) || !$this->isPropertyMapped($property, $resource)) {
continue;
}
if (empty($order) && isset($this->properties[$property])) {
$order = $this->properties[$property];
}
$order = strtoupper($order);
if (!in_array($order, ['ASC', 'DESC'])) {
continue;
}
$alias = 'o';
$field = $property;
if ($this->isPropertyNested($property)) {
$propertyParts = $this->splitPropertyParts($property);
$parentAlias = $alias;
foreach ($propertyParts['associations'] as $association) {
$alias = QueryNameGenerator::generateJoinAlias($association);
$queryBuilder->leftJoin(sprintf('%s.%s', $parentAlias, $association), $alias);
$parentAlias = $alias;
}
$field = $propertyParts['field'];
}
$queryBuilder->addOrderBy(sprintf('%s.%s', $alias, $field), $order);
}
}
开发者ID:PaskR,项目名称:DunglasApiBundle,代码行数:41,代码来源:OrderFilter.php
示例7: _addSearch
/**
* get the search dql.
*
* @return string
*/
protected function _addSearch(\Doctrine\ORM\QueryBuilder $queryBuilder)
{
if ($this->search == true) {
$request = $this->request;
$search_fields = array_values($this->fields);
foreach ($search_fields as $i => $search_field) {
$search_param = $request->get("sSearch_{$i}");
if ($request->get("sSearch_{$i}") !== false && !empty($search_param)) {
$field = explode(' ', trim($search_field));
$search_field = $field[0];
if (preg_match('/~/', $search_param)) {
$search_params = explode('~', $search_param);
$from_date = date('Y-m-d 00:00:00', strtotime($search_params[0]));
$to_date = date('Y-m-d 23:59:59', strtotime($search_params[1]));
if (($search_params[0] == '' || $from_date < '2000-01-01 00:00:00') && ($search_params[1] == '' || $to_date < '2000-01-01 00:00:00')) {
// both date fields are empty/invalid -- do nothing
} elseif ($search_params[0] == '' || $from_date < '2000-01-01 00:00:00') {
$queryBuilder->andWhere(" {$search_field} <= '{$to_date}' ");
} elseif ($search_params[1] == '' || $to_date < '2000-01-01 00:00:00') {
$queryBuilder->andWhere(" {$search_field} >= '{$from_date}' ");
} else {
$queryBuilder->andWhere(" {$search_field} between '{$from_date}' and '{$to_date}' ");
}
} else {
$queryBuilder->andWhere(" {$search_field} like '%{$request->get("sSearch_{$i}")}%' ");
}
}
}
}
}
开发者ID:ruslan-polutsygan,项目名称:datatable-bundle,代码行数:35,代码来源:DoctrineBuilder.php
示例8: addCategoryConditions
/**
* Adds additional category-related conditions to query
*
* @param QueryBuilder $queryBuilder
*/
private function addCategoryConditions(QueryBuilder $queryBuilder)
{
// show products from enabled categories
$expression = $queryBuilder->expr()->eq('categories.enabled', ':enabled2');
$queryBuilder->andWhere($expression);
$queryBuilder->setParameter('enabled2', true);
}
开发者ID:raizeta,项目名称:WellCommerce,代码行数:12,代码来源:ProductDataSetQueryBuilder.php
示例9: cloneQuery
/**
* Clones a query.
*
* @param QueryBuilder $query The query.
*
* @return QueryBuilder The cloned query.
*/
public static function cloneQuery($query)
{
/* @var $cloneQuery QueryBuilder */
$cloneQuery = clone $query;
$cloneQuery->setParameters(clone $query->getParameters());
return $cloneQuery;
}
开发者ID:nnmer,项目名称:utils-bundle,代码行数:14,代码来源:Pagination.php
示例10: handleForm
/**
* @param FilterInterface $filter
* @param FormInterface $form
* @param QueryBuilder $qb
* @param string $alias
*/
public function handleForm(FilterInterface $filter, FormInterface $form, QueryBuilder $qb, $alias)
{
$data = $form->getData();
if (!$data) {
return;
}
$columns = $filter->getFullAttributeReferences($alias);
if (!empty($data[DateRangeType::START_NAME])) {
$startDate = $data[DateRangeType::START_NAME];
$dql = [];
foreach ($columns as $column) {
$uid = uniqid('fromDate');
$dql[] = "{$column} >= :{$uid}";
$qb->setParameter($uid, $startDate);
}
$qb->andWhere(implode(' OR ', $dql));
}
if (!empty($data[DateRangeType::END_NAME])) {
$endDate = $data[DateRangeType::END_NAME];
$dql = [];
foreach ($columns as $column) {
$uid = uniqid('endDate');
$dql[] = "{$column} <= :{$uid}";
$qb->setParameter($uid, $endDate);
}
$qb->andWhere(implode(' OR ', $dql));
}
}
开发者ID:VincentChalnot,项目名称:SidusFilterBundle,代码行数:34,代码来源:DateRangeFilterType.php
示例11: apply
/**
* {@inheritdoc}
*
* Order collection by properties. The order of the ordered properties is the same as the order specified in the
* query.
*/
public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder, Request $request)
{
$metadata = $this->getClassMetadata($resource);
$fieldNames = $metadata->getFieldNames();
foreach ($request->query->all() as $filter => $values) {
if (!is_array($values)) {
continue;
}
if (null !== $this->properties) {
if (false === in_array($filter, $this->properties)) {
continue;
}
}
if (in_array($filter, $fieldNames)) {
foreach ($values as $period => $date) {
$period = strtolower($period);
$date = new \DateTime($date);
if ('before' === $period) {
$parameter = sprintf('%s%s', $period, $filter);
$queryBuilder->andWhere(sprintf('o.%s <= :%s', $filter, $parameter))->setParameter($parameter, $date);
}
if ('after' === $period) {
$parameter = sprintf('%s%s', $period, $filter);
$queryBuilder->andWhere(sprintf('o.%s >= :%s', $filter, $parameter))->setParameter($parameter, $date);
}
}
}
}
}
开发者ID:reminec,项目名称:DunglasApiBundle,代码行数:35,代码来源:DateFilter.php
示例12: createPropertyPathMapping
public function createPropertyPathMapping(QueryBuilder $qb, array $fieldMapping, array $existingMapping = [])
{
if (count($qb->getRootAliases()) > 1) {
throw new \UnexpectedValueException("Expected 1 root alias");
}
$rootAlias = $qb->getRootAliases()[0];
$aliasMapping = [$rootAlias => ''];
foreach ($qb->getDQLPart('join') as $joinFrom => $joins) {
foreach ($joins as $join) {
$joinParts = explode(".", $join->getJoin());
$aliasMapping[$join->getAlias()] = trim($aliasMapping[$joinParts[0]] . '.' . $joinParts[1], '.');
}
}
$mapping = [];
foreach ($fieldMapping as $key => $field) {
if (array_key_exists($key, $existingMapping)) {
$mapping[$key] = $existingMapping[$key];
continue;
}
$fieldParts = explode('.', $field);
if (isset($fieldParts[1])) {
$alias = $fieldParts[0];
$mapping[$key] = trim($aliasMapping[$fieldParts[0]] . '.' . $fieldParts[1], '.');
} else {
$mapping[$key] = trim($fieldParts[0]);
}
}
return $mapping;
}
开发者ID:deft,项目名称:datatables-php,代码行数:29,代码来源:PropertyPathMappingFactory.php
示例13: autoJoin
private function autoJoin(QueryBuilder $queryBuilder)
{
foreach ($this->expectedJoinChains as $tablesToJoin) {
// check if the first dimension is a known alias
if (isset($this->knownAliases[$tablesToJoin[0]])) {
$joinTo = $tablesToJoin[0];
array_pop($tablesToJoin);
} else {
// if not, it's the root table
$joinTo = $queryBuilder->getRootAliases()[0];
}
foreach ($tablesToJoin as $table) {
$joinAlias = self::ALIAS_PREFIX . $table;
$join = sprintf('%s.%s', $joinTo, $table);
if (!isset($this->joinMap[$join])) {
$this->joinMap[$join] = $joinAlias;
$this->knownAliases[$joinAlias] = true;
$queryBuilder->join(sprintf('%s.%s', $joinTo, $table), $joinAlias);
} else {
$joinAlias = $this->joinMap[$join];
}
$joinTo = $joinAlias;
}
}
}
开发者ID:j0k3r,项目名称:rulerz,代码行数:25,代码来源:AutoJoin.php
示例14: getFilter
/**
* @param QueryBuilder $qb
* @param string $dqlAlias
*
* @return string
*/
public function getFilter(QueryBuilder $qb, $dqlAlias)
{
if ($this->dqlAlias !== null) {
$dqlAlias = $this->dqlAlias;
}
return (string) $qb->expr()->isNull(sprintf('%s.%s', $dqlAlias, $this->field));
}
开发者ID:happyr,项目名称:doctrine-specification,代码行数:13,代码来源:IsNull.php
示例15: queryExtraConditions
/**
* @param array $extra
* @param QueryBuilder $builder
*/
protected function queryExtraConditions(array $extra, QueryBuilder $builder)
{
foreach ($extra as $key => $extraValue) {
$builder->andWhere("e.{$key} = :{$key}");
$builder->setParameter($key, $extraValue);
}
}
开发者ID:ryan-senn,项目名称:orm,代码行数:11,代码来源:DoctrinePresenceVerifier.php
示例16: buildQuery
/**
* Build the query.
*
* @param QueryBuilder &$qb
* @param array $parameters
*
* @return QueryBuilder
*/
public function buildQuery(QueryBuilder $qb, array $parameters)
{
if (!is_array($parameters['category'])) {
$parameters['category'] = [$parameters['category']];
}
$childrenArray = [];
//clean the parameters from the blank value
foreach ($parameters['category'] as $index => $parameter) {
//the blank value is removed
if ($parameter === '') {
unset($parameters['category'][$index]);
} else {
$parentCategory = $this->getEntityManager()->getRepository('VictoireBlogBundle:Category')->findOneById($parameter);
$childrenArray = array_merge($childrenArray, $this->getCategoryChildrens($parentCategory, []));
}
}
if (count($childrenArray) > 0) {
if (array_key_exists('strict', $parameters)) {
$repository = $this->getEntityManager()->getRepository('VictoireBlogBundle:Article');
foreach ($childrenArray as $index => $category) {
$parameter = ':category' . $index;
$subquery = $repository->createQueryBuilder('article_' . $index)->join('article_' . $index . '.category', 'category_' . $index)->where('category_' . $index . ' = ' . $parameter);
$qb->andWhere($qb->expr()->in('main_item', $subquery->getDql()))->setParameter($parameter, $category);
}
} else {
$qb = $qb->join('main_item.category', 'c')->andWhere('c.id IN (:category)')->setParameter('category', $childrenArray);
}
}
return $qb;
}
开发者ID:victoire,项目名称:victoire,代码行数:38,代码来源:CategoryFilter.php
示例17: manipulateQuery
public function manipulateQuery(QueryBuilder $query, $prefix = 'hv')
{
$query->where("{$prefix}.createdAt >= :startDate");
$query->andWhere("{$prefix}.createdAt <= :endDate");
$query->setParameters(['startDate' => $this->period->getStartDate(), 'endDate' => $this->period->getEndDate()]);
return $query;
}
开发者ID:piotrpasich,项目名称:HighFiveSlackBundle,代码行数:7,代码来源:Period.php
示例18: Expr
function it_adds_binary_filter_in_the_query(QueryBuilder $queryBuilder)
{
$queryBuilder->expr()->willReturn(new Expr());
$queryBuilder->getRootAliases()->willReturn(['p']);
$queryBuilder->andWhere('p.id = \'12\'')->shouldBeCalled();
$this->addFieldFilter('id', '=', '12');
}
开发者ID:abdeldayem,项目名称:pim-community-dev,代码行数:7,代码来源:ProductIdFilterSpec.php
示例19: filter
/**
* {@inheritdoc}
*/
public function filter(Request $request, QueryBuilder $queryBuilder)
{
if ($request->query->has('per_page') && $request->query->has('page')) {
$queryBuilder->setMaxResults($request->query->get('per_page'));
$queryBuilder->setFirstResult(($request->query->get('page') - 1) * $request->query->get('per_page'));
}
}
开发者ID:csbill,项目名称:csbill,代码行数:10,代码来源:PaginateFilter.php
示例20: apply
/**
* Apply the ACL constraints to the specified query builder, using the permission definition
*
* @param QueryBuilder $queryBuilder The query builder
* @param PermissionDefinition $permissionDef The permission definition
*
* @return Query
*/
public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissionDef)
{
$whereQueryParts = $queryBuilder->getDQLPart('where');
if (empty($whereQueryParts)) {
$queryBuilder->where('1 = 1');
// this will help in cases where no where query is specified
}
$query = $this->cloneQuery($queryBuilder->getQuery());
$builder = new MaskBuilder();
foreach ($permissionDef->getPermissions() as $permission) {
$mask = constant(get_class($builder) . '::MASK_' . strtoupper($permission));
$builder->add($mask);
}
$query->setHint('acl.mask', $builder->get());
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Kunstmaan\\AdminBundle\\Helper\\Security\\Acl\\AclWalker');
$rootEntity = $permissionDef->getEntity();
$rootAlias = $permissionDef->getAlias();
// If either alias or entity was not specified - use default from QueryBuilder
if (empty($rootEntity) || empty($rootAlias)) {
$rootEntities = $queryBuilder->getRootEntities();
$rootAliases = $queryBuilder->getRootAliases();
$rootEntity = $rootEntities[0];
$rootAlias = $rootAliases[0];
}
$query->setHint('acl.root.entity', $rootEntity);
$query->setHint('acl.extra.query', $this->getPermittedAclIdsSQLForUser($query));
$classMeta = $this->em->getClassMetadata($rootEntity);
$entityRootTableName = $this->quoteStrategy->getTableName($classMeta, $this->em->getConnection()->getDatabasePlatform());
$query->setHint('acl.entityRootTableName', $entityRootTableName);
$query->setHint('acl.entityRootTableDqlAlias', $rootAlias);
return $query;
}
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:40,代码来源:AclHelper.php
注:本文中的Doctrine\ORM\QueryBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论