Add feed repository as a service

This commit is contained in:
Romain Neutron
2014-02-27 17:10:34 +01:00
parent 20aea6de2a
commit 6aaa9ab38e
7 changed files with 20 additions and 17 deletions

View File

@@ -34,7 +34,7 @@ class Publications implements ControllerProviderInterface
}); });
$controllers->get('/list/', function (PhraseaApplication $app) { $controllers->get('/list/', function (PhraseaApplication $app) {
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser( $feeds = $app['repo.feeds']->getAllForUser(
$app['acl']->get($app['authentication']->getUser()) $app['acl']->get($app['authentication']->getUser())
); );

View File

@@ -34,7 +34,7 @@ class Feed implements ControllerProviderInterface
$app['firewall']->addMandatoryAuthentication($controllers); $app['firewall']->addMandatoryAuthentication($controllers);
$controllers->post('/requestavailable/', function (Application $app, Request $request) { $controllers->post('/requestavailable/', function (Application $app, Request $request) {
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser( $feeds = $app['repo.feeds']->getAllForUser(
$app['acl']->get($app['authentication']->getUser()) $app['acl']->get($app['authentication']->getUser())
); );
$publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']); $publishing = RecordsRequest::fromRequest($app, $request, true, [], ['bas_chupub']);
@@ -43,7 +43,7 @@ class Feed implements ControllerProviderInterface
}); });
$controllers->post('/entry/create/', function (Application $app, Request $request) { $controllers->post('/entry/create/', function (Application $app, Request $request) {
$feed = $app['EM']->getRepository('Phraseanet:Feed')->find($request->request->get('feed_id')); $feed = $app['repo.feeds']->find($request->request->get('feed_id'));
if (null === $feed) { if (null === $feed) {
$app->abort(404, "Feed not found"); $app->abort(404, "Feed not found");
@@ -101,7 +101,7 @@ class Feed implements ControllerProviderInterface
throw new AccessDeniedHttpException(); throw new AccessDeniedHttpException();
} }
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser()));
$datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]); $datas = $app['twig']->render('prod/actions/publish/publish_edit.html.twig', ['entry' => $entry, 'feeds' => $feeds]);
@@ -136,7 +136,7 @@ class Feed implements ControllerProviderInterface
$new_feed_id = $request->request->get('feed_id', $currentFeedId); $new_feed_id = $request->request->get('feed_id', $currentFeedId);
if ($currentFeedId !== (int) $new_feed_id) { if ($currentFeedId !== (int) $new_feed_id) {
$new_feed = $app['EM']->getRepository('Phraseanet:Feed')->find($new_feed_id); $new_feed = $app['repo.feeds']->find($new_feed_id);
if ($new_feed === null) { if ($new_feed === null) {
$app->abort(404, 'Feed not found'); $app->abort(404, 'Feed not found');
@@ -203,7 +203,7 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser()));
$datas = $app['twig']->render('prod/feeds/feeds.html.twig', [ $datas = $app['twig']->render('prod/feeds/feeds.html.twig', [
'feeds' => $feeds, 'feeds' => $feeds,
@@ -218,11 +218,11 @@ class Feed implements ControllerProviderInterface
$page = (int) $request->query->get('page'); $page = (int) $request->query->get('page');
$page = $page > 0 ? $page : 1; $page = $page > 0 ? $page : 1;
$feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); $feed = $app['repo.feeds']->find($id);
if (!$feed->isAccessible($app['authentication']->getUser(), $app)) { if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
$app->abort(404, 'Feed not found'); $app->abort(404, 'Feed not found');
} }
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser()));
$datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]); $datas = $app['twig']->render('prod/feeds/feeds.html.twig', ['feed' => $feed, 'feeds' => $feeds, 'page' => $page]);
@@ -234,7 +234,7 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) { $controllers->get('/subscribe/aggregated/', function (Application $app, Request $request) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser()));
$link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds), $link = $app['feed.aggregate-link-generator']->generate(new Aggregate($app['EM'], $feeds),
$app['authentication']->getUser(), $app['authentication']->getUser(),
@@ -255,7 +255,7 @@ class Feed implements ControllerProviderInterface
$controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) { $controllers->get('/subscribe/{id}/', function (Application $app, Request $request, $id) {
$renew = ($request->query->get('renew') === 'true'); $renew = ($request->query->get('renew') === 'true');
$feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); $feed = $app['repo.feeds']->find($id);
if (!$feed->isAccessible($app['authentication']->getUser(), $app)) { if (!$feed->isAccessible($app['authentication']->getUser(), $app)) {
$app->abort(404, 'Feed not found'); $app->abort(404, 'Feed not found');
} }

View File

@@ -71,7 +71,7 @@ class Root implements ControllerProviderInterface
$cssfile = '000000'; $cssfile = '000000';
} }
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($app['authentication']->getUser())); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($app['authentication']->getUser()));
$aggregate = Aggregate::createFromUser($app, $app['authentication']->getUser()); $aggregate = Aggregate::createFromUser($app, $app['authentication']->getUser());
$thjslist = ""; $thjslist = "";

