protected function getForm()
 {
     $builder = new AnnotationBuilder();
     $entity = new TestEntity();
     $form = $builder->createForm($entity);
     return $form;
 }
Exemple #2
0
 public function authenticateAction()
 {
     $user = new Forms\Login();
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $user = $request->getPost('username');
             $pass = $request->getPost('password');
             $redir = urldecode($this->params()->fromQuery('redir'));
             $authService = $this->getAuthService();
             $authService->setIdentity($user);
             $authService->setCredential($pass);
             $result = $authService->authenticate();
             /* $d = new \Zend\Debug\Debug();
                $d->dump($result);
                die; */
             foreach ($result->getMessages() as $message) {
                 //save message temporary into flashmessenger
                 $this->flashmessenger()->addMessage($message);
             }
             $conf = $this->getServiceLocator()->get('IdAuth\\Config');
             if ($conf['settings']['usePrevPageRedir']) {
                 return $this->redirect()->toUrl($redir);
             } else {
                 return $this->redirect()->toRoute('idAuth');
             }
         }
     }
     return $this->redirect()->toRoute('idAuth/login');
 }
 /**
  * The default action - show the home page
  */
 public function indexAction()
 {
     // init vars
     $data = NULL;
     $table = $this->getServiceLocator()->get('city-codes-table');
     $catList = $this->getServiceLocator()->get('form-demo-categories');
     $cityList = $table->getAllCityCodesForForm();
     $countryList = $table->getAllCountryCodesForForm();
     // submit button
     $submit = new Submit('submit');
     $submit->setAttribute('value', 'Submit');
     // build form
     $builder = new AnnotationBuilder();
     $entity = $this->getServiceLocator()->get('form-demo-listings-entity');
     $form = $builder->createForm($entity);
     $form->get('category')->setValueOptions(array_combine($catList, $catList));
     $form->getInputFilter()->get('category')->getValidatorChain()->attachByName('InArray', array('haystack' => $catList));
     $form->get('country')->setValueOptions($countryList);
     $form->getInputFilter()->get('country')->getValidatorChain()->attachByName('InArray', array('haystack' => $countryList));
     $form->add($submit);
     $form->bind($entity);
     if ($this->getRequest()->isPost()) {
         $form->setData($this->params()->fromPost());
         if ($form->isValid()) {
             $data = $form->getData();
         }
     }
     return new ViewModel(array('form' => $form, 'data' => $data, 'cityList' => $cityList));
 }
