當前位置: 首頁>>代碼示例>>PHP>>正文


PHP QueryBuilder::getParameters方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\QueryBuilder::getParameters方法的典型用法代碼示例。如果您正苦於以下問題:PHP QueryBuilder::getParameters方法的具體用法?PHP QueryBuilder::getParameters怎麽用?PHP QueryBuilder::getParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder::getParameters方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCreateDataSet_conflictingFilters

 public function testCreateDataSet_conflictingFilters()
 {
     $request = $this->getBaseRequest();
     $this->qb->andWhere('p.id = ?0')->setParameter(0, 'Test');
     $request->columnFilters[0] = 'test';
     $dataSet = $this->dataSource->createDataSet($request);
     $where = $this->qb->getDQLPart('where')->getParts();
     $this->assertCount(2, $where);
     $this->assertCount(2, $this->qb->getParameters());
 }
開發者ID:deft,項目名稱:datatables-php,代碼行數:10,代碼來源:QueryBuilderDataSourceTest.php

示例2: getSize

 /**
  * {@inheritdoc}
  */
 public function getSize()
 {
     if (null === $this->size) {
         $qb = clone $this->queryBuilder;
         $alias = current($qb->getRootAliases());
         $qb->setParameters($this->queryBuilder->getParameters());
         $qb->select("count({$alias})");
         $this->size = (int) $qb->getQuery()->getSingleScalarResult();
     }
     return $this->size;
 }
開發者ID:mcdir,項目名稱:SonatraFormExtensionsBundle,代碼行數:14,代碼來源:AjaxORMQueryBuilderLoader.php

示例3: 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

示例4:

 function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, ArrayCollection $parameters)
 {
     $this->beConstructedWith(Comparison::GT, 'age', 18, null);
     $qb->getParameters()->willReturn($parameters);
     $parameters->count()->willReturn(10);
     $qb->setParameter('comparison_10', 18)->shouldBeCalled();
     $this->getFilter($qb, 'x')->shouldReturn('x.age > :comparison_10');
 }
開發者ID:happyr,項目名稱:doctrine-specification,代碼行數:8,代碼來源:ComparisonSpec.php

示例5: it_ends_with_wildcard_when_using_starts_with

 public function it_ends_with_wildcard_when_using_starts_with(QueryBuilder $qb, ArrayCollection $parameters)
 {
     $this->beConstructedWith($this->field, $this->value, Like::STARTS_WITH, "dqlAlias");
     $qb->getParameters()->willReturn($parameters);
     $parameters->count()->willReturn(1);
     $qb->setParameter("comparison_1", "bar%")->shouldBeCalled();
     $this->match($qb, null);
 }
開發者ID:happyr,項目名稱:doctrine-specification,代碼行數:8,代碼來源:LikeSpec.php

示例6:

 function it_returns_expression_func_object(QueryBuilder $qb, ArrayCollection $parameters, Expr $expr)
 {
     $dqlAlias = 'a';
     $qb->expr()->willReturn($expr);
     $expr->in(sprintf('%s.%s', $dqlAlias, $this->field), ':in_10')->shouldBeCalled();
     $qb->getParameters()->willReturn($parameters);
     $parameters->count()->willReturn(10);
     $qb->setParameter('in_10', $this->value)->shouldBeCalled();
     $this->getFilter($qb, null);
 }
開發者ID:happyr,項目名稱:doctrine-specification,代碼行數:10,代碼來源:InSpec.php

示例7: removeExtraParameters

 /**
  * We update the query to count, get ids and fetch data, so, we can lost expected query builder parameters,
  * and we have to remove them
  *
  * @param QueryBuilder $qb
  */
 public static function removeExtraParameters(QueryBuilder $qb)
 {
     $parameters = $qb->getParameters();
     $dql = $qb->getDQL();
     foreach ($parameters as $parameter) {
         if (strpos($dql, ':' . $parameter->getName()) === false) {
             $parameters->removeElement($parameter);
         }
     }
     $qb->setParameters($parameters);
 }
開發者ID:javiersantos,項目名稱:pim-community-dev,代碼行數:17,代碼來源:QueryBuilderUtility.php

示例8: andWherePupilNotIn

 /**
  * @param QueryBuilder $query
  * @param QueryBuilder $subQuery
  * @return QueryBuilder $query with query's and subQuery's parameters.
  */
 private function andWherePupilNotIn(QueryBuilder $query, QueryBuilder $subQuery, $EleveQueryAlias)
 {
     $query->andWhere($query->expr()->notIn($EleveQueryAlias . ".id", $subQuery->getDQL()));
     /**
      * @var Parameter $param
      */
     foreach ($subQuery->getParameters() as $param) {
         $query->setParameter($param->getName(), $param->getValue(), $param->getType());
     }
     return $query;
 }
