From b02cf14d8951e7e1eafb68df80bb6b96370b9f54 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Fri, 21 Sep 2012 15:07:54 +0200 Subject: [PATCH] Update Feeds --- lib/classes/Feed/Adapter.class.php | 106 ++++++++++-------- lib/classes/Feed/Aggregate.class.php | 29 +++-- lib/classes/Feed/Collection.class.php | 40 +++---- lib/classes/Feed/Entry/Adapter.class.php | 63 ++++++----- lib/classes/Feed/Entry/Interface.class.php | 8 +- lib/classes/Feed/Publisher/Adapter.class.php | 42 +++---- .../Feed/Publisher/Interface.class.php | 6 +- lib/classes/Feed/Token.class.php | 14 ++- lib/classes/Feed/TokenAggregate.class.php | 17 +-- 9 files changed, 173 insertions(+), 152 deletions(-) diff --git a/lib/classes/Feed/Adapter.class.php b/lib/classes/Feed/Adapter.class.php index d210684e7d..a6e86fe081 100644 --- a/lib/classes/Feed/Adapter.class.php +++ b/lib/classes/Feed/Adapter.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -63,9 +65,9 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea * @param int $id * @return Feed_Adapter */ - public function __construct(appbox &$appbox, $id) + public function __construct(Application $app, $id) { - $this->appbox = $appbox; + $this->app = $app; $this->id = (int) $id; $this->load(); @@ -80,7 +82,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $this->title = $datas['title']; $this->subtitle = $datas['subtitle']; - $this->collection = $datas['base_id'] ? collection::get_from_base_id($datas['base_id']) : null; + $this->collection = $datas['base_id'] ? collection::get_from_base_id($this->app, $datas['base_id']) : null; $this->created_on = $datas['created_on']; $this->updated_on = $datas['updated_on']; $this->public = $datas['public']; @@ -92,21 +94,21 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'SELECT id, title, subtitle, created_on, updated_on, base_id, public FROM feeds WHERE id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_id' => $this->id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); - if ( ! $row) + if (!$row) throw new Exception_FeedNotFound (); $this->title = $row['title']; $this->subtitle = $row['subtitle']; - if ( ! is_null($row['base_id'])) - $this->collection = collection::get_from_base_id($row['base_id']); + if (!is_null($row['base_id'])) + $this->collection = collection::get_from_base_id($this->app, $row['base_id']); $this->created_on = new DateTime($row['created_on']); $this->updated_on = new DateTime($row['updated_on']); - $this->public = ! ! $row['public']; + $this->public = !!$row['public']; $base_id = $this->collection instanceof collection ? $this->collection->get_base_id() : null; @@ -136,7 +138,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $url = '/skins/icons/rss32.gif'; - $file = $this->appbox->get_registry()->get('GV_RootPath') + $file = $this->app['phraseanet.appbox']->get_registry()->get('GV_RootPath') . 'www/custom/feed_' . $this->get_id() . '.jpg'; if (file_exists($file)) { @@ -155,11 +157,11 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea */ public function set_icon($file) { - if ( ! file_exists($file)) { + if (!file_exists($file)) { throw new \Alchemy\Phrasea\Exception\InvalidArgumentException('File does not exists'); } - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; $config_file = $registry->get('GV_RootPath') . 'config/feed_' . $this->get_id() . '.jpg'; $www_file = $registry->get('GV_RootPath') . 'www/custom/feed_' . $this->get_id() . '.jpg'; @@ -176,10 +178,10 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'UPDATE feeds SET created_on = :created_on WHERE id = :feed_id'; $params = array( - ':created_on' => $created_on->format(DATE_ISO8601) - , ':feed_id' => $this->get_id() + ':created_on' => $created_on->format(DATE_ISO8601) + , ':feed_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->created_on = $created_on; @@ -190,7 +192,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea public function reset_icon() { - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; $config_file = $registry->get('GV_RootPath') . 'config/feed_' . $this->get_id() . '.jpg'; $www_file = $registry->get('GV_RootPath') @@ -224,6 +226,10 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea { $this->load_publishers(); + if (!$this->owner) { + return false; + } + return $this->owner->get_user()->get_id() === $user->get_id(); } @@ -294,7 +300,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea return $this; } - Feed_Publisher_Adapter::create($this->appbox, $user, $this, false); + Feed_Publisher_Adapter::create($this->app, $user, $this, false); $this->publishers = null; return $this; @@ -312,16 +318,18 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'SELECT id, usr_id, owner FROM feed_publishers WHERE feed_id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_id' => $this->id)); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { - $publisher = new Feed_Publisher_Adapter($this->appbox, $row['id']); + $publisher = new Feed_Publisher_Adapter($this->app, $row['id']); $this->publishers[$row['usr_id']] = $publisher; - if ($publisher->is_owner()) + if ($publisher->is_owner()) { $this->owner = $publisher; + } } return $this->publishers; @@ -350,8 +358,8 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'UPDATE feeds SET base_id = :base_id, updated_on = NOW() WHERE id = :feed_id'; - $params = array(':base_id' => $base_id, ':feed_id' => $this->get_id()); - $stmt = $this->appbox->get_connection()->prepare($sql); + $params = array(':base_id' => $base_id, ':feed_id' => $this->get_id()); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->collection = $collection; @@ -367,7 +375,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea */ public function set_public($boolean) { - $boolean = ! ! $boolean; + $boolean = !!$boolean; $sql = 'UPDATE feeds SET public = :public, updated_on = NOW() WHERE id = :feed_id'; @@ -376,13 +384,13 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea ':feed_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->public = $boolean; $this->delete_data_from_cache(); - $feed_collection = new Feed_Collection($this->appbox, array()); + $feed_collection = new Feed_Collection($this->app, array()); $feed_collection->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC); return $this; @@ -402,8 +410,8 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'UPDATE feeds SET title = :title, updated_on = NOW() WHERE id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':title' => $title, ':feed_id' => $this->get_id())); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt->execute(array(':title' => $title, ':feed_id' => $this->get_id())); $stmt->closeCursor(); $this->title = $title; $this->delete_data_from_cache(); @@ -422,8 +430,8 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'UPDATE feeds SET subtitle = :subtitle, updated_on = NOW() WHERE id = :feed_id'; - $params = array(':subtitle' => $subtitle, ':feed_id' => $this->get_id()); - $stmt = $this->appbox->get_connection()->prepare($sql); + $params = array(':subtitle' => $subtitle, ':feed_id' => $this->get_id()); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->subtitle = $subtitle; @@ -440,19 +448,19 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea * @param string $subtitle * @return Feed_Adapter */ - public static function create(appbox &$appbox, User_Adapter $user, $title, $subtitle) + public static function create(Application $app, User_Adapter $user, $title, $subtitle) { $sql = 'INSERT INTO feeds (id, title, subtitle, created_on, updated_on) VALUES (null, :title, :subtitle, NOW(), NOW())'; - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':title' => $title, ':subtitle' => $subtitle)); $stmt->closeCursor(); - $feed_id = $appbox->get_connection()->lastInsertId(); + $feed_id = $app['phraseanet.appbox']->get_connection()->lastInsertId(); - $feed = new self($appbox, $feed_id); + $feed = new self($app, $feed_id); - Feed_Publisher_Adapter::create($appbox, $user, $feed, true); + Feed_Publisher_Adapter::create($app, $user, $feed, true); return $feed; } @@ -464,9 +472,9 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea * @param int $id * @return Feed_Adapter */ - public static function load_with_user(appbox &$appbox, User_Adapter &$user, $id) + public static function load_with_user(Application $app, User_Adapter &$user, $id) { - $feed = new self($appbox, $id); + $feed = new self($app, $id); $coll = $feed->get_collection(); if ( $feed->is_public() @@ -494,7 +502,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $sql = 'SELECT count(id) as number FROM feed_entries WHERE feed_id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_id' => $this->get_id())); $row = $stmt->fetch(PDO::FETCH_ASSOC); $number = $row ? (int) $row['number'] : 0; @@ -525,18 +533,18 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $publishers->delete(); $sql = 'DELETE FROM feed_tokens WHERE feed_id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_id' => $this->get_id())); $stmt->closeCursor(); $sql = 'DELETE FROM feeds WHERE id = :feed_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_id' => $this->get_id())); $stmt->closeCursor(); $this->delete_data_from_cache(); - $feed_coll = new Feed_Collection($this->appbox, array()); + $feed_coll = new Feed_Collection($this->app, array()); $feed_coll->delete_data_from_cache(Feed_Collection::CACHE_PUBLIC); return; @@ -562,7 +570,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $params = array( ':feed_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -570,7 +578,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea $result = new Feed_Entry_Collection(); foreach ($rs as $row) { - $entry = new Feed_Entry_Adapter($this->appbox, $this, $row['id']); + $entry = new Feed_Entry_Adapter($this->app, $this, $row['id']); $result->add_entry($entry); } @@ -586,7 +594,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea */ public function get_homepage_link(registryInterface $registry, $format, $page = null) { - if ( ! $this->is_public()) { + if (!$this->is_public()) { return null; } @@ -627,7 +635,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea { $cache_key = self::CACHE_USER_TOKEN . '_' . $user->get_id(); try { - if ( ! $renew) { + if (!$renew) { return $this->get_data_from_cache($cache_key); } } catch (Exception $e) { @@ -643,12 +651,12 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea ':feed_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); - if ( ! $row || $renew === true) { + if (!$row || $renew === true) { $token = random::generatePassword(12, random::LETTERS_AND_NUMBERS); $sql = 'REPLACE INTO feed_tokens (id, token, feed_id, usr_id, aggregated) VALUES (null, :token, :feed_id, :usr_id, :aggregated)'; @@ -660,7 +668,7 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea , ':aggregated' => null ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $this->delete_data_from_cache($cache_key); } else { @@ -718,16 +726,16 @@ class Feed_Adapter extends Feed_Abstract implements Feed_Interface, cache_cachea public function get_data_from_cache($option = null) { - return $this->appbox->get_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option)); } public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration); } public function delete_data_from_cache($option = null) { - return $this->appbox->delete_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option)); } } diff --git a/lib/classes/Feed/Aggregate.class.php b/lib/classes/Feed/Aggregate.class.php index 097885c001..5ceecb5a14 100644 --- a/lib/classes/Feed/Aggregate.class.php +++ b/lib/classes/Feed/Aggregate.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -29,13 +31,13 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface * @param array $feeds * @return Feed_Aggregate */ - public function __construct(appbox &$appbox, Array $feeds) + public function __construct(Application $app, Array $feeds) { $this->title = 'AGGREGGATE'; $this->subtitle = 'AGREGGATE SUBTITLE'; $this->created_on = new DateTime(); $this->updated_on = new DateTime(); - $this->appbox = $appbox; + $this->app = $app; $tmp_feeds = array(); @@ -96,16 +98,13 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface ORDER BY id DESC LIMIT ' . $offset_start . ', ' . $how_many; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); foreach ($rs as $row) { - $entry = new Feed_Entry_Adapter( - $this->appbox - , $this->feeds[$row['feed_id']], $row['id'] - ); + $entry = new Feed_Entry_Adapter($this->app, $this->feeds[$row['feed_id']], $row['id']); $result->add_entry($entry); } @@ -126,7 +125,7 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface FROM feed_entries WHERE feed_id IN (' . implode(', ', array_keys($this->feeds)) . ') '; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $number = $row ? (int) $row['number'] : 0; @@ -189,12 +188,12 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface { $sql = 'SELECT token FROM feed_tokens WHERE usr_id = :usr_id AND aggregated = "1"'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':usr_id' => $user->get_id())); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); - if ( ! $row || $renew === true) { + if (!$row || $renew === true) { $token = random::generatePassword(12, random::LETTERS_AND_NUMBERS); $sql = 'REPLACE INTO feed_tokens (id, token, feed_id, usr_id, aggregated) VALUES (null, :token, :feed_id, :usr_id, :aggregated)'; @@ -206,7 +205,7 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface , ':aggregated' => '1' ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); } else { $token = $row['token']; @@ -217,15 +216,15 @@ class Feed_Aggregate extends Feed_Abstract implements Feed_Interface /** * - * @param appbox $appbox + * @param Application $app * @param User_Adapter $user * @return Feed_Aggregate */ - public static function load_with_user(appbox &$appbox, User_Adapter &$user) + public static function load_with_user(Application $app, User_Adapter &$user) { - $feeds = Feed_Collection::load_all($appbox, $user); + $feeds = Feed_Collection::load_all($app, $user); - return new self($appbox, $feeds->get_feeds()); + return new self($app, $feeds->get_feeds()); } /** diff --git a/lib/classes/Feed/Collection.class.php b/lib/classes/Feed/Collection.class.php index 967a0eb1af..6f131d0073 100644 --- a/lib/classes/Feed/Collection.class.php +++ b/lib/classes/Feed/Collection.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -25,33 +27,33 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf /** * - * @var appbox + * @var Application */ - protected $appbox; + protected $app; const CACHE_PUBLIC = 'public'; /** * - * @param appbox $appbox + * @param Application $app * @param array $feeds * @return Feed_Collection */ - public function __construct(appbox $appbox, Array $feeds) + public function __construct(Application $app, Array $feeds) { $this->feeds = $feeds; - $this->appbox = $appbox; + $this->app = $app; return $this; } /** * - * @param appbox $appbox + * @param Application $app * @param User_Adapter $user * @return Feed_Collection */ - public static function load_all(appbox $appbox, User_Adapter $user) + public static function load_all(Application $app, User_Adapter $user) { $base_ids = array_keys($user->ACL()->get_granted_base()); @@ -66,7 +68,7 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf $sql .= ' OR public = "1" ORDER BY created_on DESC'; - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -74,10 +76,10 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf $feeds = array(); foreach ($rs as $row) { - $feeds[] = new Feed_Adapter($appbox, $row['id']); + $feeds[] = new Feed_Adapter($app, $row['id']); } - return new self($appbox, $feeds); + return new self($app, $feeds); } /** @@ -95,23 +97,23 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf */ public function get_aggregate() { - return new Feed_Aggregate($this->appbox, $this->feeds); + return new Feed_Aggregate($this->app, $this->feeds); } /** * - * @param appbox $appbox + * @param Application $app * @return Feed_Collection */ - public static function load_public_feeds(appbox $appbox) + public static function load_public_feeds(Application $app) { - $rs = self::retrieve_public_feed_ids($appbox); + $rs = self::retrieve_public_feed_ids($app['phraseanet.appbox']); $feeds = array(); foreach ($rs as $feed_id) { - $feeds[] = new Feed_Adapter($appbox, $feed_id); + $feeds[] = new Feed_Adapter($app, $feed_id); } - return new self($appbox, $feeds); + return new self($app, $feeds); } protected static function retrieve_public_feed_ids(appbox &$appbox) @@ -148,16 +150,16 @@ class Feed_Collection implements Feed_CollectionInterface, cache_cacheableInterf public function get_data_from_cache($option = null) { - return $this->appbox->get_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option)); } public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration); } public function delete_data_from_cache($option = null) { - return $this->appbox->delete_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option)); } } diff --git a/lib/classes/Feed/Entry/Adapter.class.php b/lib/classes/Feed/Entry/Adapter.class.php index 829d9ef105..404bf91994 100644 --- a/lib/classes/Feed/Entry/Adapter.class.php +++ b/lib/classes/Feed/Entry/Adapter.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -21,7 +23,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa * * @var appbox */ - protected $appbox; + protected $app; /** * @@ -93,14 +95,14 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa /** * - * @param appbox $appbox + * @param Application $app * @param Feed_Adapter $feed * @param int $id * @return Feed_Entry_Adapter */ - public function __construct(appbox &$appbox, Feed_Adapter &$feed, $id) + public function __construct(Application $app, Feed_Adapter &$feed, $id) { - $this->appbox = $appbox; + $this->app = $app; $this->feed = $feed; $this->id = (int) $id; $this->load(); @@ -135,7 +137,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa FROM feed_entries WHERE id = :id '; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':id' => $this->id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -168,7 +170,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa public function get_link() { - $registry = registry::get_instance(); + $registry = $this->app['phraseanet.registry']; $href = sprintf( '%slightbox/feeds/entry/%d/' @@ -225,7 +227,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa { $sql = 'UPDATE feed_entries SET feed_id = :feed_id, updated_on = NOW() WHERE id = :entry_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array( ':feed_id' => $feed->get_id(), ':entry_id' => $this->get_id(), @@ -254,7 +256,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa $sql = 'UPDATE feed_entries SET title = :title, updated_on = NOW() WHERE id = :entry_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':title' => $title, ':entry_id' => $this->get_id())); $stmt->closeCursor(); $this->title = $title; @@ -276,7 +278,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa SET description = :subtitle, updated_on = NOW() WHERE id = :entry_id'; $params = array(':subtitle' => $subtitle, ':entry_id' => $this->get_id()); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->subtitle = $subtitle; @@ -299,7 +301,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa ':author_name' => $author_name, ':entry_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->author_name = $author_name; @@ -322,7 +324,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa ':author_email' => $author_email, ':entry_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->author_email = $author_email; @@ -340,7 +342,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa ':created_on' => $datetime->format(DATE_ISO8601), ':entry_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->created_on = $datetime; @@ -358,7 +360,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa ':updated_on' => $datetime->format(DATE_ISO8601), ':entry_id' => $this->get_id() ); - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); $this->updated_on = $datetime; @@ -374,7 +376,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa public function get_publisher() { if ( ! $this->publisher instanceof Feed_Publisher_Adapter) - $this->publisher = new Feed_Publisher_Adapter($this->appbox, $this->publisher_id); + $this->publisher = new Feed_Publisher_Adapter($this->app, $this->publisher_id); return $this->publisher; } @@ -439,7 +441,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa $items = array(); foreach ($rs as $item_id) { try { - $items[] = new Feed_Entry_Item($this->appbox, $this, $item_id); + $items[] = new Feed_Entry_Item($this->app['phraseanet.appbox'], $this, $item_id); } catch (Exception_NotFound $e) { } @@ -460,7 +462,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa $sql = 'SELECT id FROM feed_entry_elements WHERE entry_id = :entry_id ORDER BY ord ASC'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':entry_id' => $this->get_id())); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -487,7 +489,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa } $sql = 'DELETE FROM feed_entries WHERE id = :entry_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':entry_id' => $this->get_id())); $stmt->closeCursor(); @@ -505,7 +507,7 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa * @param string $author_mail * @return Feed_Entry_Adapter */ - public static function create(appbox &$appbox, Feed_Adapter $feed + public static function create(Application $app, Feed_Adapter $feed , Feed_Publisher_Adapter $publisher, $title, $subtitle, $author_name, $author_mail) { if ( ! $feed->is_publisher($publisher->get_user())) { @@ -532,18 +534,17 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa ':author_email' => trim($author_mail), ); - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $stmt->closeCursor(); - $entry_id = $appbox->get_connection()->lastInsertId(); + $entry_id = $app['phraseanet.appbox']->get_connection()->lastInsertId(); $feed->delete_data_from_cache(); - $entry = new self($appbox, $feed, $entry_id); + $entry = new self($app, $feed, $entry_id); - $Core = \bootstrap::getCore(); - $eventsmanager = $Core['events-manager']; + $eventsmanager = $app['events-manager']; $eventsmanager->trigger('__FEED_ENTRY_CREATE__', array('entry_id' => $entry_id), $entry); return $entry; @@ -551,14 +552,14 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa /** * - * @param appbox $appbox + * @param Application $app * @param type $id * @return Feed_Entry_Adapter */ - public static function load_from_id(appbox $appbox, $id) + public static function load_from_id(Application $app, $id) { $sql = 'SELECT feed_id FROM feed_entries WHERE id = :entry_id'; - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':entry_id' => $id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -566,9 +567,9 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa if ( ! $row) throw new Exception_Feed_EntryNotFound(); - $feed = new Feed_Adapter($appbox, $row['feed_id']); + $feed = new Feed_Adapter($app, $row['feed_id']); - return new self($appbox, $feed, $id); + return new self($app, $feed, $id); } public function get_cache_key($option = null) @@ -578,16 +579,16 @@ class Feed_Entry_Adapter implements Feed_Entry_Interface, cache_cacheableInterfa public function get_data_from_cache($option = null) { - return $this->appbox->get_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option)); } public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration); } public function delete_data_from_cache($option = null) { - return $this->appbox->delete_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option)); } } diff --git a/lib/classes/Feed/Entry/Interface.class.php b/lib/classes/Feed/Entry/Interface.class.php index c25b467ee7..20686e54f7 100644 --- a/lib/classes/Feed/Entry/Interface.class.php +++ b/lib/classes/Feed/Entry/Interface.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -18,7 +20,7 @@ interface Feed_Entry_Interface { - public function __construct(appbox &$appbox, Feed_Adapter &$feed, $id); + public function __construct(Application $app, Feed_Adapter &$feed, $id); public function get_feed(); @@ -50,8 +52,8 @@ interface Feed_Entry_Interface public function delete(); - public static function create(appbox &$appbox, Feed_Adapter $feed + public static function create(Application $app, Feed_Adapter $feed , Feed_Publisher_Adapter $publisher, $title, $subtitle, $author_name, $author_mail); - public static function load_from_id(appbox $appbox, $id); + public static function load_from_id(Application $app, $id); } diff --git a/lib/classes/Feed/Publisher/Adapter.class.php b/lib/classes/Feed/Publisher/Adapter.class.php index ef4590ab2d..f1915b9f27 100644 --- a/lib/classes/Feed/Publisher/Adapter.class.php +++ b/lib/classes/Feed/Publisher/Adapter.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -19,9 +21,9 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl { /** * - * @var appbox + * @var Application */ - protected $appbox; + protected $app; /** * @@ -55,13 +57,13 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl /** * - * @param appbox $appbox + * @param Application $app * @param int $id * @return Feed_Publisher_Adapter */ - public function __construct(appbox &$appbox, $id) + public function __construct(Application $app, $id) { - $this->appbox = $appbox; + $this->app = $app; $this->id = (int) $id; $this->load(); @@ -77,8 +79,8 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl try { $datas = $this->get_data_from_cache(); - $this->user = User_Adapter::getInstance($datas['usr_id'], $this->appbox); - $this->added_by = User_Adapter::getInstance($datas['added_by_usr_id'], $this->appbox); + $this->user = User_Adapter::getInstance($datas['usr_id'], $this->app); + $this->added_by = User_Adapter::getInstance($datas['added_by_usr_id'], $this->app); $this->created_on = $datas['created_on']; $this->owner = $datas['owner']; @@ -89,7 +91,7 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl $sql = 'SELECT id, usr_id, owner, created_on, added_by FROM feed_publishers WHERE id = :feed_publisher_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_publisher_id' => $this->id)); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -97,10 +99,10 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl if ( ! $row) throw new Exception_Feed_PublisherNotFound(); - $this->user = User_Adapter::getInstance($row['usr_id'], $this->appbox); + $this->user = User_Adapter::getInstance($row['usr_id'], $this->app); $this->owner = ! ! $row['owner']; $this->created_on = new DateTime($row['created_on']); - $this->added_by = User_Adapter::getInstance($row['added_by'], $this->appbox); + $this->added_by = User_Adapter::getInstance($row['added_by'], $this->app); $datas = array( 'usr_id' => $this->user->get_id() @@ -166,7 +168,7 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl public function delete() { $sql = 'DELETE FROM feed_publishers WHERE id = :feed_publisher_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt = $this->app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute(array(':feed_publisher_id' => $this->get_id())); $stmt->closeCursor(); @@ -175,28 +177,28 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl /** * - * @param appbox $appbox + * @param Application $app * @param User_Adapter $user * @param Feed_Adapter $feed * @param boolean $owner * @return Feed_Publisher_Adapter */ - public static function create(appbox &$appbox, User_Adapter &$user, Feed_Adapter &$feed, $owner) + public static function create(Application $app, User_Adapter &$user, Feed_Adapter &$feed, $owner) { $sql = 'INSERT INTO feed_publishers (id, usr_id, feed_id, owner, created_on, added_by) VALUES (null, :usr_id, :feed_id, :owner, NOW(), :added_by)'; - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $params = array( ':usr_id' => $user->get_id() , ':feed_id' => $feed->get_id() , ':owner' => $owner ? '1' : null - , ':added_by' => $owner ? $user->get_id() : $appbox->get_session()->get_usr_id() + , ':added_by' => $owner ? $user->get_id() : $app['phraseanet.user']->get_id() ); $stmt->execute($params); - $id = $appbox->get_connection()->lastInsertId(); + $id = $app['phraseanet.appbox']->get_connection()->lastInsertId(); $stmt->closeCursor(); - return new self($appbox, $id); + return new self($app, $id); } /** @@ -223,16 +225,16 @@ class Feed_Publisher_Adapter implements Feed_Publisher_Interface, cache_cacheabl public function get_data_from_cache($option = null) { - return $this->appbox->get_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->get_data_from_cache($this->get_cache_key($option)); } public function set_data_to_cache($value, $option = null, $duration = 0) { - return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); + return $this->app['phraseanet.appbox']->set_data_to_cache($value, $this->get_cache_key($option), $duration); } public function delete_data_from_cache($option = null) { - return $this->appbox->delete_data_from_cache($this->get_cache_key($option)); + return $this->app['phraseanet.appbox']->delete_data_from_cache($this->get_cache_key($option)); } } diff --git a/lib/classes/Feed/Publisher/Interface.class.php b/lib/classes/Feed/Publisher/Interface.class.php index 27eb8912c9..1d8e23bf02 100644 --- a/lib/classes/Feed/Publisher/Interface.class.php +++ b/lib/classes/Feed/Publisher/Interface.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -18,7 +20,7 @@ interface Feed_Publisher_Interface { - public function __construct(appbox &$appbox, $id); + public function __construct(Application $app, $id); public function get_user(); @@ -32,7 +34,7 @@ interface Feed_Publisher_Interface public function delete(); - public static function create(appbox &$appbox, User_Adapter &$user, Feed_Adapter &$feed, $owner); + public static function create(Application $app, User_Adapter &$user, Feed_Adapter &$feed, $owner); public static function getPublisher(appbox &$appbox, Feed_Adapter &$feed, User_Adapter &$user); } diff --git a/lib/classes/Feed/Token.class.php b/lib/classes/Feed/Token.class.php index f6fa1828a4..eac22eb107 100644 --- a/lib/classes/Feed/Token.class.php +++ b/lib/classes/Feed/Token.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -45,7 +47,7 @@ class Feed_Token * * @var appbox */ - protected $appbox; + protected $app; /** * @@ -54,7 +56,7 @@ class Feed_Token * @param int $feed_id * @return Feed_Token */ - public function __construct(appbox &$appbox, $token, $feed_id) + public function __construct(Application $app, $token, $feed_id) { $sql = 'SELECT feed_id, usr_id FROM feed_tokens WHERE feed_id = :feed_id @@ -65,7 +67,7 @@ class Feed_Token , ':token' => $token ); - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -75,7 +77,7 @@ class Feed_Token $this->feed_id = (int) $row['feed_id']; $this->usr_id = (int) $row['usr_id']; - $this->appbox = $appbox; + $this->app = $app; return $this; } @@ -87,7 +89,7 @@ class Feed_Token public function get_user() { if ( ! $this->user) - $this->user = User_Adapter::getInstance($this->usr_id, $this->appbox); + $this->user = User_Adapter::getInstance($this->usr_id, $this->app); return $this->user; } @@ -99,7 +101,7 @@ class Feed_Token public function get_feed() { if ( ! $this->feed) - $this->feed = Feed_Adapter::load_with_user($this->appbox, $this->get_user(), $this->feed_id); + $this->feed = Feed_Adapter::load_with_user($this->app, $this->get_user(), $this->feed_id); return $this->feed; } diff --git a/lib/classes/Feed/TokenAggregate.class.php b/lib/classes/Feed/TokenAggregate.class.php index 96c860b476..e2ed497fc6 100644 --- a/lib/classes/Feed/TokenAggregate.class.php +++ b/lib/classes/Feed/TokenAggregate.class.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Application; + /** * * @package Feeds @@ -20,11 +22,11 @@ class Feed_TokenAggregate extends Feed_Token /** * - * @param appbox $appbox + * @param Application $app * @param string $token * @return Feed_TokenAggregate */ - public function __construct(appbox &$appbox, $token) + public function __construct(Application $app, $token) { $sql = 'SELECT usr_id FROM feed_tokens @@ -34,7 +36,7 @@ class Feed_TokenAggregate extends Feed_Token ':token' => $token ); - $stmt = $appbox->get_connection()->prepare($sql); + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); $stmt->execute($params); $row = $stmt->fetch(PDO::FETCH_ASSOC); $stmt->closeCursor(); @@ -43,7 +45,7 @@ class Feed_TokenAggregate extends Feed_Token throw new Exception_FeedNotFound($token); $this->usr_id = $row['usr_id']; - $this->appbox = $appbox; + $this->app = $app; return $this; } @@ -54,9 +56,10 @@ class Feed_TokenAggregate extends Feed_Token */ public function get_feed() { - if ( ! $this->feed) - $this->feed = Feed_Aggregate::load_with_user($this->appbox, $this->get_user()); - + if ( ! $this->feed) { + $this->feed = Feed_Aggregate::load_with_user($this->app, $this->get_user()); + } + return $this->feed; } }