Exemple #4
0
 /**
  * @param EntityManager         $entityManager
  * @param Entity\EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $doctrineHydrator = new DoctrineHydrator($entityManager);
     $this->setHydrator($doctrineHydrator)->setObject($object);
     $builder = new AnnotationBuilder();
     /**
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($object)->getElements() as $element) {
         /**
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
             $element->setOptions(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager]));
         }
         if ($element instanceof Radio) {
             $attributes = $element->getAttributes();
             $valueOptionsArray = 'get' . ucfirst($attributes['array']);
             $element->setOptions(array_merge_recursive($element->getOptions(), ['value_options' => $object->{$valueOptionsArray}()]));
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
 }
 public function addAction()
 {
     // The annotation builder help us create a form from the annotations in the user entity.
     $builder = new AnnotationBuilder();
     $entity = $this->serviceLocator->get('user-entity');
     $form = $builder->createForm($entity);
     $form->add(array('name' => 'password_verify', 'type' => 'Zend\\Form\\Element\\Password', 'attributes' => array('placeholder' => 'Verify Password Here...', 'required' => 'required'), 'options' => array('label' => 'Verify Password')), array('priority' => $form->get('password')->getOption('priority')));
     // This is the special code that protects our form being submitted from automated scripts
     $form->add(array('name' => 'csrf', 'type' => 'Zend\\Form\\Element\\Csrf'));
     // This is the submit button
     $form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Submit', 'required' => 'false')));
     // We bind the entity to the user. If the form tries to read/write data from/to the entity
     // it will use the hydrator specified in the entity to achieve this. In our case we use ClassMethods
     // hydrator which means that reading will happen calling the getter methods and writing will happen by
     // calling the setter methods.
     $form->bind($entity);
     if ($this->getRequest()->isPost()) {
         $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($data);
         if ($form->isValid()) {
             // We use now the Doctrine 2 entity manager to save user data to the database
             $entityManager = $this->serviceLocator->get('entity-manager');
             $entityManager->persist($entity);
             $entityManager->flush();
             $this->flashmessenger()->addSuccessMessage('User was added successfully.');
             $event = new EventManager('user');
             $event->trigger('register', $this, array('user' => $entity));
             // redirect the user to the view user action
             return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'view', 'id' => $entity->getId()));
         }
     }
     // pass the data to the view for visualization
     return array('form1' => $form);
 }
 /**
  * @param EntityManager $entityManager
  */
 public function __construct(EntityManager $entityManager)
 {
     parent::__construct('doa');
     $doa = new Entity\Doa();
     $doctrineHydrator = new DoctrineHydrator($entityManager, 'Affiliation\\Entity\\Doa');
     $this->setHydrator($doctrineHydrator)->setObject($doa);
     $builder = new AnnotationBuilder();
     /**
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($doa)->getElements() as $element) {
         /**
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect) {
             $element->setOptions(['object_manager' => $entityManager]);
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
     $this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'contact', 'options' => ["label" => "txt-signer"]]);
     $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-source-file", "help-block" => _("txt-attachment-requirements")]]);
 }
 /**
  * For JS AJAX validation - validates a property of Equipment object.
  * @return JSON status=ok|error,message={string}
  */
 public function validateJSONAction()
 {
     try {
         $propName = $this->params()->fromPost('propName');
         if (!in_array($propName, Equipment::propertyNames())) {
             throw new \Exception('Wrong property provided.');
         }
         $value = $this->params()->fromPost('value');
         if (!$propName || !$value) {
             throw new \Exception('No property and/or value given.');
         }
         $equipment = new Equipment();
         $builder = new AnnotationBuilder();
         $form = $builder->createForm($equipment);
         $form->setData(array($propName => $value))->isValid();
         $elements = $form->getElements();
         $element = $elements[$propName];
         if (count($element->getMessages())) {
             return $this->myJsonModel(array('status' => 'error', 'message' => $element->getMessages()));
         } else {
             return $this->myJsonModel(array('status' => 'ok', 'message' => ''));
         }
     } catch (\Exception $e) {
         // @TODO: set status to syserror so JS doesn't confuse with
         // validation error
         return $this->myJsonModel(array('status' => 'error', 'message' => $e->getMessage()));
     }
 }
 /**
  * @param EntityManager         $entityManager
  * @param Entity\EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $doctrineHydrator = new DoctrineHydrator($entityManager);
     $this->setHydrator($doctrineHydrator)->setObject($object);
     $builder = new AnnotationBuilder();
     /**
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($object)->getElements() as $element) {
         /**
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
             $element->setOptions(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager]));
         }
         if ($element instanceof Radio) {
             $attributes = $element->getAttributes();
             $valueOptionsArray = 'get' . ucfirst($attributes['array']);
             $element->setOptions(array_merge_recursive($element->getOptions(), ['value_options' => $object->{$valueOptionsArray}()]));
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
     $this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'organisation', 'options' => ['disable_inarray_validator' => true, "label" => _("txt-organisation"), "help-block" => _("txt-organisation-help-block")]]);
     $this->add(['type' => '\\Zend\\Form\\Element\\Text', 'name' => 'branch', 'options' => ["label" => _("txt-branch"), "help-block" => _("txt-branch-help-block")]]);
 }
 /**
  * @param EntityManager         $entityManager
  * @param Entity\EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $doctrineHydrator = new DoctrineHydrator($entityManager);
     $this->setHydrator($doctrineHydrator)->setObject($object);
     $builder = new AnnotationBuilder();
     /*
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($object)->getElements() as $element) {
         /*
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
             $element->setOptions(['object_manager' => $entityManager]);
         }
         if ($element instanceof Radio) {
             $attributes = $element->getAttributes();
             $valueOptionsArray = 'get' . ucfirst($attributes['array']);
             $element->setOptions(['value_options' => $object->{$valueOptionsArray}()]);
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
     $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'attributes' => ["class" => "form-control"], 'options' => ["label" => _("txt-source-file"), "help-block" => _("txt-attachment-requirements")]]);
 }
Exemple #10
0
 /**
  * @param mixed $model
  */
 public function setModel($model)
 {
     $modelClass = get_class($model);
     $this->form = $this->annotationBuilder->createForm($modelClass);
     $this->form->bind($model);
     $this->setVariables(['form' => $this->form, 'object' => $model, 'title' => $this->getFieldSetTitle($model)]);
     $this->buildFormViewModel($this->form, $this);
 }
Exemple #11
0
 /**
  * Returns constructed Feedback
  *
  * @param ServiceManager $sm ServiceManager
  *
  * @return Form
  */
 public static function getFeedbackForm(ServiceManager $sm)
 {
     $builder = new AnnotationBuilder();
     $form = $builder->createForm('\\Swissbib\\Feedback\\Form\\FeedbackForm');
     $form->add(new Csrf('security'));
     $form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'feedback.form.submit']]);
     return $form;
 }
 public function getForm()
 {
     if (!$this->form) {
         $user = new User();
         $builder = new AnnotationBuilder();
         $this->form = $builder->createForm($user);
     }
     return $this->form;
 }
 private function getForm()
 {
     if (!$this->form) {
         $form = new LoginForm();
         $builder = new AnnotationBuilder();
         $this->form = $builder->createForm($form);
     }
     return $this->form;
 }
