mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Add login template variable to get last published items
This commit is contained in:
@@ -50,6 +50,7 @@ class Login implements ControllerProviderInterface
|
||||
public static function getDefaultTemplateVariables(Application $app)
|
||||
{
|
||||
return array(
|
||||
'last_publication_items' => \Feed_Entry_Item::loadLatest($app, 20),
|
||||
'instance_title' => $app['phraseanet.registry']->get('GV_homeTitle'),
|
||||
'has_terms_of_use' => $app->hasTermsOfUse(),
|
||||
'meta_description' => $app['phraseanet.registry']->get('GV_metaDescription'),
|
||||
|
@@ -9,6 +9,8 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Feeds
|
||||
@@ -207,6 +209,73 @@ class Feed_Entry_Item implements Feed_Entry_ItemInterface, cache_cacheableInterf
|
||||
return new self($appbox, $entry, $item_id);
|
||||
}
|
||||
|
||||
public static function loadLatest(Application $app, $nbItems = 20)
|
||||
{
|
||||
$execution = 0;
|
||||
$items = array();
|
||||
|
||||
do {
|
||||
$feeds = $entries = array();
|
||||
|
||||
$sql = 'SELECT en.id AS entry, f.id AS feed
|
||||
FROM feed_entry_elements AS el
|
||||
INNER JOIN feed_entries AS en ON (el.entry_id = en.id)
|
||||
INNER JOIN feeds AS f ON (f.id = en.feed_id)
|
||||
WHERE f.public = 1 AND f.base_id IS null
|
||||
ORDER BY en.updated_on DESC
|
||||
LIMIT ' . ($nbItems * $execution) .','. $nbItems;
|
||||
|
||||
$stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach($rows as $row) {
|
||||
if (!isset($feeds[$row['feed']])) {
|
||||
$feeds[$row['feed']] = new Feed_Adapter($app, $row['feed']);
|
||||
}
|
||||
|
||||
if (!isset($entries[$row['entry']])) {
|
||||
$entries[$row['entry']] = new Feed_Entry_Adapter($app, $feeds[$row['feed']], $row['entry']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($entries as $entry) {
|
||||
foreach ($entry->get_content() as $item) {
|
||||
if (null !== $preview = $item->get_record()->get_subdef('preview')) {
|
||||
if (null !== $permalink = $preview->get_permalink()) {
|
||||
if (!isset($items[$item->get_id()])) {
|
||||
$items[$item->get_id()] = array(
|
||||
'entry' => $entry,
|
||||
'record' => $item->get_record(),
|
||||
'preview' => $preview,
|
||||
'permalink' => $permalink
|
||||
);
|
||||
|
||||
if (count($items) >= $nbItems) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($items) > $nbItems) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($rows) <= $nbItems) {
|
||||
break;
|
||||
}
|
||||
|
||||
$execution++;
|
||||
}
|
||||
while (count($items) < $nbItems);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function get_cache_key($option = null)
|
||||
{
|
||||
return 'feedentryitem_' . $this->get_id() . '_' . ($option ? '_' . $option : '');
|
||||
|
Reference in New Issue
Block a user