public function createAction(Request $request)
    {
        $this->isAllowed('BUSINESS_MANAGE_ROLE');

        $model = new RegistrationRole();
        $form = $this->createCreateForm($model);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            $selectedApps = array();
            foreach ($model->applications as $selectedApp) {
                $selectedApps[] = $selectedApp->getId();
            }

            foreach ($model->rolesByApplication as $app) {
                if (in_array($app->getId(), $selectedApps)) {
                    $permissions = null === $app->getRole()
                        ? array()
                        : $app->getRole()->getPermissions();

                    $role = new Role();
                    $role->setName($model->role->getName());
                    $role->setApplication($app);
                    $role->setPermissions($permissions);
                    $em->persist($role);
                }
            }

            $em->flush();
            $this->get('session')->getFlashBag()->add('success', 'role.flash.created');

            return $this->redirect($this->generateUrl('sam_role'));
        }

        return $this->render('CanalTPSamEcoreSecurityBundle:Role:new.html.twig', array(
            'entity' => $model,
            'form'   => $form->createView(),
        ));
    }
public function createAction(Request $request)
    {
        $this->isAllowed('BUSINESS_MANAGE_ROLE');

        $model = new RegistrationRole();
        $form = $this->createCreateForm($model);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

            $selectedApps = array();
            foreach ($model->applications as $selectedApp) {
                $selectedApps[] = $selectedApp->getId();
            }

            foreach ($model->rolesByApplication as $app) {
                if (in_array($app->getId(), $selectedApps)) {
                    $permissions = null === $app->getRole()
                        ? array()
                        : $app->getRole()->getPermissions();

                    $role = new Role();
                    $role->setName($model->role->getName());
                    $role->setApplication($app);
                    $role->setPermissions($permissions);
                    $em->persist($role);
                }
            }

            $em->flush();
            $this->get('session')->getFlashBag()->add('success', 'role.flash.created');

            return $this->redirect($this->generateUrl('sam_role'));
        }

        return $this->render('CanalTPSamEcoreSecurityBundle:Role:new.html.twig', array(
            'entity' => $model,
            'form'   => $form->createView(),
        ));
    }
public function createAction ( Request $ request ) { $ this -> isAllowed ( 'BUSINESS_MANAGE_ROLE' ) ; $ model = new RegistrationRole ( ) ; $ form = $ this -> createCreateForm ( $ model ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ selectedApps = array ( ) ; foreach ( $ model -> applications as $ selectedApp ) { $ selectedApps [ ] = $ selectedApp -> getId ( ) ; } foreach ( $ model -> rolesByApplication as $ app ) { if ( in_array ( $ app -> getId ( ) , $ selectedApps ) ) { $ permissions = null === $ app -> getRole ( ) ? array ( ) : $ app -> getRole ( ) -> getPermissions ( ) ; $ role = new Role ( ) ; $ role -> setName ( $ model -> role -> getName ( ) ) ; $ role -> setApplication ( $ app ) ; $ role -> setPermissions ( $ permissions ) ; $ em -> persist ( $ role ) ; } } $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'role.flash.created' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'sam_role' ) ) ; } return $ this -> render ( 'CanalTPSamEcoreSecurityBundle:Role:new.html.twig' , array ( 'entity' => $ model , 'form' => $ form -> createView ( ) , ) ) ; }
Creates a new Role entity.
Creates a new Role entity .