Exemple #14
0
 /**
  * @param ServiceManager $sm
  *
  * @return Form
  */
 public static function getCopyForm(ServiceManager $sm)
 {
     AbstractValidator::setDefaultTranslator($sm->get('\\VuFind\\Translator'));
     $builder = new AnnotationBuilder();
     $form = $builder->createForm('\\Swissbib\\Record\\Form\\CopyForm');
     $form->add(new Csrf('security'));
     $form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'request_copy_text']]);
     return $form;
 }
 public function __construct()
 {
     $this->lastAttemptResult = LoginLogoutService::$failedLoginAttempt;
     $this->authservice = new AuthenticationService();
     $this->authservice->setStorage(new \Main\Service\UserSessionStorage());
     $user = new User();
     $builder = new AnnotationBuilder();
     $this->form = $builder->createForm($user);
 }
Exemple #16
0
 public static function factory(PeepEntity $peep = null)
 {
     if (null === $peep) {
         $peep = __NAMESPACE__ . '\\PeepEntity';
     }
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($peep);
     $form->add(new CsrfElement('secure'));
     $form->add(array('name' => 'peep', 'attributes' => array('type' => 'submit', 'value' => 'Peep!')));
     if ($peep instanceof PeepEntity) {
         $form->bind($peep);
     }
     return $form;
 }
Exemple #17
0
 /**
  * Primerio oter todos os atributos da classe de forma automática;
  * Depois, obter todos atributos que possuem annotações que serão utilizadas;
  * Estes atributos serão gerados na grid. 
  * 
  * @param \Dataware\Entity\Grid $grid
  */
 private function makeGridColumnsByEntity(Grid $grid)
 {
     if (strlen($grid->getEntity()) > 0) {
         $annotationBuilder = new AnnotationBuilder();
         $formEspecification = $annotationBuilder->getFormSpecification($grid->getEntity());
         foreach ($formEspecification['elements'] as $element) {
             if (strlen($element['spec']['options']['label']) > 0) {
                 // É possível a partir do tipo, conseguir descobrir o alinhamento dos registros.
                 $gridColumn = new GridColumn($element['spec']['name'], $element['spec']['options']['label']);
                 $grid->addColumn($gridColumn);
             }
         }
     }
 }
