本文整理汇总了PHP中Doctrine\ORM\Query类的典型用法代码示例。如果您正苦于以下问题:PHP Query类的具体用法?PHP Query怎么用?PHP Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rewind
/**
* {@inheritdoc}
*/
public function rewind()
{
if (!$this->iterableResult) {
$this->iterableResult = $this->query->iterate(array(), Query::HYDRATE_ARRAY);
}
$this->iterableResult->rewind();
}
示例2: getSlice
/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
$query = clone $this->query;
$query->setParameters($this->query->getParameters());
$query->setFirstResult($offset)->setMaxResults($length);
return $query->getQuery()->getResult();
}
示例3: __construct
/**
* Constructor.
*
* Stores various parameters that are otherwise unavailable
* because Doctrine\ORM\Query\SqlWalker keeps everything private without
* accessors.
*
* @param \Doctrine\ORM\Query $query
* @param \Doctrine\ORM\Query\ParserResult $parserResult
* @param array $queryComponents
*/
public function __construct($query, $parserResult, array $queryComponents)
{
$this->platform = $query->getEntityManager()->getConnection()->getDatabasePlatform();
$this->rsm = $parserResult->getResultSetMapping();
$this->queryComponents = $queryComponents;
parent::__construct($query, $parserResult, $queryComponents);
}
示例4: addHint
/**
* Adds a hint to a query object
*
* @param Query $query
* @param string $name
* @param mixed $value
*
* @return bool TRUE if the hint is added; otherwise, FALSE
*/
public function addHint(Query $query, $name, $value)
{
$result = false;
if ($name === Query::HINT_CUSTOM_TREE_WALKERS) {
$walkers = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);
if (false === $walkers) {
$walkers = [$value];
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $walkers);
$result = true;
} elseif (!in_array($value, $walkers, true)) {
$walkers[] = $value;
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $walkers);
$result = true;
}
} elseif ($name === Query::HINT_CUSTOM_OUTPUT_WALKER) {
if ($query->getHint($name) !== $value) {
$query->setHint($name, $value);
$result = true;
}
} else {
$query->setHint($name, $value);
$result = true;
}
return $result;
}
示例5: apply
/**
* Apply ACL filter
*
* @param QueryBuilder | Query $query
* @param array $permissions
* @param string | UserInterface $identity
* @param string $alias
* @param array|Query|QueryBuilder $extraCriteria
*
* @return Query
*/
public function apply($query, array $permissions = array('VIEW'), $identity = null, $alias = null, $extraCriteria = false)
{
if (null === $identity) {
$token = $this->securityContext->getToken();
$identity = $token->getUser();
}
$query->setHint(static::HINT_ACL_EXTRA_CRITERIA, $this->getExtraCriteria($extraCriteria));
if ($query instanceof QueryBuilder) {
$query = $this->cloneQuery($query->getQuery());
} elseif ($query instanceof Query) {
$query = $this->cloneQuery($query);
} else {
throw new \Exception();
}
$maskBuilder = new MaskBuilder();
foreach ($permissions as $permission) {
$mask = constant(get_class($maskBuilder) . '::MASK_' . strtoupper($permission));
$maskBuilder->add($mask);
}
$entity = $this->getEntityFromAlias($query, $alias);
$metadata = $entity['metadata'];
$alias = $entity['alias'];
$table = $metadata->getQuotedTableName($this->em->getConnection()->getDatabasePlatform());
$aclQuery = $this->getExtraQuery($this->getClasses($metadata), $this->getIdentifiers($identity), $maskBuilder->get());
$hintAclMetadata = false !== $query->getHint('acl.metadata') ? $query->getHint('acl.metadata') : array();
$hintAclMetadata[] = array('query' => $aclQuery, 'table' => $table, 'alias' => $alias);
$query->setHint('acl.metadata', $hintAclMetadata);
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, $this->aclWalker);
return $query;
}
示例6: processParameterMappings
/**
* @param Query $query
* @param array $paramMappings
* @return array
* @throws \Doctrine\ORM\Query\QueryException
*/
protected function processParameterMappings(Query $query, $paramMappings)
{
$sqlParams = array();
$types = array();
/** @var Parameter $parameter */
foreach ($query->getParameters() as $parameter) {
$key = $parameter->getName();
if (!isset($paramMappings[$key])) {
throw QueryException::unknownParameter($key);
}
$value = $query->processParameterValue($parameter->getValue());
$type = $parameter->getValue() === $value ? $parameter->getType() : Query\ParameterTypeInferer::inferType($value);
foreach ($paramMappings[$key] as $position) {
$types[$position] = $type;
}
$sqlPositions = $paramMappings[$key];
$value = array($value);
$countValue = count($value);
for ($i = 0, $l = count($sqlPositions); $i < $l; $i++) {
$sqlParams[$sqlPositions[$i]] = $value[$i % $countValue];
}
}
if (count($sqlParams) != count($types)) {
throw QueryException::parameterTypeMissmatch();
}
if ($sqlParams) {
ksort($sqlParams);
$sqlParams = array_values($sqlParams);
ksort($types);
$types = array_values($types);
}
return array($sqlParams, $types);
}
示例7: getItemCount
/**
* {@inheritDoc}
*
* @api
*/
public function getItemCount()
{
try {
return array_sum(array_map('current', $this->countQuery->getScalarResult()));
} catch (NoResultException $e) {
return 0;
}
}
示例8: applyTranslatorGedmoHints
/**
* @param Query $query
*/
protected function applyTranslatorGedmoHints(Query &$query)
{
if (BELCEBUR_GEDMO_TRANSLATION_LOCALE !== 'BELCEBUR_GEDMO_TRANSLATION_LOCALE') {
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, $this->gedmoWalker);
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, BELCEBUR_GEDMO_TRANSLATION_LOCALE);
$query->setHint(TranslatableListener::HINT_FALLBACK, TRUE);
}
}
示例9: __construct
public function __construct(DoctrineOrmPaginator $paginator)
{
$this->paginator = $paginator;
$this->query = $paginator->getQuery();
$this->firstResult = $this->query->getFirstResult();
$this->maxResults = $this->query->getMaxResults();
$this->totalItems = count($paginator);
}
示例10: processMostSearchedQuery
/**
* @param Query $query
*
* @return array
*/
protected function processMostSearchedQuery(Query $query)
{
$resultQuery = $query->getArrayResult();
$result = [];
foreach ($resultQuery as $answerArray) {
$result[] = ['title' => $answerArray['title'], 'description' => $answerArray['description'], 'uri' => $this->routerInterface->generate('aalto_api_answer_show', ['slug' => $answerArray['slug']])];
}
return $result;
}
示例11: setTranslatableQueryHints
/**
* @param Query $query
* @param string $locale
* @throws \Exception
*/
protected function setTranslatableQueryHints(Query $query, $locale)
{
if (!class_exists('Gedmo\\Translatable\\TranslatableListener')) {
throw new \Exception('"Translatable" extension missing. "stof/doctrine-extensions-bundle" needs to be installed');
}
$query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
$query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_FALLBACK, 1);
}
示例12: addCustomTreeWalker
/**
* Add a custom TreeWalker $walker class name to
* be included in the CustomTreeWalker hint list
* of the given $query
*
* @param Query $query
* @param string $walker
* @return void
*/
public static function addCustomTreeWalker(Query $query, $walker)
{
$customTreeWalkers = $query->getHint(Query::HINT_CUSTOM_TREE_WALKERS);
if ($customTreeWalkers !== false && is_array($customTreeWalkers)) {
$customTreeWalkers = array_merge($customTreeWalkers, array($walker));
} else {
$customTreeWalkers = array($walker);
}
$query->setHint(Query::HINT_CUSTOM_TREE_WALKERS, $customTreeWalkers);
}
示例13: cloneQuery
/**
* Clones a query
* @param Query $query the query to be cloned
* @return \Query the new query
*/
private function cloneQuery($query)
{
/* @var $cloneQuery Query */
$cloneQuery = clone $query;
$cloneQuery->setParameters(clone $query->getParameters());
foreach ($query->getHints() as $name => $value) {
$cloneQuery->setHint($name, $value);
}
return $cloneQuery;
}
示例14: cloneQuery
/**
* @param Query $query
* @return Query
*/
protected static function cloneQuery(Query $query)
{
/* @var $countQuery Query */
$countQuery = clone $query;
$params = $query->getParameters();
foreach ($params as $key => $param) {
$countQuery->setParameter($key, $param);
}
return $countQuery;
}
示例15: setMaxPerPage
/**
* @param int $maxPerPage
*/
public function setMaxPerPage($maxPerPage)
{
if ($maxPerPage > 0) {
$this->maxPerPage = $maxPerPage;
$this->query->setMaxResults($maxPerPage);
} else {
$this->maxPerPage = 0;
$this->query->setMaxResults(Query::INFINITY);
}
$this->calculateFirstResult();
}