/**
  * Create admin user form
  *
  * Method to create the Doctrine ORM user form for edit/create users 
  *
  * @return Zend\Form\Form
  */
 public function createUserForm($userEntity, $formName = 'LogIn')
 {
     $entityManager = $this->getEntityManager();
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $this->form = $builder->createForm($userEntity);
     $this->form->setHydrator(new DoctrineHydrator($entityManager));
     $this->form->setAttribute('method', 'post');
     $this->addCommonFields();
     switch ($formName) {
         case 'SignUp':
             $this->addSignUpFields();
             $this->addSignUpFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register'), 'name' => 'register'));
             break;
         case 'EditProfile':
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register', array('action' => 'edit-profile')), 'name' => 'edit-profile'));
             break;
         case 'ChangePassword':
             $this->addChangePasswordFields();
             $this->addChangePasswordFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register', array('action' => 'change-password')), 'name' => 'change-password'));
             break;
         case 'ResetPassword':
             $this->addResetPasswordFields();
             $this->addResetPasswordFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register', array('action' => 'reset-password')), 'name' => 'reset-password'));
             break;
         case 'ChangeEmail':
             $this->addChangeEmailFields();
             $this->addChangeEmailFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register', array('action' => 'change-email')), 'name' => 'change-email'));
             break;
         case 'ChangeSecurityQuestion':
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-register', array('action' => 'change-security-question')), 'name' => 'change-security-question'));
             break;
         case 'CreateUser':
             $this->addCreateUserFields();
             $this->addCreateUserFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-admin', array('action' => 'create-user')), 'name' => 'register'));
             break;
         case 'EditUser':
             $this->form->setAttributes(array('name' => 'register'));
             break;
         default:
             $this->addLoginFields();
             $this->addLoginFilters();
             $this->form->setAttributes(array('action' => $this->getUrlPlugin()->fromRoute('user-index', array('action' => 'login')), 'name' => 'login'));
             break;
     }
     $this->form->bind($userEntity);
     return $this->form;
 }
Exemplo n.º 2
0
 public function unserialiseAction()
 {
     $form = new \Zend\Form\Form();
     $form->setAttribute('method', 'post');
     $form->add(array('name' => 'code', 'attributes' => array('type' => 'textarea', 'class' => 'input-lg', 'style' => 'width:900px;height:300px;')));
     $form->bind(new \ArrayObject($this->params()->fromPost()));
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     $code = $this->params()->fromPost('code');
     if ($code) {
         $viewModel->setVariable("result", \DevelopmentLib\ArrayExporter::exportPhp54(unserialize($code)));
     }
     return $viewModel;
 }
 public function testBindingWorksAsExpected()
 {
     $form = new \Zend\Form\Form();
     $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
     $fieldset = new MoneyFieldset();
     $fieldset->init();
     $form->add($fieldset, array('name' => 'money'));
     $model = new TestModel();
     $form->bind($model);
     $this->assertEquals(5432.1, $fieldset->get('amount')->getValue());
     $this->assertEquals('ZAR', $fieldset->get('currency')->getValue());
     $form->setData(array('money' => array('amount' => 1234.56, 'currency' => 'GBP')));
     $this->assertTrue($form->isValid());
     $bound = $form->getData();
     $this->assertInstanceOf('NetglueMoney\\Form\\TestModel', $bound);
     $this->assertInstanceOf('NetglueMoney\\Money\\Money', $bound->money);
     $this->assertSame(123456, $bound->money->getAmount());
     $this->assertSame('GBP', $bound->money->getCurrencyCode());
 }
Exemplo n.º 4
0
 public function testExtractFromObjectDoesntTouchOriginalObject()
 {
     $form = new \Zend\Form\Form();
     $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
     $this->productFieldset->setUseAsBaseFieldset(true);
     $form->add($this->productFieldset);
     $originalObjectHash = spl_object_hash($this->productFieldset->get("categories")->getTargetElement()->getObject());
     $product = new Product();
     $product->setName("foo");
     $product->setPrice(42);
     $cat1 = new \ZendTest\Form\TestAsset\Entity\Category();
     $cat1->setName("bar");
     $cat2 = new \ZendTest\Form\TestAsset\Entity\Category();
     $cat2->setName("bar2");
     $product->setCategories(array($cat1, $cat2));
     $form->bind($product);
     $form->setData(array("product" => array("name" => "franz", "price" => 13, "categories" => array(array("name" => "sepp"), array("name" => "herbert")))));
     $objectAfterExtractHash = spl_object_hash($this->productFieldset->get("categories")->getTargetElement()->getObject());
     $this->assertSame($originalObjectHash, $objectAfterExtractHash);
 }
Exemplo n.º 5
0
    public function testDoesNotCreateNewObjects()
    {
        $form = new \Zend\Form\Form();
        $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods());
        $this->productFieldset->setUseAsBaseFieldset(true);
        $form->add($this->productFieldset);

        $product = new Product();
        $product->setName("foo");
        $product->setPrice(42);
        $cat1 = new \ZendTest\Form\TestAsset\Entity\Category();
        $cat1->setName("bar");
        $cat2 = new \ZendTest\Form\TestAsset\Entity\Category();
        $cat2->setName("bar2");

        $product->setCategories(array($cat1,$cat2));

        $form->bind($product);

        $form->setData(
            array("product"=>
                array(
                    "name" => "franz",
                    "price" => 13,
                    "categories" => array(
                        array("name" => "sepp"),
                        array("name" => "herbert")
                    )
                )
            )
        );
        $form->isValid();

        $categories = $product->getCategories();
        $this->assertSame($categories[0], $cat1);
        $this->assertSame($categories[1], $cat2);
    }
Exemplo n.º 6
0
 public function analyzeClassAction()
 {
     $form = new \Zend\Form\Form();
     $form->setAttribute('method', 'post');
     $form->add(array('name' => 'class', 'attributes' => array('type' => 'text', 'class' => 'input-lg')));
     $form->add(array('name' => 'code', 'attributes' => array('type' => 'textarea', 'class' => 'input-lg', 'style' => 'width:900px;height:300px;')));
     $form->bind(new \ArrayObject($this->params()->fromPost()));
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     $code = $this->params()->fromPost('code');
     eval($code);
     $reflectedClass = new \ReflectionClass($this->params()->fromPost('class'));
     var_dump($reflectedClass->getMethods());
     return $viewModel;
 }
Exemplo n.º 7
0
<?php

require_once './autoloader.php';
$value = array('title' => 'mytitle');
$value = new \ArrayObject($value);
$value['tag'] = new \ArrayObject(array('tagname' => 'mytag'));
$tagElement = array('name' => 'tagname', 'attributes' => array('type' => 'text', 'label' => 'Post Tag Name'));
$postElement = array('name' => 'title', 'attributes' => array('type' => 'text', 'label' => 'Post Title'));
$fieldset = new \Zend\Form\Fieldset('tag');
$fieldset->add($tagElement);
$form = new \Zend\Form\Form();
$form->add($postElement);
$form->add($fieldset);
$form->bind($value);