/** * 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; }
/** * @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; }
/** * @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)); }
/** * {@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]; }
/** * @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)); }
/** * @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; }
/** * @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)); }
/** * @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; }
/** * 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(); } }
public function getFlatTreeByQuery(AbstractTreeRepository $repository, \Doctrine\ORM\Query $query) { return $repository->buildTreeArray($query->getArrayResult()); }
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."); } }