| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace AppBundle\Controller\Settings\Divers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use AppBundle\Entity\FamilyLog; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use AppBundle\Form\Type\FamilyLogType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * FamilyLog controller. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @Route("/admin/settings/divers/familylog") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class FamilyLogController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Lists all FamilyLog entities. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @Route("/", name="admin_familylog") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @Method("GET") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @Template() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function indexAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $em = $this->getDoctrine()->getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $entities = $em->getRepository('AppBundle:FamilyLog')->findAll(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             'entities'  => $entities, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * Finds and displays a FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @Route("/{slug}/show", name="admin_familylog_show") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @Method("GET") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @Template() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function showAction(FamilyLog $familylog) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $deleteForm = $this->createDeleteForm($familylog->getId(), 'admin_familylog_delete'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |             'familylog' => $familylog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |             'delete_form' => $deleteForm->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * Displays a form to create a new FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @Route("/new", name="admin_familylog_new") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @Method("GET") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @Template() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function newAction() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $familylog = new FamilyLog(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $form = $this->createForm(new FamilyLogType(), $familylog); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             'familylog' => $familylog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             'form'   => $form->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * Creates a new FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @Route("/create", name="admin_familylog_create") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @Method("POST") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @Template("AppBundle:FamilyLog:new.html.twig") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 79 |  | View Code Duplication |     public function createAction(Request $request) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $familylog = new FamilyLog(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $form = $this->createForm(new FamilyLogType(), $familylog); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         if ($form->handleRequest($request)->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $em = $this->getDoctrine()->getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             $em->persist($familylog); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             $em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             if ($form->get('save')->isClicked()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 $url = $this->redirect($this->generateUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     'admin_familylog_show', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                     array('slug' => $familylog->getSlug()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             } elseif ($form->get('addmore')->isClicked()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |                 $this->addFlash('info', 'gestock.settings.add_ok'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                 $url = $this->redirect($this->generateUrl('admin_familylog_new')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             return $url; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             'familylog' => $familylog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'form'   => $form->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      * Displays a form to edit an existing FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * @Route("/{slug}/edit", name="admin_familylog_edit") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * @Method("GET") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @Template() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 113 |  | View Code Duplication |     public function editAction(FamilyLog $familylog) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $editForm = $this->createForm(new FamilyLogType(), $familylog, array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             'action' => $this->generateUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |                 'admin_familylog_update', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 array('slug' => $familylog->getSlug()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             'method' => 'PUT', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         $deleteForm = $this->createDeleteForm($familylog->getId(), 'admin_familylog_delete'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             'familylog' => $familylog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             'edit_form'   => $editForm->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             'delete_form' => $deleteForm->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * Edits an existing FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |      * @Route("/{slug}/update", name="admin_familylog_update") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |      * @Method("PUT") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @Template("AppBundle:FamilyLog:edit.html.twig") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     public function updateAction(FamilyLog $familylog, Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $editForm = $this->createForm(new FamilyLogType(), $familylog, array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             'action' => $this->generateUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |                 'admin_familylog_update', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                 array('slug' => $familylog->getSlug()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             'method' => 'PUT', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         if ($editForm->handleRequest($request)->isValid()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |             $this->getDoctrine()->getManager()->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |             return $this->redirect($this->generateUrl( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |                 'admin_familylog_edit', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |                 array('slug' => $familylog->getSlug()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $deleteForm = $this->createDeleteForm($familylog->getId(), 'admin_familylog_delete'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             'familylog' => $familylog, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             'edit_form'   => $editForm->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |             'delete_form' => $deleteForm->createView(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * Deletes a FamilyLog entity. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      * @Route("/{id}/delete", name="admin_familylog_delete", requirements={"id"="\d+"}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |      * @Method("DELETE") | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 169 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |     public function deleteAction(FamilyLog $familylog, Request $request) | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |         $form = $this->createDeleteForm($familylog->getId(), 'admin_familylog_delete'); | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |         if ($form->handleRequest($request)->isValid()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |             $em = $this->getDoctrine()->getManager(); | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |             $em->remove($familylog); | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |             $em->flush(); | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 179 |  |  |         return $this->redirect($this->generateUrl('admin_familylog')); | 
            
                                                                        
                            
            
                                    
            
            
                | 180 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |      * Create Delete form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |      * @param integer                       $id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |      * @param string                        $route | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * @return \Symfony\Component\Form\Form | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     protected function createDeleteForm($id, $route) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |         return $this->createFormBuilder(null, array('attr' => array('id' => 'delete'))) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             ->setAction($this->generateUrl($route, array('id' => $id))) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             ->setMethod('DELETE') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             ->getForm() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 197 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 198 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.