本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::getParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getParameter方法的具体用法?PHP QueryBuilder::getParameter怎么用?PHP QueryBuilder::getParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::getParameter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLoader
/**
* Return the default loader object.
*
* @param ObjectManager $manager
* @param QueryBuilder $queryBuilder
* @param string $class
*
* @return EntityLoaderInterface
*/
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
{
$queryBuilder->innerJoin(NodeVersion::class, 'nv', Join::WITH, 'nv.refId = e.id and nv.refEntityName = :ref_name');
$queryBuilder->innerJoin(NodeTranslation::class, 'nt', Join::WITH, 'nt.id = nv.nodeTranslation and nt.publicNodeVersion = nv.id');
$queryBuilder->innerJoin(Node::class, 'n', Join::WITH, 'n.id = nt.node');
$queryBuilder->andWhere($queryBuilder->expr()->eq("n.deleted", 0));
$queryBuilder->andWhere($queryBuilder->expr()->eq('nt.online', 1));
$queryBuilder->setParameter("ref_name", $class);
if (null !== $queryBuilder->getParameter('left') && null !== $queryBuilder->getParameter('right')) {
$queryBuilder->andWhere('n.lft >= :left')->andWhere('n.rgt <= :right');
}
if (null !== $queryBuilder->getParameter('lang')) {
$queryBuilder->andWhere('nt.lang = :lang');
}
return new ORMQueryBuilderLoader($queryBuilder, $manager, $class);
}
示例2: getParamName
/**
* @param string $field
* @return string
*/
private function getParamName($field)
{
$paramName = str_replace('.', '_', $field);
$counter = 0;
do {
$index = substr($paramName, strrpos($paramName, '_') + 1);
if (is_numeric($index)) {
$paramName = substr_replace($paramName, $counter, strrpos($paramName, '_') + 1);
$counter++;
} else {
$paramName .= "_{$counter}";
}
} while ($this->qb->getParameter($paramName));
return $paramName;
}
示例3: hasParameterName
/**
* @param string $parameterName
*
* @return bool
*/
private function hasParameterName($parameterName)
{
return null !== $this->queryBuilder->getParameter($parameterName);
}
示例4: handleOperator
/**
* Gets the proper query expression for the set of data given.
*
* @param QueryBuilder $queryBuilder
* @param string $alias alias of the entity to which belongs the property
* @param ClassMetadata $aliasMetadata
* @param string $property
* @param string $operator
* @param string|array $value
* @param string|null $parameter If is string is used to construct the parameter to avoid parameter conflicts.
*
* @return Expr|null
*/
private function handleOperator(QueryBuilder $queryBuilder, $alias, ClassMetadata $aliasMetadata, $property, $operator, $value, $parameter = null)
{
$queryExpr = null;
if (null === $parameter) {
$parameter = $property;
}
// Only particular case: the between operator
if (self::PARAMETER_OPERATOR_BETWEEN === $operator && is_array($value) && 2 === count($value)) {
$value = array_values($value);
$paramBefore = sprintf(':between_before_%s', $parameter);
$paramAfter = sprintf(':between_after_%s', $parameter);
$queryExpr = $queryBuilder->expr()->between(sprintf('%s.%s', $alias, $property), $paramBefore, $paramAfter);
$queryBuilder->setParameter($paramBefore, $value[0])->setParameter($paramAfter, $value[1]);
return $queryExpr;
}
// Expect $value to be a string
if (false === is_string($value)) {
return null;
}
// Normalize $value before using it
$value = $this->normalizeValue($aliasMetadata, $property, $value);
$parameterValue = self::PARAMETER_OPERATOR_LIKE === $operator || self::PARAMETER_OPERATOR_NLIKE === $operator ? sprintf('%%%s%%', $value) : $value;
switch ($operator) {
case self::PARAMETER_OPERATOR_GT:
$queryExpr = $queryBuilder->expr()->gt(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
case self::PARAMETER_OPERATOR_GTE:
$queryExpr = $queryBuilder->expr()->gte(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
case self::PARAMETER_OPERATOR_LT:
$queryExpr = $queryBuilder->expr()->lt(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
case self::PARAMETER_OPERATOR_LTE:
$queryExpr = $queryBuilder->expr()->lte(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
case self::PARAMETER_OPERATOR_NEQ:
if (null === $value) {
// Skip the set parameter that takes place after the switch case
return $queryBuilder->expr()->isNotNull(sprintf('%s.%s', $alias, $property));
} else {
$queryExpr = $queryBuilder->expr()->neq(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
}
break;
case self::PARAMETER_OPERATOR_LIKE:
$queryExpr = $queryBuilder->expr()->like(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
case self::PARAMETER_OPERATOR_NLIKE:
$queryExpr = $queryBuilder->expr()->notLike(sprintf('%s.%s', $alias, $property), sprintf(':%s', $parameter));
break;
}
if (null === $queryBuilder->getParameter($parameter)) {
$queryBuilder->setParameter($parameter, $parameterValue);
}
return $queryExpr;
}
示例5: getPaginatedResult
/**
* An internal method for getting paginated results from querybuilder
* @param QueryBuilder $queryBuilder
* @param PaginationParameters $paginationParameters
* @param $resultKey Deprecated, use HIDDEN keyword instead
* @return \Zend\Paginator\Paginator
*/
public function getPaginatedResult(QueryBuilder $queryBuilder, PaginationParameters $paginationParameters, $resultKey = null)
{
if ($paginationParameters->getOrder() != null && $paginationParameters->getSort() != null) {
if (!is_array($paginationParameters->getSort()) && !is_array($paginationParameters->getOrder())) {
$sort = array($paginationParameters->getSort());
$order = array($paginationParameters->getOrder());
} else {
if (count($paginationParameters->getSort()) != count($paginationParameters->getOrder())) {
throw new \InvalidArgumentException('Sort and order arrays must be the same length');
}
$sort = $paginationParameters->getSort();
$order = $paginationParameters->getOrder();
}
foreach ($sort as $key => $oneSortField) {
if (!strstr($oneSortField, '.')) {
$alias = $queryBuilder->getRootAlias() . '.';
} else {
$alias = '';
}
$queryBuilder->addOrderBy($alias . $oneSortField, $order[$key]);
}
}
if ($paginationParameters->getFilters() != null) {
foreach ($paginationParameters->getFilters() as $field => $value) {
if ($value == '' || $queryBuilder->getParameter($field) != null) {
continue;
}
if (!strstr($field, '.')) {
$entityField = $queryBuilder->getRootAlias() . '.' . $field;
} else {
$entityField = $field;
}
if (is_array($value)) {
$queryBuilder->andWhere($entityField . ' IN (\'' . implode("', '", $value) . '\')');
} else {
$queryBuilder->andWhere($entityField . ' = :' . str_replace('.', '_', $field))->setParameter(str_replace('.', '_', $field), $value);
}
}
}
if ($this->usedPaginator == null) {
$paginatorTool = new \Doctrine\ORM\Tools\Pagination\Paginator($queryBuilder);
} else {
$paginatorTool = $this->usedPaginator;
}
$paginator = new Paginator(new Adapter\DoctrinePaginator($paginatorTool));
$paginator->setItemCountPerPage($paginationParameters->getItemCountPerPage());
$paginator->setCurrentPageNumber($paginationParameters->getCurrentPageNumber());
if ($paginationParameters->getCache() != null) {
$paginator->setCache($paginationParameters->getCache());
}
if ($resultKey !== null) {
foreach ($paginator as &$itemElement) {
$itemElement = $itemElement[$resultKey];
}
}
return $paginator;
}
示例6: getParameter
/**
* Gets a (previously set) query parameter of the query being constructed.
*
* @param mixed $key The key (index or name) of the bound parameter.
*
* @return mixed The value of the bound parameter.
*/
public function getParameter($key)
{
return $this->queryBuilder->getParameter($key);
}