Exemple #18
0
 /**
  * {@inheritDoc}
  */
 protected function getCreateForm()
 {
     $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $builder = new AnnotationBuilder($entityManager);
     $form = $builder->createForm($this->getEntity());
     $options = $entityManager->getRepository('Comment\\Entity\\EntityType')->getEntities();
     $select = $form->getElements()['entity'];
     $select->setValueOptions($options);
     $select->setOptions(array('empty_option' => 'Please choose entity'));
     $form->setInputFilter(new Filter\EntityTypeInputFilter($this->getServiceLocator()));
     $urlHelper = $this->getUrlHelper();
     $form->setAttribute('action', $urlHelper('comment/default', ['controller' => 'entity-type', 'action' => 'create']));
     //        $form->setData(['isVisible' => true, 'isEnabled' => true]);
     return $form;
 }
 /**
  * Overrides the base getFormSpecification() to additionally iterate through each
  * field/association in the metadata and trigger the associated event.
  *
  * This allows building of a form from metadata instead of requiring annotations.
  * Annotations are still allowed through the ElementAnnotationsListener.
  *
  * {@inheritDoc}
  */
 public function getFormSpecification($entity)
 {
     $formSpec = parent::getFormSpecification($entity);
     $metadata = $this->objectManager->getClassMetadata(is_object($entity) ? get_class($entity) : $entity);
     $inputFilter = $formSpec['input_filter'];
     $formElements = array('DoctrineModule\\Form\\Element\\ObjectSelect', 'DoctrineModule\\Form\\Element\\ObjectMultiCheckbox', 'DoctrineModule\\Form\\Element\\ObjectRadio');
     foreach ($formSpec['elements'] as $key => $elementSpec) {
         $name = isset($elementSpec['spec']['name']) ? $elementSpec['spec']['name'] : null;
         $isFormElement = isset($elementSpec['spec']['type']) && in_array($elementSpec['spec']['type'], $formElements);
         if (!$name) {
             continue;
         }
         if (!isset($inputFilter[$name])) {
             $inputFilter[$name] = new \ArrayObject();
         }
         $params = array('metadata' => $metadata, 'name' => $name, 'elementSpec' => $elementSpec, 'inputSpec' => $inputFilter[$name]);
         if ($this->checkForExcludeElementFromMetadata($metadata, $name)) {
             $elementSpec = $formSpec['elements'];
             unset($elementSpec[$key]);
             $formSpec['elements'] = $elementSpec;
             if (isset($inputFilter[$name])) {
                 unset($inputFilter[$name]);
             }
             $formSpec['input_filter'] = $inputFilter;
             continue;
         }
         if ($metadata->hasField($name) || !$metadata->hasAssociation($name) && $isFormElement) {
             $this->getEventManager()->trigger(static::EVENT_CONFIGURE_FIELD, $this, $params);
         } elseif ($metadata->hasAssociation($name)) {
             $this->getEventManager()->trigger(static::EVENT_CONFIGURE_ASSOCIATION, $this, $params);
         }
     }
     $formSpec['options'] = array('prefer_form_input_filter' => true);
     return $formSpec;
 }
