mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
Implement Doctrine feeds instead of Phrasea ones in the /list/ route
This commit is contained in:
@@ -36,8 +36,8 @@ class Publications implements ControllerProviderInterface
|
||||
|
||||
$controllers->get('/list/', function(PhraseaApplication $app) {
|
||||
|
||||
$feeds = \Feed_Collection::load_all(
|
||||
$app, $app['authentication']->getUser()
|
||||
$feeds = $app["EM"]->getRepository("Entities\Feed")->getAllForUser(
|
||||
$app['authentication']->getUser()
|
||||
);
|
||||
|
||||
return $app['twig']
|
||||
|
333
lib/Doctrine/Entities/Feed.php
Normal file
333
lib/Doctrine/Entities/Feed.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
|
||||
namespace Entities;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
/**
|
||||
* Feed
|
||||
*/
|
||||
class Feed
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $public;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $icon_url;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
private $base_id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $created;
|
||||
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
private $updated;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
private $publishers;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
private $entries;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->publishers = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
$this->entries = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set public
|
||||
*
|
||||
* @param boolean $public
|
||||
* @return Feed
|
||||
*/
|
||||
public function setPublic($public)
|
||||
{
|
||||
$this->public = $public;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get public
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getPublic()
|
||||
{
|
||||
return $this->public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set icon_url
|
||||
*
|
||||
* @param string $iconUrl
|
||||
* @return Feed
|
||||
*/
|
||||
public function setIconUrl($iconUrl)
|
||||
{
|
||||
$this->icon_url = $iconUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get icon_url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIconUrl()
|
||||
{
|
||||
return $this->icon_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set base_id
|
||||
*
|
||||
* @param integer $baseId
|
||||
* @return Feed
|
||||
*/
|
||||
public function setBaseId($baseId)
|
||||
{
|
||||
$this->base_id = $baseId;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get base_id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getBaseId()
|
||||
{
|
||||
return $this->base_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title
|
||||
*
|
||||
* @param string $title
|
||||
* @return Feed
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set description
|
||||
*
|
||||
* @param string $description
|
||||
* @return Feed
|
||||
*/
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set created
|
||||
*
|
||||
* @param \DateTime $created
|
||||
* @return Feed
|
||||
*/
|
||||
public function setCreated($created)
|
||||
{
|
||||
$this->created = $created;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get created
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getCreated()
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set updated
|
||||
*
|
||||
* @param \DateTime $updated
|
||||
* @return Feed
|
||||
*/
|
||||
public function setUpdated($updated)
|
||||
{
|
||||
$this->updated = $updated;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get updated
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getUpdated()
|
||||
{
|
||||
return $this->updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add publishers
|
||||
*
|
||||
* @param \Entities\FeedPublisher $publishers
|
||||
* @return Feed
|
||||
*/
|
||||
public function addPublisher(\Entities\FeedPublisher $publishers)
|
||||
{
|
||||
$this->publishers[] = $publishers;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove publishers
|
||||
*
|
||||
* @param \Entities\FeedPublisher $publishers
|
||||
*/
|
||||
public function removePublisher(\Entities\FeedPublisher $publishers)
|
||||
{
|
||||
$this->publishers->removeElement($publishers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get publishers
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getPublishers()
|
||||
{
|
||||
return $this->publishers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add entries
|
||||
*
|
||||
* @param \Entities\FeedEntry $entries
|
||||
* @return Feed
|
||||
*/
|
||||
public function addEntrie(\Entities\FeedEntry $entries)
|
||||
{
|
||||
$this->entries[] = $entries;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove entries
|
||||
*
|
||||
* @param \Entities\FeedEntry $entries
|
||||
*/
|
||||
public function removeEntrie(\Entities\FeedEntry $entries)
|
||||
{
|
||||
$this->entries->removeElement($entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entries
|
||||
*
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getEntries()
|
||||
{
|
||||
return $this->entries;
|
||||
}
|
||||
|
||||
public function getOwner()
|
||||
{
|
||||
foreach ($this->getPublishers() as $publisher) {
|
||||
if ($publisher->isOwner()) {
|
||||
return $publisher;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function isOwner(\User_Adapter $user)
|
||||
{
|
||||
$owner = $this->getOwner();
|
||||
if ($owner !== null && $user->get_id() === $owner->getId()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getCollection(Application $app)
|
||||
{
|
||||
if ($this->getBaseId() !== null)
|
||||
return \collection::get_from_base_id($app, $this->getBaseId());
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Repositories;
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
@@ -12,4 +13,31 @@ use Doctrine\ORM\EntityRepository;
|
||||
*/
|
||||
class SessionRepository extends EntityRepository
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Application $app
|
||||
* @param User_Adapter $user
|
||||
* @return \Doctrine\Common\Collections\Collection
|
||||
*/
|
||||
public function getAllForUser(\User_Adapter $user)
|
||||
{
|
||||
$base_ids = array_keys($user->ACL()->get_granted_base());
|
||||
|
||||
|
||||
$dql = 'SELECT f FROM Entities\Feed f
|
||||
WHERE f.base_id IS NULL ';
|
||||
|
||||
if (count($base_ids) > 0) {
|
||||
$dql .= ' OR f.base_id
|
||||
IN (' . implode(', ', $base_ids) . ') ';
|
||||
}
|
||||
|
||||
$dql .= ' OR f.public = true
|
||||
ORDER BY f.created DESC';
|
||||
|
||||
$query = $this->_em->createQuery($dql);
|
||||
$feeds = $query->getResult();
|
||||
return $feeds;
|
||||
}
|
||||
}
|
||||
|
@@ -59,35 +59,35 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for feed in feeds.get_feeds %}
|
||||
{% for feed in feeds %}
|
||||
<tr class="{% if loop.index is odd %}odd{% else %}even{% endif %}">
|
||||
<td>
|
||||
<div style="border:1px solid #ccc; width:22px; height:22px; margin:2px;">
|
||||
<a href="{{ path('admin_feeds_feed', { 'id' : feed.get_id() }) }}">
|
||||
<img src="{{feed.get_icon_url() ~ '?' ~ random(1000) }}" id="pub_icon" style="margin:3px; width:16px; height:16px;"/>
|
||||
<a href="{{ path('admin_feeds_feed', { 'id' : feed.getId() }) }}">
|
||||
<img src="{{feed.getIconUrl() ~ '?' ~ random(1000) }}" id="pub_icon" style="margin:3px; width:16px; height:16px;"/>
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
<td valign="center" align="left">
|
||||
<a href="{{ path('admin_feeds_feed', { 'id' : feed.get_id() }) }}" style="display:block;">{{ feed.get_title() }}</a>
|
||||
<a href="{{ path('admin_feeds_feed', { 'id' : feed.getId() }) }}" style="display:block;">{{ feed.getTitle() }}</a>
|
||||
</td>
|
||||
<td style="text-align: center;">
|
||||
{{ app['date-formatter'].getDate(feed.get_created_on()) }}
|
||||
{{ app['date-formatter'].getDate(feed.getCreated()) }}
|
||||
</td>
|
||||
<td valign="center" align="center">
|
||||
{% if feed.get_collection() != null %}
|
||||
{{ feed.get_collection().get_databox().get_label(app['locale.I18n']) }} /
|
||||
{{ feed.get_collection().get_name() }}
|
||||
{% if feed.getCollection() != null %}
|
||||
{{ feed.getCollection().get_databox().get_label(app['locale.I18n']) }} /
|
||||
{{ feed.getCollection().get_name() }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td valign="center" align="center">
|
||||
{% if feed.is_public() %}
|
||||
{% if feed.getPublic() %}
|
||||
<img src="/skins/icons/ligth-on.png" title="{% trans 'This feed is public' %}"/>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td valign="center" align="center">
|
||||
{% if feed.is_owner(app['authentication'].getUser()) %}
|
||||
<form class="no-ajax form_publication" action="{{ path('admin_feeds_feed_delete', { 'id' : feed.get_id() }) }}" method="post" style="margin:0;">
|
||||
{% if feed.isOwner(app['authentication'].getUser()) %}
|
||||
<form class="no-ajax form_publication" action="{{ path('admin_feeds_feed_delete', { 'id' : feed.getId() }) }}" method="post" style="margin:0;">
|
||||
<button class="feed_remover btn btn-mini">{% trans 'boutton::supprimer' %}</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
|
Reference in New Issue
Block a user