| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace AppBundle\Fixture\Cms; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use AppBundle\Entity\CmsBlock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Doctrine\Common\DataFixtures\FixtureInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\Common\Persistence\ObjectManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\DependencyInjection\ContainerAwareInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\DependencyInjection\ContainerInterface; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class LayoutBlocks implements FixtureInterface, OrderedFixtureInterface, ContainerAwareInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     private $container; | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function setContainer(ContainerInterface $container = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->container = $container; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |      * {@inheritDoc} | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function getOrder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         return 0; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     private function resource($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $location = $this->container->get('kernel')->locateResource("@AppBundle/Resources/views/blocks/layout/{$name}.html.twig"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         return file_get_contents($location); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function load(ObjectManager $manager) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $blocks = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             'footer', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         foreach ($blocks as $alias) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             $block = new CmsBlock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             $block->setAlias($alias); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $block->setName(implode(' ', array_map('ucfirst', explode('_', $alias)))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $block->setContent($this->resource($alias)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             $manager->persist($block); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         foreach (['css', 'js'] as $alias) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $block = new CmsBlock(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $block->setAlias($alias); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $block->setName(implode(' ', array_map('ucfirst', explode('_', $alias)))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             $block->setContent("/* cms block for {$alias} */"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $manager->persist($block); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $manager->flush(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |  |