開發者ID:WildCodeSchool,項目名稱:projet-gesty,代碼行數:16,代碼來源:ActivityRepositoryAbstract.php

示例9: fixUnusedParameters

 /**
  * Removes unused parameters from query builder
  *
  * @param QueryBuilder $qb
  */
 public function fixUnusedParameters(QueryBuilder $qb)
 {
     $dql = $qb->getDQL();
     $usedParameters = [];
     /** @var $parameter \Doctrine\ORM\Query\Parameter */
     foreach ($qb->getParameters() as $parameter) {
         if ($this->dqlContainsParameter($dql, $parameter->getName())) {
             $usedParameters[$parameter->getName()] = $parameter->getValue();
         }
     }
     $qb->setParameters($usedParameters);
 }
開發者ID:northdakota,項目名稱:platform,代碼行數:17,代碼來源:QueryBuilderTools.php

示例10: getPaginator

 /**
  * Get Paginator
  * 
  * @param integer $limit ( limit per page )
  * @param array $options
  * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
  */
 protected function getPaginator($limit = 30, $options = array())
 {
     $page = $this->get('request')->query->get('page', 1);
     $cnt = 0;
     if ($this->get('request')->query->has('page')) {
         $page = $this->get('request')->query->get('page');
         $this->get('session')->set('_pager_' . $this->get('request')->get('_route'), $page);
     } elseif ($this->get('session')->has('_pager_' . $this->get('request')->get('_route'))) {
         $page = $this->get('session')->get('_pager_' . $this->get('request')->get('_route'));
     }
     if (isset($options['total_item_count']) and (int) $options['total_item_count']) {
         $cnt = $options['total_item_count'];
     }
     $this->paginator = $this->get('knp_paginator');
     if (is_array($this->query) or $this->query instanceof QueryBuilder) {
         $pagination = $this->paginator->paginate($this->query, $page, $limit, $options);
     } elseif ($this->query instanceof NativeQuery) {
         $rsm = new ResultSetMapping();
         $rsm->addScalarResult('cnt', 'cnt');
         $q = strstr($this->query->getSQL(), " FROM ");
         $q = "SELECT COUNT(*) cnt " . $q;
         $cntQuery = $this->em->createNativeQuery($q, $rsm)->setParameters($this->query->getParameters());
         try {
             $cnt = $cntQuery->getSingleScalarResult();
         } catch (\Doctrine\Orm\NoResultException $e) {
             $cnt = 0;
         }
         $sql = $this->query->getSQL();
         $pagination = $this->paginator->paginate(array());
         $sort_name = $pagination->getPaginatorOption('sortFieldParameterName');
         $sort_direction_name = $pagination->getPaginatorOption('sortDirectionParameterName');
         if ($this->get('request')->query->has($sort_name) and $this->get('request')->query->has($sort_direction_name)) {
             $sql .= ' ORDER BY ' . $this->get('request')->query->get($sort_name) . ' ' . $this->get('request')->query->get($sort_direction_name);
         } elseif (isset($options['default_sort']) and $options['default_sort']) {
             $sql .= ' ORDER BY ';
             foreach ($options['default_sort'] as $field => $type) {
                 $sql .= $field . ' ' . $type . ',';
             }
             $sql = trim($sql, ',');
         }
         if (!isset($options['not_use_limit_offset'])) {
             $offset = $limit * ($page - 1);
             $this->query->setSQL($sql . ' LIMIT ' . $limit . ' OFFSET ' . $offset);
         }
         $pagination->setCurrentPageNumber($page);
         $pagination->setItemNumberPerPage($limit);
         $pagination->setTotalItemCount($cnt);
         $pagination->setItems($this->query->getResult());
     }
     $pagination->setTemplate($this->container->getParameter('zk2_admin_panel.pagination_template'));
     $pagination->setSortableTemplate($this->container->getParameter('zk2_admin_panel.sortable_template'));
     return compact('pagination');
 }
開發者ID:zk2,項目名稱:admin-panel-bundle,代碼行數:60,代碼來源:AdminPanelController.php

示例11: getRawSQLFromORMQueryBuilder

 /**
  * @param QueryBuilder $qb
  *
  * @return string
  */
 public function getRawSQLFromORMQueryBuilder(QueryBuilder $qb)
 {
     $sql = $qb->getDQL();
     $parameters = $qb->getParameters();
     /** @var Query\Parameter $param */
     foreach ($parameters as $param) {
         if (is_array($param->getValue()) && !empty($param->getValue())) {
             $sql = str_replace(':' . $param->getName(), "'" . implode("', '", $param->getValue()) . "'", $sql);
         } else {
             $sql = str_replace(':' . $param->getName(), "'" . $param->getValue() . "'", $sql);
         }
     }
     return $sql;
 }