Exemple #20
0
 /**
  * Note:
  * Only save to / load from cache if it is the specified entity.
  * Otherwise strange stuff will happen when using fieldsets and collections.
  *
  * {@inheritDoc}
  */
 public function getFormSpecification($entity)
 {
     $config = $this->getConfiguration();
     $cache = $config->getCache();
     $cacheKey = $config->getCacheKey();
     // Pre event
     $this->triggerEvent(FormEvent::EVENT_FORM_SPECIFICATIONS_PRE, $this, array('cacheKey' => $cacheKey));
     // Load form specs from cache:
     if ($config->isCacheableEntity($entity) && $cache->hasItem($cacheKey)) {
         $formSpec = $cache->getItem($cacheKey);
         // Parse form specs:
     } else {
         $formSpec = parent::getFormSpecification($entity);
         // Save cache:
         if ($config->isCacheableEntity($entity)) {
             try {
                 $cache->setItem($cacheKey, $formSpec);
             } catch (\Exception $e) {
                 // Silent fail
             }
         }
     }
     // Post event
     $this->triggerEvent(FormEvent::EVENT_FORM_SPECIFICATIONS_POST, $this, array('cacheKey' => $cacheKey, 'formSpec' => $formSpec));
     return $formSpec;
 }
 /**
  * Overrides the base getFormSpecification() to additionally iterate through each
  * field/association in the metadata and trigger the associated event.
  *
  * This allows building of a form from metadata instead of requiring annotations.
  * Annotations are still allowed through the ElementAnnotationsListener.
  *
  * {@inheritDoc}
  */
 public function getFormSpecification($entity)
 {
     $formSpec = parent::getFormSpecification($entity);
     $metadata = $this->objectManager->getClassMetadata(is_object($entity) ? get_class($entity) : $entity);
     $inputFilter = $formSpec['input_filter'];
     foreach ($formSpec['elements'] as $key => $elementSpec) {
         $name = isset($elementSpec['spec']['name']) ? $elementSpec['spec']['name'] : null;
         if (!$name) {
             continue;
         }
         if (!isset($inputFilter[$name])) {
             $inputFilter[$name] = new \ArrayObject();
         }
         $params = array('metadata' => $metadata, 'name' => $name, 'elementSpec' => $elementSpec, 'inputSpec' => $inputFilter[$name]);
         if ($this->checkForExcludeElementFromMetadata($metadata, $name)) {
             $elementSpec = $formSpec['elements'];
             unset($elementSpec[$key]);
             $formSpec['elements'] = $elementSpec;
             if (isset($inputFilter[$name])) {
                 unset($inputFilter[$name]);
             }
             $formSpec['input_filter'] = $inputFilter;
             continue;
         }
         if ($metadata->hasField($name)) {
             $this->getEventManager()->trigger(static::EVENT_CONFIGURE_FIELD, $this, $params);
         } elseif ($metadata->hasAssociation($name)) {
             $this->getEventManager()->trigger(static::EVENT_CONFIGURE_ASSOCIATION, $this, $params);
         }
     }
     return $formSpec;
 }
 private function getRadarForm()
 {
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $event = new Event();
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($event);
     $form->setHydrator(new DoctrineObject($em))->setObject($event);
     $categories = $em->getRepository('Application\\Entity\\RadarCategory')->findBy(array('defaultradarcategory' => true));
     if ($categories) {
         $cat = $categories[0];
         $form->add(new CustomFieldset($this->getServiceLocator(), $cat->getId()));
         //uniquement les champs ajoutés par conf
         $form->get('custom_fields')->remove($cat->getRadarfield()->getId());
         $form->get('custom_fields')->remove($cat->getStatefield()->getId());
     }
     return $form;
 }
