public function addCountry()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        $areaCountryForm = $this->createForm(AdminForm::AREA_COUNTRY);
        $error_msg = null;
        try {
            $form = $this->validateForm($areaCountryForm);

            $event = new AreaAddCountryEvent($form->get('area_id')->getData(), $form->get('country_id')->getData());

            $this->dispatch(TheliaEvents::AREA_ADD_COUNTRY, $event);

            if (! $this->eventContainsObject($event)) {
                throw new \LogicException(
                    $this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName))
                );
            }

            // Log object modification
            if (null !== $changedObject = $this->getObjectFromEvent($event)) {
                $this->adminLogAppend(
                    $this->resourceCode,
                    AccessManager::UPDATE,
                    sprintf(
                        "%s %s (ID %s) modified, new country added",
                        ucfirst($this->objectName),
                        $this->getObjectLabel($changedObject),
                        $this->getObjectId($changedObject)
                    ),
                    $this->getObjectId($changedObject)
                );
            }

            // Redirect to the success URL
            return $this->generateSuccessRedirect($areaCountryForm);
        } catch (FormValidationException $ex) {
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $error_msg = $ex->getMessage();
        }

        $this->setupFormErrorContext(
            $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)),
            $error_msg,
            $areaCountryForm
        );

        // At this point, the form has errors, and should be redisplayed.
        return $this->renderEditionTemplate();
    }
public function addCountry()
    {
        // Check current user authorization
        if (null !== $response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE)) {
            return $response;
        }

        $areaCountryForm = $this->createForm(AdminForm::AREA_COUNTRY);
        $error_msg = null;
        try {
            $form = $this->validateForm($areaCountryForm);

            $event = new AreaAddCountryEvent($form->get('area_id')->getData(), $form->get('country_id')->getData());

            $this->dispatch(TheliaEvents::AREA_ADD_COUNTRY, $event);

            if (! $this->eventContainsObject($event)) {
                throw new \LogicException(
                    $this->getTranslator()->trans("No %obj was updated.", array('%obj', $this->objectName))
                );
            }

            // Log object modification
            if (null !== $changedObject = $this->getObjectFromEvent($event)) {
                $this->adminLogAppend(
                    $this->resourceCode,
                    AccessManager::UPDATE,
                    sprintf(
                        "%s %s (ID %s) modified, new country added",
                        ucfirst($this->objectName),
                        $this->getObjectLabel($changedObject),
                        $this->getObjectId($changedObject)
                    ),
                    $this->getObjectId($changedObject)
                );
            }

            // Redirect to the success URL
            return $this->generateSuccessRedirect($areaCountryForm);
        } catch (FormValidationException $ex) {
            // Form cannot be validated
            $error_msg = $this->createStandardFormValidationErrorMessage($ex);
        } catch (\Exception $ex) {
            // Any other error
            $error_msg = $ex->getMessage();
        }

        $this->setupFormErrorContext(
            $this->getTranslator()->trans("%obj modification", array('%obj' => $this->objectName)),
            $error_msg,
            $areaCountryForm
        );

        // At this point, the form has errors, and should be redisplayed.
        return $this->renderEditionTemplate();
    }
public function addCountry ( ) { // Check current user authorization if ( null !== $ response = $ this -> checkAuth ( $ this -> resourceCode , array ( ) , AccessManager :: UPDATE ) ) { return $ response ; } $ areaCountryForm = $ this -> createForm ( AdminForm :: AREA_COUNTRY ) ; $ error_msg = null ; try { $ form = $ this -> validateForm ( $ areaCountryForm ) ; $ event = new AreaAddCountryEvent ( $ form -> get ( 'area_id' ) -> getData ( ) , $ form -> get ( 'country_id' ) -> getData ( ) ) ; $ this -> dispatch ( TheliaEvents :: AREA_ADD_COUNTRY , $ event ) ; if ( ! $ this -> eventContainsObject ( $ event ) ) { throw new \ LogicException ( $ this -> getTranslator ( ) -> trans ( "No %obj was updated." , array ( '%obj' , $ this -> objectName ) ) ) ; } // Log object modification if ( null !== $ changedObject = $ this -> getObjectFromEvent ( $ event ) ) { $ this -> adminLogAppend ( $ this -> resourceCode , AccessManager :: UPDATE , sprintf ( "%s %s (ID %s) modified, new country added" , ucfirst ( $ this -> objectName ) , $ this -> getObjectLabel ( $ changedObject ) , $ this -> getObjectId ( $ changedObject ) ) , $ this -> getObjectId ( $ changedObject ) ) ; } // Redirect to the success URL return $ this -> generateSuccessRedirect ( $ areaCountryForm ) ; } catch ( FormValidationException $ ex ) { // Form cannot be validated $ error_msg = $ this -> createStandardFormValidationErrorMessage ( $ ex ) ; } catch ( \ Exception $ ex ) { // Any other error $ error_msg = $ ex -> getMessage ( ) ; } $ this -> setupFormErrorContext ( $ this -> getTranslator ( ) -> trans ( "%obj modification" , array ( '%obj' => $ this -> objectName ) ) , $ error_msg , $ areaCountryForm ) ; // At this point, the form has errors, and should be redisplayed. return $ this -> renderEditionTemplate ( ) ; }
add a country to a define area
add a country to a define area