Merge branch '3.8'

Conflicts:
	bower.json
	lib/Alchemy/Phrasea/Controller/Prod/Feed.php
	lib/classes/Feed/Entry/Adapter.php
	lib/classes/Feed/Entry/Item.php
	lib/classes/eventsmanager/notify/feed.php
	tests/classes/Feed/Entry/Feed_Entry_ItemTest.php
This commit is contained in:
Romain Neutron
2013-10-24 14:05:04 +02:00
21 changed files with 375 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
namespace Repositories;
use Alchemy\Phrasea\Application;
use Doctrine\ORM\EntityRepository;
/**
@@ -12,4 +13,74 @@ use Doctrine\ORM\EntityRepository;
*/
class FeedItemRepository extends EntityRepository
{
/**
* Checks if a record is published in a public feed.
*
* @param Application $app
* @param integer $sbas_id
* @param integer $record_id
*
* @return Boolean
*/
public function isRecordInPublicFeed(Application $app, $sbas_id, $record_id)
{
$dql = 'SELECT i
FROM Entities\FeedItem i
JOIN i.entry e
JOIN e.feed f
WHERE i.sbasId = :sbas_id
AND i.recordId = :record_id
AND f.public = true';
$query = $this->_em->createQuery($dql);
$query->setParameters(array('sbas_id' => $sbas_id, 'record_id' => $record_id));
$query->useResultCache(false);
return count($query->getResult()) > 0;
}
/**
* Gets latest items from public feeds.
*
* @param Application $app
* @param integer $nbItems
*
* @return FeedItem[] An array of FeedItem
*/
public function loadLatest(Application $app, $nbItems = 20)
{
$execution = 0;
$items = array();
do {
$dql = 'SELECT i
FROM Entities\FeedItem i
JOIN i.entry e
JOIN e.feed f
WHERE f.public = true ORDER BY i.createdOn DESC';
$query = $this->_em->createQuery($dql);
$query
->setFirstResult((integer) $nbItems * $execution)
->setMaxResults((integer) $nbItems);
$result = $query->getResult();
foreach($result as $item) {
if (null !== $preview = $item->getRecord($app)->get_subdef('preview')) {
if (null !== $permalink = $preview->get_permalink()) {
$items[] = $item;
if (count($items) >= $nbItems) {
break;
}
}
}
}
$execution++;
} while (count($items) < $nbItems && count($result) !== 0);
return $items;
}
}