Exemple #23
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $sm
  * @return \Zend\Form\Form
  */
 public function createService(ServiceLocatorInterface $sm)
 {
     $seo = new Seo(Null, Null, Null, Null);
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($seo);
     $form->bind($seo);
     $form->get('type')->setValueOptions(Seo::$entityType);
     //    $form->add(array(
     //        'type' => 'DoctrineModule\Form\Element\ObjectSelect',
     //        'name' => 'pageId',
     //        'priority' => 5,
     //        'options' => array(
     //            'label' => 'Homeowners',
     //            'object_manager' => $sm->get('doctrine.entitymanager.orm_default'),
     //            'target_class' => '\BuilderJob\Entity\Homeowner',
     //            'property' => 'email',
     //            'empty_option' => '--- please choose ---',
     //            'is_method' => true,
     //            'find_method' => array(
     //                'name' => 'findAll',
     //            ),
     //        ),
     //    ));
     $form->add(array('type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'name' => 'pageId', 'priority' => 5, 'options' => array('label' => 'Builder', 'object_manager' => $sm->get('doctrine.entitymanager.orm_default'), 'target_class' => '\\BuilderJob\\Entity\\Builder', 'property' => 'email', 'empty_option' => '--- please choose ---', 'is_method' => true, 'find_method' => array('name' => 'findAll'))));
     $form->getInputFilter()->add(array('name' => 'pageId', 'required' => TRUE));
     //
     //    $form->add(array(
     //        'type' => 'DoctrineModule\Form\Element\ObjectSelect',
     //        'name' => 'pageId',
     //        'priority' => 5,
     //        'options' => array(
     //            'label' => 'Job',
     //            'object_manager' => $sm->get('doctrine.entitymanager.orm_default'),
     //            'target_class' => '\BuilderJob\Entity\Job',
     //            'property' => 'title',
     //            'empty_option' => '--- please choose ---',
     //            'is_method' => true,
     //            'find_method' => array(
     //                'name' => 'findAll',
     //            ),
     //        ),
     //    ));
     $form->add(array('name' => 'security', 'type' => 'Zend\\Form\\Element\\Csrf'));
     $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Add Seo')));
     return $form;
 }
 /**
  * Inject annotations from configuration, if any.
  *
  * @param array $config
  * @param AnnotationBuilder $builder
  * @return void
  */
 private function injectAnnotations(array $config, AnnotationBuilder $builder)
 {
     if (!isset($config['annotations'])) {
         return;
     }
     $parser = $builder->getAnnotationParser();
     foreach ($config['annotations'] as $fullyQualifiedClassName) {
         $parser->registerAnnotation($fullyQualifiedClassName);
     }
 }
Exemple #25
0
 public function annotationSimpleAction()
 {
     // prepare data
     $comment = new \Mod2\Entity\Comment1();
     $comment->type = 2;
     $comment->comment = 'Test annotation';
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($comment);
     $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Go', 'id' => 'submitbutton')));
     $form->bind($comment);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             var_dump($comment);
         }
     }
     return array('form' => $form);
 }
 public function __construct(EntityManager $entityManager)
 {
     // we want to ignore the name passed
     parent::__construct('entity-create-form');
     $this->setAttribute('method', 'post')->setHydrator(new DoctrineHydrator($entityManager, 'Application\\Entity\\Place'))->setObject(new Place());
     $builder = new AnnotationBuilder();
     $repository = $entityManager->getRepository('Application\\Entity\\Place');
     $id = 1;
     //(int)$this->params()->fromQuery('id');
     $place = $repository->find($id);
     $entity = $place;
     // new Place();
     //Add the fieldset, and set it as the base fieldset
     $fieldset = $builder->createForm($entity);
     $fieldset->setUseAsBaseFieldset(true);
     //var_dump($fieldset);
     $this->add($fieldset);
     $this->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf'));
     $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Save')));
 }
 public function loginAction()
 {
     $view = new ViewModel();
     $login = new Login();
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($login);
     $request = $this->getRequest();
     $ldap = $this->getServiceLocator()->get('Zf2LdapAuth\\Client\\Ldap');
     if ($request->isPost()) {
         $form->bind($login);
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             try {
                 $auth = $ldap->authenticate($data->name, $data->password);
                 if ($auth === TRUE) {
                     $view->data = "Authentication Successful, Redirecting...";
                     if ($ldap->useCallBack()) {
                         $userData = $ldap->getUserObj($data->name);
                         if ($userData !== FALSE) {
                             $callBackFunction = $ldap->getCallBackFunction();
                             $callBackFunction::setData($userData);
                         }
                     }
                     /* User already has a session so redirect back */
                     return $this->redirect()->toUrl($ldap->getRedirectLocation());
                 } else {
                     $view->error = $auth;
                     $view->form = $form;
                     return $view;
                 }
             } catch (\Exception $exc) {
                 $view->data = $exc->getMessage();
                 return $view;
             }
         }
     } else {
         $view->form = $form;
         return $view;
     }
 }