開發者ID:omusico,項目名稱:zf2-demo,代碼行數:19,代碼來源:AbstractRepositoryTestCase.php

示例12: getItemsCountInCategory

 /**
  * {@inherit}
  */
 public function getItemsCountInCategory(CategoryInterface $category, QueryBuilder $categoryQb = null)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select($qb->expr()->count('distinct i'));
     $qb->from($this->entityName, 'i');
     $qb->join('i.categories', 'node');
     if (null === $categoryQb) {
         $qb->where('node.id = :nodeId');
         $qb->setParameter('nodeId', $category->getId());
     } else {
         $qb->where($categoryQb->getDqlPart('where'));
         $qb->setParameters($categoryQb->getParameters());
     }
     return $qb->getQuery()->getSingleScalarResult();
 }
開發者ID:alexisfroger,項目名稱:pim-community-dev,代碼行數:18,代碼來源:AbstractItemCategoryRepository.php

示例13: applyMassActionParameters

 /**
  * Applies mass action parameters on the query builder
  *
  * @param QueryBuilder $qb
  * @param bool         $inset
  * @param array        $values
  */
 public function applyMassActionParameters($qb, $inset, $values)
 {
     if (!empty($values)) {
         $valueWhereCondition = $inset ? $qb->expr()->in($this->getAlias(), $values) : $qb->expr()->notIn($this->getAlias(), $values);
         $qb->andWhere($valueWhereCondition);
     }
     if (null !== $qb->getDQLPart('where')) {
         $whereParts = $qb->getDQLPart('where')->getParts();
         $qb->resetDQLPart('where');
         foreach ($whereParts as $part) {
             if (!is_string($part) || !strpos($part, 'entityIds')) {
                 $qb->andWhere($part);
             }
         }
     }
     $qb->setParameters($qb->getParameters()->filter(function ($parameter) {
         return $parameter->getName() !== 'entityIds';
     }));
     // remove limit of the query
     $qb->setMaxResults(null);
 }
開發者ID:ronanguilloux,項目名稱:CustomEntityBundle,代碼行數:28,代碼來源:CustomEntityRepository.php

示例14: testApply

 /**
  * @dataProvider applyDataProvider
  */
 public function testApply($platform, $value, $comparisonType, $expectedDql, $expectedParams)
 {
     $paramCounter = 0;
     $em = $this->getMock('Doctrine\\ORM\\EntityManagerInterface');
     $qb = new QueryBuilder($em);
     $ds = $this->getMock('Oro\\Bundle\\FilterBundle\\Datasource\\Orm\\OrmFilterDatasourceAdapter', ['generateParameterName', 'getDatabasePlatform'], [$qb]);
     $ds->expects($this->any())->method('generateParameterName')->willReturnCallback(function () use(&$paramCounter) {
         return sprintf('param%s', ++$paramCounter);
     });
     $ds->expects($this->any())->method('getDatabasePlatform')->willReturn($platform);
     $data = ['type' => $comparisonType, 'value' => $value];
     $em->expects($this->any())->method('getExpressionBuilder')->willReturn(new Query\Expr());
     $qb->select('j')->from('TestEntity', 'j');
     $this->filter->apply($ds, $data);
     $this->assertEquals($expectedDql, $qb->getDQL());
     $params = [];
     /** @var Query\Parameter $param */
     foreach ($qb->getParameters() as $param) {
         $params[$param->getName()] = $param->getValue();
     }
     $this->assertEquals($expectedParams, $params);
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:25,代碼來源:CommandWithArgsFilterTest.php

示例15: addCriteria

 /**
  * @param QueryBuilder $qb
  * @param Criteria     $criteria
  */
 public static function addCriteria(QueryBuilder $qb, Criteria $criteria)
 {
     $rootAlias = $qb->getRootAlias();
     $visitor = new QueryExpressionVisitor($rootAlias);
     if ($whereExpression = $criteria->getWhereExpression()) {
         $qb->andWhere($visitor->dispatch($whereExpression));
         foreach ($visitor->getParameters() as $parameter) {
             $qb->getParameters()->add($parameter);
         }
     }
     if ($criteria->getOrderings()) {
         foreach ($criteria->getOrderings() as $sort => $order) {
             $qb->addOrderBy($rootAlias . '.' . $sort, $order);
         }
     }
     // Overwrite limits only if they was set in criteria
     if (($firstResult = $criteria->getFirstResult()) !== null) {
         $qb->setFirstResult($firstResult);
     }
     if (($maxResults = $criteria->getMaxResults()) !== null) {
         $qb->setMaxResults($maxResults);
     }
 }
開發者ID:nmallare,項目名稱:platform,代碼行數:27,代碼來源:QueryBuilderHelper.php


注:本文中的Doctrine\ORM\QueryBuilder::getParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。