| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of Webcook common bundle. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * See LICENSE file in the root of the bundle. Webcook | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Webcook\Cms\CoreBundle\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Webcook\Cms\CoreBundle\Base\BaseRestController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Webcook\Cms\CoreBundle\Entity\Page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Webcook\Cms\CoreBundle\Entity\PageSection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Webcook\Cms\CoreBundle\Form\Type\PageType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Webcook\Cms\CoreBundle\Form\Type\PageSectionType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Nelmio\ApiDocBundle\Annotation\ApiDoc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Webcook\Cms\SecurityBundle\Authorization\Voter\WebcookCmsVoter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use FOS\RestBundle\Controller\Annotations\Get; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use FOS\RestBundle\Controller\Annotations\Post; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use FOS\RestBundle\Controller\Annotations\Put; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use FOS\RestBundle\Controller\Annotations\Delete; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Doctrine\DBAL\LockMode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * Page controller. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | class PageController extends BaseRestController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * Update page section order. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param int $id Id of the desired Page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |     public function orderAction($id) | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         $order = $this->getPutParameters('order'); | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |         $pageSection = $this->getEntityManager()->getRepository('Webcook\Cms\CoreBundle\Entity\PageSection')->find($id); | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |         if (!is_null($pageSection)) { | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |             if (!is_numeric($order)) { | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |                 throw new BadRequestHttpException('Order is not numeric.'); | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |             $pageSection->setOrder($order); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |             $this->getEntityManager()->flush(); | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         } else { | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |             throw new NotFoundHttpException('Page section does not exist.'); | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |         return $pageSection; | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 55 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |  |