mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Rework FeedAggregate. Issue with embedded entry collection.
PHRAS-542
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
319
lib/Alchemy/Phrasea/Feed/AggregateEntryCollection.php
Normal file
319
lib/Alchemy/Phrasea/Feed/AggregateEntryCollection.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2015 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace Alchemy\Phrasea\Feed;
|
||||
|
||||
use Alchemy\Phrasea\Model\Repositories\FeedEntryRepository;
|
||||
use Closure;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\Common\Collections\Selectable;
|
||||
|
||||
class AggregateEntryCollection implements Collection, Selectable
|
||||
{
|
||||
/** @var FeedEntryRepository */
|
||||
private $repository;
|
||||
/** @var FeedInterface[] */
|
||||
private $feeds;
|
||||
/** @var ArrayCollection|null */
|
||||
private $entries;
|
||||
|
||||
/**
|
||||
* @param FeedEntryRepository $repository
|
||||
* @param FeedInterface[] $feeds
|
||||
*/
|
||||
public function __construct(FeedEntryRepository $repository, $feeds)
|
||||
{
|
||||
$this->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);
|
||||
}
|
||||
}
|
@@ -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.
|
||||
|
@@ -254,19 +254,13 @@ 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner of the feed.
|
||||
*
|
||||
|
@@ -5,7 +5,7 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{% for entry in feeds.getEntries(0, 5) %}
|
||||
{% for entry in feeds.entries.slice(0, 5) %}
|
||||
<div class="boxPubli">
|
||||
<div class="titlePubli">
|
||||
<h2 class="htitlePubli">
|
||||
|
@@ -58,7 +58,7 @@
|
||||
{% set doctype_display = user_setting('doctype_display') %}
|
||||
|
||||
{% set offset_start = ((page - 1) * 5 )%}
|
||||
{% set entries = feed.getEntries(offset_start,5) %}
|
||||
{% set entries = feed.entries.slice(offset_start,5) %}
|
||||
|
||||
{% for entry in entries %}
|
||||
{% block content_item %}
|
||||
|
@@ -272,15 +272,17 @@ class RSSFeedTest extends \PhraseanetWebTestCase
|
||||
$count = 0;
|
||||
$offset_start = 0;
|
||||
$n_entries = 20;
|
||||
$entries = $feed->getEntries($offset_start, $n_entries);
|
||||
$entries = $feed->getEntries()->slice($offset_start, $n_entries);
|
||||
|
||||
foreach ($list_entries as $node) {
|
||||
if (sizeof($entries) == 0) {
|
||||
$offset_start = ($offset_start++) * $n_entries;
|
||||
$entries = $feed->getEntries($offset_start, $n_entries);
|
||||
if (sizeof($entries) == 0) //no more
|
||||
$offset_start += $n_entries;
|
||||
$entries = $feed->getEntries()->slice($offset_start, $n_entries);
|
||||
if (sizeof($entries) == 0) {
|
||||
//no more
|
||||
break;
|
||||
}
|
||||
}
|
||||
$feed_entry = array_shift($entries);
|
||||
switch ($node->nodeName) {
|
||||
case 'title':
|
||||
@@ -567,12 +569,12 @@ class RSSFeedTest extends \PhraseanetWebTestCase
|
||||
$count = 0;
|
||||
$offset_start = 0;
|
||||
$n_entries = 20;
|
||||
$entries = $feed->getEntries($offset_start, $n_entries);
|
||||
$entries = $feed->getEntries()->slice($offset_start, $n_entries);
|
||||
|
||||
foreach ($entries_item as $entry) {
|
||||
if (sizeof($entries) == 0) {
|
||||
$offset_start = ($offset_start++) * $n_entries;
|
||||
$entries = $feed->getEntries($offset_start, $n_entries);
|
||||
$offset_start += $n_entries;
|
||||
$entries = $feed->getEntries()->slice($offset_start, $n_entries);
|
||||
if (sizeof($entries) == 0) //no more
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user