本文整理汇总了PHP中Doctrine\ORM\Query::getArrayResult方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::getArrayResult方法的具体用法?PHP Query::getArrayResult怎么用?PHP Query::getArrayResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::getArrayResult方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* Get list of values.
*
* @access public
* @param string $sKey
* @param string $sValue
* @return array
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
public function getList($sKey, $sValue)
{
static::$mResult = $this->oQuery->getArrayResult();
$aResults = [];
foreach (static::$mResult as $mResult) {
$aResults[$mResult[$sKey]] = $mResult[$sValue];
}
return $aResults;
}
示例2: 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;
}
示例3: testDqlFunction
/**
* @dataProvider functionsDataProvider
* @param array $functions
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDqlFunction(array $functions, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
foreach ($functions as $function) {
$this->registerDqlFunction($function['type'], $function['name'], $function['className'], $configuration);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例4: paginate
/**
* {@inheritdoc}
*/
public function paginate(Query $query, $results, $offset, $arrayResult = true)
{
if ($results <= 0 || $results > $this->maxResults) {
$results = $this->defaultResults;
}
if ($offset < 0) {
$offset = 0;
}
$paginator = new Paginator($query, false);
$query->setFirstResult($offset)->setMaxResults($results);
if ($arrayResult) {
$result = $query->getArrayResult();
} else {
$result = $query->getResult();
}
return ['recordsTotal' => count($paginator), 'recordsFiltered' => count($paginator), 'data' => $result];
}
示例5: testDateFunction
/**
* @dataProvider functionsDataProvider
* @param string $type
* @param string $functionName
* @param string $functionClass
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDateFunction($type, $functionName, $functionClass, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
switch ($type) {
case 'datetime':
$configuration->addCustomDatetimeFunction($functionName, $functionClass);
break;
case 'numeric':
$configuration->addCustomNumericFunction($functionName, $functionClass);
break;
case 'string':
default:
$configuration->addCustomStringFunction($functionName, $functionClass);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例6: normalize
/**
* @inheritdoc
*/
public function normalize(Query $query, QueryBuilder $queryBuilder)
{
// execute the query
$itemList = $query->getArrayResult();
// normalize result (for request of type $queryBuilder->select("item, bp, item.id * 3 as titi"); )
$normalizedItemList = array();
foreach ($itemList as $item) {
$normalizedItem = array();
foreach ($item as $key => $val) {
// hack : is_array is added according to this issue : https://github.com/kitpages/KitpagesDataGridBundle/issues/18
// can't reproduce this error...
if (is_int($key) && is_array($val)) {
foreach ($val as $newKey => $newVal) {
$normalizedItem[$newKey] = $newVal;
}
} else {
$normalizedItem[$key] = $val;
}
}
$normalizedItemList[] = $normalizedItem;
}
return $normalizedItemList;
}
示例7: testDqlFunction
/**
* @dataProvider functionsDataProvider
* @param array $functions
* @param string $dql
* @param string $sql
* @param string $expectedResult
*/
public function testDqlFunction(array $functions, $dql, $sql, $expectedResult)
{
$configuration = $this->entityManager->getConfiguration();
foreach ($functions as $function) {
$this->registerDqlFunction($function['type'], $function['name'], $function['className'], $configuration);
}
$query = new Query($this->entityManager);
$query->setDQL($dql);
if (is_array($sql)) {
$constraints = array();
foreach ($sql as $sqlVariant) {
$constraints[] = $this->equalTo($sqlVariant);
}
$constraint = new \PHPUnit_Framework_Constraint_Or();
$constraint->setConstraints($constraints);
$this->assertThat($query->getSQL(), $constraint);
} else {
$this->assertEquals($sql, $query->getSQL(), sprintf('Unexpected SQL for "%s"', $dql));
}
$result = $query->getArrayResult();
$this->assertNotEmpty($result);
$this->assertEquals($expectedResult, array_values(array_shift($result)), sprintf('Unexpected result for "%s"', $dql));
}
示例8: formatDate
/**
* @param Query $query
* @param string $dateFormat
*
* @return array
*/
private function formatDate(Query $query, $dateFormat = 'Y-m-d')
{
$payments = [];
foreach ($query->getArrayResult() as $result) {
/** @var \DateTime $created */
$created = $result['created'];
$date = $created->format($dateFormat);
if (!isset($payments[$date])) {
$payments[$date] = 0;
}
$payments[$date] += $result['totalAmount'];
}
return $payments;
}
示例9: getResult
/**
* Processes the result after it was retrieved. In the default configuration, it returns an array result, or
* if no query fields are specified, it tries to serialize all objects.
*/
protected function getResult(Query $query)
{
if (count($this->getQueryFields()) == 0) {
$aSerializedResult = array();
foreach ($query->getResult() as $result) {
$aSerializedResult[] = $result->serialize();
}
return $aSerializedResult;
} else {
return $query->getArrayResult();
}
}
示例10: getFlatTreeByQuery
public function getFlatTreeByQuery(AbstractTreeRepository $repository, \Doctrine\ORM\Query $query)
{
return $repository->buildTreeArray($query->getArrayResult());
}
示例11: doQueryResult
public static function doQueryResult(\Doctrine\ORM\Query $query, $resultType)
{
switch ($resultType) {
case ResultType::ArrayType:
return $query->getArrayResult();
break;
case ResultType::ObjectType:
return $query->getResult();
break;
case ResultType::SingleObjectType:
return $query->getSingleResult();
break;
case ResultType::SingleArrayType:
return $query->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
break;
default:
throw new \Exception("Not a valid ResultType.");
}
}