-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPhotoController.php
72 lines (59 loc) · 2.34 KB
/
PhotoController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace FOQ\AlbumBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOQ\AlbumBundle\Model\AlbumInterface;
use FOQ\AlbumBundle\Document\Photo;
class PhotoController extends ContainerAware
{
public function listByAlbumAction(AlbumInterface $album, $page = 1)
{
/**
* Because subrequests loose the query parameters
*/
$this->container->get('request')->query->set('page', $page);
return $this->getTemplating()->renderResponse('FOQAlbumBundle:Photo:byAlbum.html.twig', array(
'album' => $album,
'photos' => $this->getPhotoProvider()->getAlbumPhotos($album)
));
}
public function showAction($username, $slug, $number)
{
return $this->getTemplating()->renderResponse('FOQAlbumBundle:Photo:show.html.twig', array(
'album' => $this->getAlbumProvider()->getAlbum($username, $slug),
'photo' => $this->getPhotoProvider()->getPhoto($album, $number, true)
));
}
public function deleteAction($username, $slug, $number)
{
$album = $this->getAlbumProvider()->getAlbum($username, $slug);
$this->checkAlbumOwning($album);
$photo = $this->getPhotoProvider()->getPhoto($album, $number);
$this->container->get('foq_album.deleter.photo')->delete($album, $photo);
$this->container->get('foq_album.object_manager')->flush();
return new RedirectResponse($this->container->get('router')->generate('foq_album_album_show', array(
'username' => $username,
'slug' => $slug,
)));
}
protected function getTemplating()
{
return $this->container->get('templating');
}
protected function getAlbumProvider()
{
return $this->container->get('foq_album.provider.album');
}
protected function getPhotoProvider()
{
return $this->container->get('foq_album.provider.photo');
}
protected function checkAlbumOwning(AlbumInterface $album)
{
if ($album->getUser() !== $this->container->get('foq_album.security_helper')->getUser()) {
throw new AccessDeniedException();
}
}
}