diff --git a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php index 14b0300d81..95faa2996e 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V1Controller.php @@ -1836,7 +1836,7 @@ class V1Controller extends Controller { return array_map(function ($entry) use ($request) { return $this->listPublicationEntry($request, $entry); - }, iterator_to_array($feed->getEntries($offset_start, $how_many))); + }, $feed->getEntries()->slice($offset_start, $how_many)); } /** diff --git a/lib/Alchemy/Phrasea/Feed/Aggregate.php b/lib/Alchemy/Phrasea/Feed/Aggregate.php index c58f3de5bf..cc68b94277 100644 --- a/lib/Alchemy/Phrasea/Feed/Aggregate.php +++ b/lib/Alchemy/Phrasea/Feed/Aggregate.php @@ -109,17 +109,11 @@ class Aggregate implements FeedInterface /** * {@inheritdoc} */ - public function getEntries($offset_start = null, $how_many = null) + public function getEntries() { - if ($this->feeds->isEmpty()) { - return new ArrayCollection(); - } - - $feedIds = $this->feeds->getKeys(); - /** @var FeedEntryRepository $feedEntryRepository */ $feedEntryRepository = $this->em->getRepository('Phraseanet:FeedEntry'); - return new ArrayCollection($feedEntryRepository->findByFeeds($feedIds, $offset_start, $how_many)); + return new AggregateEntryCollection($feedEntryRepository, $this->feeds); } /** diff --git a/lib/Alchemy/Phrasea/Feed/AggregateEntryCollection.php b/lib/Alchemy/Phrasea/Feed/AggregateEntryCollection.php new file mode 100644 index 0000000000..600d4fd1af --- /dev/null +++ b/lib/Alchemy/Phrasea/Feed/AggregateEntryCollection.php @@ -0,0 +1,319 @@ +repository = $repository; + if ($feeds instanceof \Traversable) { + $feeds = iterator_to_array($feeds); + } + $this->feeds = $feeds; + } + + public function slice($offset, $length = null) + { + return $this->repository->findByFeeds($this->feeds, $offset, $length); + } + + private function __load___() + { + $this->entries = new ArrayCollection($this->repository->findByFeeds($this->feeds)); + } + + public function count() + { + if (null === $this->entries) { + return $this->repository->countByFeeds($this->feeds); + } + + return $this->entries->count(); + } + + public function toArray() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->toArray(); + } + + public function first() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->first(); + } + + public function last() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->last(); + } + + public function key() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->key(); + } + + public function next() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->next(); + } + + public function current() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->current(); + } + + public function remove($key) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->remove($key); + } + + public function removeElement($element) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->removeElement($element); + } + + public function offsetExists($offset) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->offsetExists($offset); + } + + public function offsetGet($offset) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->offsetGet($offset); + } + + public function offsetSet($offset, $value) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->offsetSet($offset, $value); + } + + public function offsetUnset($offset) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->offsetUnset($offset); + } + + public function containsKey($key) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->containsKey($key); + } + + public function contains($element) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->contains($element); + } + + public function exists(Closure $p) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->exists($p); + } + + public function indexOf($element) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->indexOf($element); + } + + public function get($key) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->get($key); + } + + public function getKeys() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->getKeys(); + } + public function getValues() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->getValues(); + } + + public function set($key, $value) + { + if (null === $this->entries) { + $this->__load___(); + } + + $this->entries->set($key, $value); + } + + public function add($value) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->add($value); + } + + public function isEmpty() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->isEmpty(); + } + + public function getIterator() + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->getIterator(); + } + + public function map(Closure $func) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->map($func); + } + + public function filter(Closure $p) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->filter($p); + } + + public function forAll(Closure $p) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->forAll($p); + } + + public function partition(Closure $p) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->partition($p); + } + + public function clear() + { + if (null === $this->entries) { + $this->__load___(); + } + + $this->entries->clear(); + } + + public function matching(Criteria $criteria) + { + if (null === $this->entries) { + $this->__load___(); + } + + return $this->entries->matching($criteria); + } +} diff --git a/lib/Alchemy/Phrasea/Feed/FeedInterface.php b/lib/Alchemy/Phrasea/Feed/FeedInterface.php index d2e4d56801..16175d4d12 100644 --- a/lib/Alchemy/Phrasea/Feed/FeedInterface.php +++ b/lib/Alchemy/Phrasea/Feed/FeedInterface.php @@ -33,12 +33,9 @@ interface FeedInterface /** * Returns a collection of FeedEntry. * - * @param integer $offset_start - * @param integer $how_many - * * @return FeedEntry[]|Collection */ - public function getEntries($offset_start = 0, $how_many = null); + public function getEntries(); /** * Returns an UTF-8 subtitle for the feed. diff --git a/lib/Alchemy/Phrasea/Model/Entities/Feed.php b/lib/Alchemy/Phrasea/Model/Entities/Feed.php index 3bc15dfdea..e3cdd9a62c 100644 --- a/lib/Alchemy/Phrasea/Model/Entities/Feed.php +++ b/lib/Alchemy/Phrasea/Model/Entities/Feed.php @@ -254,17 +254,11 @@ class Feed implements FeedInterface /** * Get entries * - * @param int $offset_start - * @param int $how_many * @return FeedEntry[]|Collection */ - public function getEntries($offset_start = 0, $how_many = null) + public function getEntries() { - if (null === $how_many) { - return $this->entries; - } - - return $this->entries->slice($offset_start, $how_many); + return $this->entries; } /** diff --git a/templates/web/client/home_inter_pub_basket.html.twig b/templates/web/client/home_inter_pub_basket.html.twig index f2f32a384e..ac57eabc34 100644 --- a/templates/web/client/home_inter_pub_basket.html.twig +++ b/templates/web/client/home_inter_pub_basket.html.twig @@ -5,7 +5,7 @@