Exemple #28
0
 /**
  * @param $entity
  * @return null|\Zend\Form\Form
  */
 public function convertEntity(BaseInterface $entity)
 {
     if (empty($entity)) {
         throw new \InvalidArgumentException("Entity must not be null!");
     }
     $className = get_class($entity);
     // if passed a null object, instantiate a new doctrine object of that class
     if ($entity->isNull()) {
         // null object, get
         $className = substr($className, 0, -4);
         $entity = new $className();
     }
     $builder = new AnnotationBuilder();
     // use the entity annotations and create a zend form object
     $form = $builder->createForm($className);
     // set strategy for how to transfer data between form elements and
     $form->setHydrator(new DoctrineHydrator($this->em(), $className));
     // populate form with entity
     $form->bind($entity);
     return $form;
 }
Exemple #29
0
 /**
  * @param EntityManager         $entityManager
  * @param Entity\EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $contact = new Entity\Contact();
     $doctrineHydrator = new DoctrineHydrator($entityManager, 'Contact\\Entity\\Contact');
     $this->setHydrator($doctrineHydrator)->setObject($contact);
     $builder = new AnnotationBuilder();
     /**
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($object)->getElements() as $element) {
         /**
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
             $element->setOptions(array('object_manager' => $entityManager));
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
     $contactPhone = new ContactPhoneFieldset($entityManager, new Entity\Phone());
     $contactPhone->setObject(new Entity\Phone());
     $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'phone', 'options' => array('label' => _("txt-phone-information"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactPhone)));
     $contactProfileFieldset = new \Contact\Form\ContactProfileFieldset($entityManager, new Entity\Profile());
     $this->add($contactProfileFieldset);
     $contactPhoto = new \Contact\Form\ContactPhotoFieldset($entityManager, new Entity\Photo());
     $contactPhoto->setObject(new Entity\Photo());
     $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'photo', 'options' => array('label' => _("txt-profile-photo"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => false, 'target_element' => $contactPhoto)));
     $contactAddress = new ContactAddressFieldset($entityManager, new Entity\Address());
     $contactAddress->setObject(new Entity\Address());
     $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'address', 'options' => array('label' => _("txt-address-information"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactAddress)));
     $contactCommunity = new ContactCommunityFieldset($entityManager, new Entity\Community());
     $contactCommunity->setObject(new Entity\Community());
     $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'community', 'options' => array('label' => _("txt-community-information"), 'count' => 5, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactCommunity)));
     $contactOrganisationFieldset = new \Contact\Form\ContactOrganisationFieldset($entityManager, new Entity\ContactOrganisation());
     $this->add($contactOrganisationFieldset);
 }
 /**
  * @param EntityManager         $entityManager
  * @param Entity\EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $phone = new Entity\Phone();
     $doctrineHydrator = new DoctrineHydrator($entityManager, 'Contact\\Entity\\Phone');
     $this->setHydrator($doctrineHydrator)->setObject($phone);
     $builder = new AnnotationBuilder();
     /*
      * Go over the different form elements and add them to the form
      */
     foreach ($builder->createForm($object)->getElements() as $element) {
         /*
          * Go over each element to add the objectManager to the EntitySelect
          */
         if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
             $element->setOptions(array('object_manager' => $entityManager));
         }
         //Add only when a type is provided
         if (array_key_exists('type', $element->getAttributes())) {
             $this->add($element);
         }
     }
 }