View File

@@ -739,7 +739,7 @@ class Login implements ControllerProviderInterface
$app->addFlash('error', $app->trans('login::erreur: No available connection - Please contact sys-admin')); $app->addFlash('error', $app->trans('login::erreur: No available connection - Please contact sys-admin'));
} }
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->findBy(['public' => true], ['updatedOn' => 'DESC']); $feeds = $app['repo.feeds']->findBy(['public' => true], ['updatedOn' => 'DESC']);
$form = $app->form(new PhraseaAuthenticationForm()); $form = $app->form(new PhraseaAuthenticationForm());
$form->setData([ $form->setData([

View File

@@ -25,7 +25,7 @@ class RSSFeeds implements ControllerProviderInterface
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->get('/feed/{id}/{format}/', function (Application $app, $id, $format) { $controllers->get('/feed/{id}/{format}/', function (Application $app, $id, $format) {
$feed = $app['EM']->getRepository('Phraseanet:Feed')->find($id); $feed = $app['repo.feeds']->find($id);
if (null === $feed) { if (null === $feed) {
$app->abort(404, 'Feed not found'); $app->abort(404, 'Feed not found');
@@ -66,7 +66,7 @@ class RSSFeeds implements ControllerProviderInterface
$user = $token->getUser(); $user = $token->getUser();
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($user));
$aggregate = new Aggregate($app['EM'], $feeds, $token); $aggregate = new Aggregate($app['EM'], $feeds, $token);

View File

@@ -202,6 +202,9 @@ class ORMServiceProvider implements ServiceProviderInterface
$app['repo.orders'] = $app->share(function (PhraseaApplication $app) { $app['repo.orders'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Order'); return $app['EM']->getRepository('Phraseanet:Order');
}); });
$app['repo.feeds'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Feed');
});
$app['repo.feed-entries'] = $app->share(function (PhraseaApplication $app) { $app['repo.feed-entries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedEntry'); return $app['EM']->getRepository('Phraseanet:FeedEntry');
}); });

View File

@@ -78,7 +78,7 @@ class Aggregate implements FeedInterface
*/ */
public static function createFromUser(Application $app, User $user) public static function createFromUser(Application $app, User $user)
{ {
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->getAllForUser($app['acl']->get($user)); $feeds = $app['repo.feeds']->getAllForUser($app['acl']->get($user));
$token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(['user' => $user]); $token = $app['EM']->getRepository('Phraseanet:AggregateToken')->findOneBy(['user' => $user]);
return new static($app['EM'], $feeds, $token); return new static($app['EM'], $feeds, $token);
@@ -94,7 +94,7 @@ class Aggregate implements FeedInterface
*/ */
public static function create(Application $app, array $feed_ids) public static function create(Application $app, array $feed_ids)
{ {
$feeds = $app['EM']->getRepository('Phraseanet:Feed')->findByIds($feed_ids); $feeds = $app['repo.feeds']->findByIds($feed_ids);
return new static($app, $feeds); return new static($app, $feeds);
} }
@@ -239,6 +239,6 @@ class Aggregate implements FeedInterface
*/ */
public static function getPublic(Application $app) public static function getPublic(Application $app)
{ {
return new static($app['EM'], $app['EM']->getRepository('Phraseanet:Feed')->findBy(['public' => true], ['updatedOn' => 'DESC'])); return new static($app['EM'], $app['repo.feeds']->findBy(['public' => true], ['updatedOn' => 'DESC']));
} }
} }