[Beeframework-svn] SF.net SVN: beeframework:[295] trunk/framework/Bee
Brought to you by:
b_hartmann,
m_plomer
From: <m_p...@us...> - 2015-03-03 07:12:21
|
Revision: 295 http://sourceforge.net/p/beeframework/code/295 Author: m_plomer Date: 2015-03-03 07:12:13 +0000 (Tue, 03 Mar 2015) Log Message: ----------- Context: TContextAware: made interface method final Persistence: - GenericDaoBase: revamped alias handling - PaginationBase: now implements JsonSerializable interface - DaoBase: phpdoc update Modified Paths: -------------- trunk/framework/Bee/Context/Config/TContextAware.php trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php trunk/framework/Bee/Persistence/PaginationBase.php Modified: trunk/framework/Bee/Context/Config/TContextAware.php =================================================================== --- trunk/framework/Bee/Context/Config/TContextAware.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Context/Config/TContextAware.php 2015-03-03 07:12:13 UTC (rev 295) @@ -17,7 +17,7 @@ /** * @param IContext $context */ - public function setBeeContext(IContext $context) { + public final function setBeeContext(IContext $context) { $this->context = $context; } Modified: trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/Doctrine2/DaoBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -2,7 +2,7 @@ namespace Bee\Persistence\Doctrine2; /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,9 +58,10 @@ } /** + * todo: give this a proper name. This method ONLY applies the text filter (and is only ever intended to do so). All + * todo: other filters are use-case- (or at least entity-) specific. * @param QueryBuilder $queryBuilder * @param IRestrictionHolder $restrictionHolder - * @internal param QueryBuilder $query */ protected final function applyFilterRestrictions(QueryBuilder &$queryBuilder, IRestrictionHolder $restrictionHolder = null) { if (is_null($restrictionHolder)) { Modified: trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php =================================================================== --- trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/Doctrine2/GenericDaoBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -14,355 +14,422 @@ */ abstract class GenericDaoBase extends DaoBase { - const ALIAS_MATCHER = '#^([a-zA-Z0-9_]{2,})\.#'; + /** + * @var callable + */ + private $idRestrictor; - /** - * @var callable - */ - private $idRestrictor; + /** + * @var array + * + * ex: + * e0 => 'e.adresse', + * e1 => 'e.hochschultyp', + * e2 => 'e.adresse.land', + * e3 => 'e.adresse.verwaltungseinheit', + * e4 => 'e.hochschultyp.kategorie', + * e5 => 'e.adresse.land.regionen' + */ + private $aliases; - /** - * @var array - */ - private $aliases; - /** * @var array + * + * ex: + * 'e.adresse' => e0 + * 'e.hochschultyp' => e1 + * 'e.adresse.land', => e2 + * 'e.adresse.verwaltungseinheit' => e3 + * 'e.hochschultyp.kategorie' => e4 + * 'e.adresse.land.regionen' => e5 */ private $reverseAliases; - /** - * @var array - * - * todo: this is only for one-time use during a request. should be ok for MOST cases... - */ - private $addedAliases = array(); + /** + * @var array + */ + private $joins = array(); - /** - * @var array - */ - private $joins = array(); + /** + * @var array + */ + private $restrictions = array(); - /** - * @var array - */ - private $restrictions = array(); + /** + * @var array + */ + private $defaultOrderMapping = array(); - /** - * @var array - */ - private $defaultOrderMapping = array(); - /** * @var array */ private $fieldDisaggregations = array(); - /** - * @param mixed $id - * @throws UnexpectedValueException - * @return mixed - */ - public function getById($id) { - if(!is_callable($this->idRestrictor)) { - $idFields = $this->getIdFieldName(); + /** + * @var array + */ + private $addedAliases = array(); - $expectedDim = count($idFields); - $actualDim = count($id); + /** + * @param mixed $id + * @throws UnexpectedValueException + * @return mixed + */ + public function getById($id) { + if (!is_callable($this->idRestrictor)) { + $idFields = $this->getIdFieldName(); - // unpack single-valued id if necessary - if (is_array($id) && $actualDim === 1) { - $id = $id[0]; - } + $expectedDim = count($idFields); + $actualDim = count($id); - $baseEntityAlias = $this->getEntityAlias(); - if ($expectedDim > 1) { - // composite key - if ($actualDim === 1) { - $id = DaoUtils::explodeScalarId($id, $idFields); - } else if ($actualDim !== $expectedDim) { - throw new UnexpectedValueException('Dimension of given ID (' . count($id) . ') does not match expected dimension (' . count($idFields) . ').'); - } + // unpack single-valued id if necessary + if (is_array($id) && $actualDim === 1) { + $id = $id[0]; + } - // here we can be sure that the dimensions match - both branches above would have thrown otherwise - $whereParts = array(); - array_walk($id, function ($value, $key) use ($baseEntityAlias, &$whereParts) { - $whereParts[] = $baseEntityAlias . '.' . $key . ' = ' . ':' . $key; - }); + $baseEntityAlias = $this->getEntityAlias(); + if ($expectedDim > 1) { + // composite key + if ($actualDim === 1) { + $id = DaoUtils::explodeScalarId($id, $idFields); + } else if ($actualDim !== $expectedDim) { + throw new UnexpectedValueException('Dimension of given ID (' . count($id) . ') does not match expected dimension (' . count($idFields) . ').'); + } - $where = implode(' AND ', $whereParts); - $this->idRestrictor = function(QueryBuilder $qb, $id) use ($where) { - $qb->where($where)->setParameters($id); - }; - } else { - $where = $baseEntityAlias . '.' . $idFields . ' = :id'; - $this->idRestrictor = function(QueryBuilder $qb, $id) use ($where) { - $qb->where($where)->setParameter('id', $id); - }; - } - } + // here we can be sure that the dimensions match - both branches above would have thrown otherwise + $whereParts = array(); + /** @noinspection PhpUnusedParameterInspection */ + array_walk($id, function ($value, $key) use ($baseEntityAlias, &$whereParts) { + $whereParts[] = $baseEntityAlias . '.' . $key . ' = ' . ':' . $key; + }); - $setter = $this->idRestrictor; - $setter($qb = $this->getBaseQuery(), $id); - return $this->getSingleResult($qb); - } + $where = implode(' AND ', $whereParts); + $this->idRestrictor = function (QueryBuilder $qb, $id) use ($where) { + $qb->where($where)->setParameters($id); + }; + } else { + $where = $baseEntityAlias . '.' . $idFields . ' = :id'; + $this->idRestrictor = function (QueryBuilder $qb, $id) use ($where) { + $qb->where($where)->setParameter('id', $id); + }; + } + } - /** - * @param IRestrictionHolder $restrictionHolder - * @param IOrderAndLimitHolder $orderAndLimitHolder - * @param array $defaultOrderMapping - * @return array - */ - public function getList(IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { - return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); - } + $setter = $this->idRestrictor; + $setter($qb = $this->getBaseQuery(), $id); + return $this->getSingleResult($qb); + } /** + * @param IRestrictionHolder $restrictionHolder + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @param array $defaultOrderMapping + * @return array + */ + public function getList(IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null) { + return $this->executeListQuery($this->getBaseQuery(), $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping, null); + } + + /** * @param QueryBuilder $queryBuilder - * @param string $expr - * @return string + * @param IRestrictionHolder $restrictionHolder + * @param IOrderAndLimitHolder $orderAndLimitHolder + * @param array $defaultOrderMapping + * @param null $hydrationMode + * @return array */ - protected function transformAndAddAliasForPathExpression(QueryBuilder $queryBuilder, $expr) { - $tokens = explode('.', $expr); - $currentAlias = $this->getEntityAlias(); - do { - $field = $currentAlias . '.' . array_shift($tokens); - if(array_key_exists($field, $this->reverseAliases)) { - // this is an association, there must be an actual field token left in the array - Assert::isTrue(count($tokens) > 0, 'No more property path tokens - check your listConfiguration for invalid property paths!'); - $currentAlias = $this->reverseAliases[$field]; + public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { + if (!is_null($restrictionHolder)) { + $internalFilterableFields = array(); + if (Strings::hasText($restrictionHolder->getFilterString())) { + $this->disaggregateAndInternalizeFieldList($restrictionHolder->getFilterableFields(), $internalFilterableFields, $queryBuilder); } +// $internalFilters = array(); +// if (count($restrictionHolder->getFilters()) > 0) { +// $this->internalizeFieldValueMapping($restrictionHolder->getFilters(), $internalFilters, $queryBuilder); +// } + $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields); + } - } while(count($tokens) > 0); + if (!is_null($orderAndLimitHolder)) { + if (count($orderAndLimitHolder->getOrderMapping()) > 0) { + $internalMapping = array(); + $this->disaggregateAndInternalizeFieldValueMapping($orderAndLimitHolder->getOrderMapping(), $internalMapping, $queryBuilder); + $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); + } + } - $this->addAliasForExpression($queryBuilder, $field); - return $field; - } + return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); + } /** + * @param array $externalFieldValueMapping + * @param array $internalFieldValueMapping * @param QueryBuilder $queryBuilder - * @param string $expr + * @param string $prefix */ - protected function addAliasForExpression(QueryBuilder $queryBuilder, $expr) { - if(preg_match(self::ALIAS_MATCHER, $expr, $matches)) { - $this->addAlias($queryBuilder, $matches[1]); - } - } + protected final function disaggregateAndInternalizeFieldValueMapping(array $externalFieldValueMapping, array &$internalFieldValueMapping, QueryBuilder $queryBuilder, $prefix = '') { + foreach ($externalFieldValueMapping as $field => $value) { + array_walk($this->getFieldDisaggregation($field, $prefix), function ($field) use (&$internalFieldValueMapping, $queryBuilder, $value) { + $internalFieldValueMapping[$this->internalizeFieldExpression($field, $queryBuilder)] = $value; + }); + } + } - /** - * @param QueryBuilder $queryBuilder - * @param string $alias - */ - protected function addAlias(QueryBuilder $queryBuilder, $alias) { - if(!$this->containsAlias($alias)) { - $this->addedAliases[$alias] = true; - $this->addAliasForExpression($queryBuilder, $this->aliases[$alias]); - $queryBuilder->leftJoin($this->aliases[$alias], $alias); - } - } + /** + * @param array $externalFieldList + * @param array $internalFieldList + * @param QueryBuilder $queryBuilder + * @param string $prefix + */ + protected final function disaggregateAndInternalizeFieldList(array $externalFieldList, array &$internalFieldList, QueryBuilder $queryBuilder, $prefix = '') { + $prefix = $prefix ?: $this->getEntityAlias() . '.'; + foreach ($externalFieldList as $field) { + $internalFieldList = array_merge($internalFieldList, array_map(function ($field) use (&$queryBuilder, $prefix) { + return $this->internalizeFieldExpression($field, $queryBuilder); + }, $this->getFieldDisaggregation($field, $prefix))); + } + } - /** - * @param $alias - * @return boolean - */ - protected function containsAlias($alias) { - // todo: Alias presence could in theory also be detected by examining the query builders DQL parts. Feasibility / performance? - // pros: more thorough and consistent - // cons: more overhead? - return $alias == $this->getEntityAlias() || array_key_exists($alias, $this->addedAliases) || array_key_exists($alias, $this->getJoins()); - } + /** + * @param string $fieldExpr + * @param QueryBuilder $queryBuilder + * @param bool $join + * @return string + */ + protected final function internalizeFieldExpression($fieldExpr, QueryBuilder $queryBuilder, $join = false) { + // ex: $fieldExpr = 'e.hochschultyp.kategorie.promotionsrecht' + $dotPos = strrpos($fieldExpr, '.'); // 24 + $fieldName = substr($fieldExpr, $dotPos + 1); // 'promotionsrecht' + $pathExpr = substr($fieldExpr, 0, $dotPos); // 'e.hochschultyp.kategorie' - public function executeListQuery(QueryBuilder $queryBuilder, IRestrictionHolder $restrictionHolder = null, IOrderAndLimitHolder $orderAndLimitHolder = null, array $defaultOrderMapping = null, $hydrationMode = null) { - // todo: there is no particular reason to do the path-to-alias transformations in every request... - if(!is_null($restrictionHolder)) { - $internalFilterableFields = array(); - if(Strings::hasText($restrictionHolder->getFilterString())) { - foreach($restrictionHolder->getFilterableFields() as $field) { - $internalFilterableFields = array_merge($internalFilterableFields, $this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field))); - } - } - $internalFilters = array(); - if(count($restrictionHolder->getFilters()) > 0) { - foreach($restrictionHolder->getFilters() as $field => $value) { - $internalFilters[$this->transformAndAddAliasForPathExpression($queryBuilder, $field)] = $value; - } - } - $restrictionHolder = new GenericDaoBase_RestrictionWrapper($restrictionHolder, $internalFilterableFields, $internalFilters); - } + if($pathExpr != $this->getEntityAlias()) { + Assert::isTrue(array_key_exists($pathExpr, $this->reverseAliases), 'Unknown path expression "' . $pathExpr . '"'); + $this->internalizePathExpression($pathExpr, $queryBuilder, $join); + $pathExpr = $this->reverseAliases[$pathExpr]; + } - if(!is_null($orderAndLimitHolder)) { - if(count($orderAndLimitHolder->getOrderMapping()) > 0) { - $internalMapping = array(); - foreach($orderAndLimitHolder->getOrderMapping() as $field => $dir) { - $internalMapping = array_merge($internalMapping, array_fill_keys($this->getFieldDisaggregation($this->transformAndAddAliasForPathExpression($queryBuilder, $field)), $dir)); - } + // ex: return e4.promotionsrecht + return $pathExpr . '.' . $fieldName; + } - $orderAndLimitHolder = new GenericDaoBase_OrderAndLimitWrapper($orderAndLimitHolder, $internalMapping); - } - } + /** + * @param string $pathExpr + * @param QueryBuilder $queryBuilder + * @param bool $fetchJoin + * @return string + */ + protected final function internalizePathExpression($pathExpr, QueryBuilder $queryBuilder, $fetchJoin = false) { + // ex (Rc1): $pathExpr = 'e.hochschultyp.kategorie' + // ex (Rc2): $pathExpr = 'e.hochschultyp' + // ex (Rc3): $pathExpr = 'e' - return parent::executeListQuery($queryBuilder, $restrictionHolder, $orderAndLimitHolder, $defaultOrderMapping ?: $this->getDefaultOrderMapping(), $hydrationMode ?: $this->getHydrationMode()); - } + if(($dotPos = strrpos($pathExpr, '.')) !== false) { + $currentAlias = $this->reverseAliases[$pathExpr]; + if(!array_key_exists($currentAlias, $this->addedAliases)) { + + $currentAssociation = substr($pathExpr, $dotPos + 1); + $pathExpr = substr($pathExpr, 0, $dotPos); + + // ex (Rc1): + // $currentAlias = 'e4' + // $currentAssociation = 'kategorie' + // $pathExpr = 'e.hochschultyp' + + // ex (Rc2): + // $currentAlias = 'e1' + // $currentAssociation = 'hochschultyp' + // $pathExpr = 'e' + + $parentAlias = $this->internalizePathExpression($pathExpr, $queryBuilder, $fetchJoin); + + // ex (Rc2): $parentAlias = 'e' + // ex (Rc1): $parentAlias = 'e1' + + $currentAssociation = $parentAlias . '.' . $currentAssociation; + + // ex (Rc2): $currentAssociation = 'e.hochschultyp' + // ex (Rc1): $currentAssociation = 'e1.kategorie' + + $queryBuilder->leftJoin($currentAssociation, $currentAlias); + if($fetchJoin) { + $queryBuilder->addSelect($currentAlias); + } + $this->addedAliases[$currentAlias] = $currentAssociation; + + // ex (Rc2): $this->addedAliases = array('e1' => 'e.hochschultyp') + // ex (Rc1): $this->addedAliases = array('e1' => 'e.hochschultyp', 'e4' => 'e1.kategorie') + } + $pathExpr = $currentAlias; + } + + // ex (Rc3): $pathExpr = 'e' + // ex (Rc2): $pathExpr = 'e1' + // ex (Rc1): $pathExpr = 'e4' + + return $pathExpr; + } + /** * @param null $entity * @return QueryBuilder */ - protected function getBaseQuery($entity = null) { - $baseEntityAlias = $this->getEntityAlias(); + protected function getBaseQuery($entity = null) { + $baseEntityAlias = $this->getEntityAlias(); $entity = $entity ?: $this->getEntity(); // $indexBy = count($this->getIdFieldName()) > 1 ? null : $baseEntityAlias . '.' . $this->getIdFieldName(); // return $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias) // ->from($this->getEntity(), $baseEntityAlias, $indexBy); - $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); - $this->addJoinsToBaseQuery($qb); - $this->addRestrictionsToBaseQuery($qb); - return $qb; - } + $qb = $this->getEntityManager()->createQueryBuilder()->select($baseEntityAlias)->from($entity, $baseEntityAlias, $this->getIndexBy()); + $this->addJoinsToBaseQuery($qb); + $this->addRestrictionsToBaseQuery($qb); + return $qb; + } - /** - * @param QueryBuilder $q - */ - protected function addJoinsToBaseQuery(QueryBuilder $q) { - foreach($this->joins as $alias => $relation) { - $q->addSelect($alias)->leftJoin($relation, $alias); - } - } + /** + * @param QueryBuilder $q + */ + protected function addJoinsToBaseQuery(QueryBuilder $q) { + foreach ($this->joins as $join) { + $this->internalizePathExpression($join, $q, true); + } + } - /** - * @param QueryBuilder $q - */ - protected function addRestrictionsToBaseQuery(QueryBuilder $q) { - foreach($this->restrictions as $restriction) { - $q->andWhere($restriction); - } - } + /** + * @param QueryBuilder $q + */ + protected function addRestrictionsToBaseQuery(QueryBuilder $q) { + foreach ($this->restrictions as $restriction) { + $q->andWhere($restriction); + } + } - /** - * @param QueryBuilder $qb - * @return mixed - */ - protected function getSingleResult(QueryBuilder $qb) { - $q = $this->getQueryFromBuilder($qb); - return $q->getSingleResult($this->getHydrationMode()); - } + /** + * @param QueryBuilder $qb + * @return mixed + */ + protected function getSingleResult(QueryBuilder $qb) { + $q = $this->getQueryFromBuilder($qb); + return $q->getSingleResult($this->getHydrationMode()); + } - /** - * @return null|string - */ - protected function getHydrationMode() { - return null; - } + /** + * @return null|string + */ + protected function getHydrationMode() { + return null; + } - /** - * @return string - */ - protected function getEntityAlias() { - return 'e'; - } + /** + * @return string + */ + protected function getEntityAlias() { + return 'e'; + } - /** - * @return mixed - */ - abstract protected function getIdFieldName(); + /** + * @return mixed + */ + abstract protected function getIdFieldName(); - /** - * @return string - */ - public abstract function getEntity(); + /** + * @return string + */ + public abstract function getEntity(); - /** - * @return null - */ - protected function getIndexBy() { - return null; - } + /** + * @return null + */ + protected function getIndexBy() { + return null; + } /** * @param QueryBuilder $queryBuilder * @param $filters - * @param $categoryName - * @param string $baseAlias - * @param null $property + * @param string $fieldPath */ - protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $categoryName, $baseAlias = 'e', $property = null) { - $property = $property ?: $categoryName; - if (array_key_exists($categoryName, $filters)) { - if(!is_array($catIds = $filters[$categoryName])) { + protected function addCategoryRestrictions(QueryBuilder $queryBuilder, $filters, $fieldPath) { + if (array_key_exists($fieldPath, $filters)) { + if (!is_array($catIds = $filters[$fieldPath])) { $catIds = array_filter(explode(',', $catIds)); } - if(count($catIds) > 0) { - $this->addAlias($queryBuilder, $baseAlias); - $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $baseAlias . '.' . $property . ')', $catIds)); + if (count($catIds) > 0) { + $queryBuilder->andWhere($queryBuilder->expr()->in('IDENTITY(' . $this->internalizeFieldExpression($fieldPath, $queryBuilder) . ')', $catIds)); } } } /** * @param QueryBuilder $queryBuilder - * @param $filters - * @param string $fldName + * @param array $filters + * @param string $fieldExpr + * @param string $filterKey */ - protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fldName) { - if (array_key_exists($fldName, $filters) && $value = $filters[$fldName]) { - $fldName = $this->transformAndAddAliasForPathExpression($queryBuilder, $fldName); - $queryBuilder->andWhere($fldName . ' = :val')->setParameter('val', $value); + protected function addValueRestriction(QueryBuilder $queryBuilder, $filters, $fieldExpr, $filterKey = '') { + $filterKey = $filterKey ?: $fieldExpr; + if (array_key_exists($filterKey, $filters) && $value = $filters[$filterKey]) { + $queryBuilder->andWhere($this->internalizeFieldExpression($fieldExpr, $queryBuilder) . ' = :val')->setParameter('val', $value); } } // ================================================================================================================= - // == GETTERS & SETTERS ============================================================================================ - // ================================================================================================================= + // == GETTERS & SETTERS ============================================================================================ + // ================================================================================================================= - /** - * @return array - */ - public function getAliases() { - return $this->aliases; - } + /** + * @return array + */ + public function getAliases() { + return $this->aliases; + } - /** - * @param array $aliases - */ - public function setAliases(array $aliases) { - $this->aliases = $aliases; - $this->reverseAliases = array_flip($aliases); - } + /** + * @param array $aliases + */ + public function setAliases(array $aliases) { + $this->aliases = array(); + array_walk($aliases, function ($val, $key) { + $this->aliases[is_numeric($key) ? 'e' . $key : $key] = $val; + }); + $this->reverseAliases = array_flip($this->aliases); + } - /** - * @param array $joins - */ - public function setJoins(array $joins) { - $this->joins = $joins; - } + /** + * @param array $joins + */ + public function setJoins(array $joins) { + $this->joins = $joins; + } - /** - * @return array - */ - public function getJoins() { - return $this->joins; - } + /** + * @return array + */ + public function getJoins() { + return $this->joins; + } - /** - * @param array $restrictions - */ - public function setRestrictions(array $restrictions) { - $this->restrictions = $restrictions; - } + /** + * @param array $restrictions + */ + public function setRestrictions(array $restrictions) { + $this->restrictions = $restrictions; + } - /** - * @return array - */ - public function getDefaultOrderMapping() { - return $this->defaultOrderMapping; - } + /** + * @return array + */ + public function getDefaultOrderMapping() { + return $this->defaultOrderMapping; + } - /** - * @param array $defaultOrderMapping - */ - public function setDefaultOrderMapping(array $defaultOrderMapping) { - $this->defaultOrderMapping = $defaultOrderMapping; - } + /** + * @param array $defaultOrderMapping + */ + public function setDefaultOrderMapping(array $defaultOrderMapping) { + $this->defaultOrderMapping = $defaultOrderMapping; + } /** * @return array @@ -380,10 +447,12 @@ /** * @param $aggregateFieldName + * @param string $prefix * @return array */ - public function getFieldDisaggregation($aggregateFieldName) { - if(array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { + protected function getFieldDisaggregation($aggregateFieldName, $prefix = '') { + $aggregateFieldName = ($prefix ?: $this->getEntityAlias() . '.') . $aggregateFieldName; + if (array_key_exists($aggregateFieldName, $this->fieldDisaggregations)) { return $this->fieldDisaggregations[$aggregateFieldName]; } return array($aggregateFieldName); @@ -462,20 +531,19 @@ */ private $internalFilterableFields; - /** - * @var array - */ - private $internalFilters; +// /** +// * @var array +// */ +// private $internalFilters; /** * @param $wrappedRestrictionHolder * @param $internalFilterableFields - * @param $internalFilters */ - function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields, array $internalFilters) { + function __construct(IRestrictionHolder $wrappedRestrictionHolder, array $internalFilterableFields/*, array $internalFilters*/) { $this->wrappedRestrictionHolder = $wrappedRestrictionHolder; $this->internalFilterableFields = $internalFilterableFields; - $this->internalFilters = $internalFilters; +// $this->internalFilters = $internalFilters; } /** @@ -496,6 +564,7 @@ * @return array */ public function getFilters() { - return $this->internalFilters; +// return $this->internalFilters; + return $this->wrappedRestrictionHolder->getFilters(); } } \ No newline at end of file Modified: trunk/framework/Bee/Persistence/PaginationBase.php =================================================================== --- trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-01 17:46:21 UTC (rev 294) +++ trunk/framework/Bee/Persistence/PaginationBase.php 2015-03-03 07:12:13 UTC (rev 295) @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +use JsonSerializable; /** * Class BasicListStateHolder @@ -22,7 +23,7 @@ * Implements the pagination aspect of the IOrderAndLimitHolder and embodies generic logic for * @package Bee\Persistence */ -abstract class PaginationBase implements IOrderAndLimitHolder { +abstract class PaginationBase implements IOrderAndLimitHolder, JsonSerializable { /** * @var int @@ -50,7 +51,7 @@ * @param int $pageSize */ public function setPageSize($pageSize) { - $this->pageSize = $pageSize; + $this->pageSize = intval($pageSize); } /** @@ -71,17 +72,17 @@ * @param $currentPage */ public function setCurrentPage($currentPage) { - $currentPage = $currentPage < 0 ? 0 : $currentPage; - $this->currentPage = $currentPage; + $currentPage = intval($currentPage); + $this->currentPage = $currentPage < 0 ? 0 : $currentPage; } /** * @param int $resultCount */ public function setResultCount($resultCount) { - $this->resultCount = $resultCount; + $this->resultCount = intval($resultCount); if($this->getCurrentPage() >= $this->getPageCount()) { - $this->setCurrentPage($this->getPageCount() - 1); + $this->adjustCurrentPageOnOverflow(); } } @@ -99,4 +100,11 @@ protected function adjustCurrentPageOnOverflow() { $this->setCurrentPage($this->getPageCount() - 1); } + + /** + * @return array + */ + function jsonSerialize() { + return array('pageCount' => $this->getPageCount(), 'pageSize' => $this->getPageSize(), 'currentPage' => $this->getCurrentPage(), 'resultCount' => $this->getResultCount()); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |