| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Sonata Project package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Thomas Rabaix <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Sonata\NewsBundle\Action; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Sonata\ClassificationBundle\Model\CollectionManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Sonata\NewsBundle\Model\BlogInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Sonata\NewsBundle\Model\PostManagerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\HttpFoundation\Response; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Symfony\Component\Translation\TranslatorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | final class CollectionPostArchiveAction extends AbstractPostArchiveAction | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var CollectionManagerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private $collectionManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         BlogInterface $blog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         PostManagerInterface $postManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         TranslatorInterface $translator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         CollectionManagerInterface $collectionManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         parent::__construct($blog, $postManager, $translator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->collectionManager = $collectionManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param string $collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @return Response | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |     public function __invoke(Request $request, $collection) | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |         $collection = $this->collectionManager->findOneBy([ | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             'slug' => $collection, | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |             'enabled' => true, | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |         ]); | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         if (!$collection || !$collection->getEnabled()) { | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |             throw new NotFoundHttpException('Unable to find the collection'); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         if ($seoPage = $this->getSeoPage()) { | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |             $seoPage | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |                 ->setTitle($this->trans('archive_collection.meta_title', [ | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |                     '%title%' => $this->getBlog()->getTitle(), | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |                     '%collection%' => $collection->getName(), | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |                 ])) | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |                 ->addMeta('property', 'og:title', $this->trans('archive_collection.meta_title', [ | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |                     '%title%' => $this->getBlog()->getTitle(), | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |                     '%collection%' => $collection->getName(), | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |                 ])) | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |                 ->addMeta('name', 'description', $this->trans('archive_collection.meta_description', [ | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |                     '%title%' => $this->getBlog()->getTitle(), | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |                     '%collection%' => $collection->getName(), | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |                     '%description%' => $collection->getDescription(), | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |                 ])) | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |                 ->addMeta('property', 'og:description', $this->trans('archive_collection.meta_description', [ | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |                     '%title%' => $this->getBlog()->getTitle(), | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |                     '%collection%' => $collection->getName(), | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |                     '%description%' => $collection->getDescription(), | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |                 ])); | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |         return $this->renderArchive($request, ['collection' => $collection], ['collection' => $collection]); | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  |