Example #1
0
 public function getForm($mode)
 {
     $builder = new AnnotationBuilder($this->getEntityManager());
     $form = $builder->createForm('Minibus\\Model\\Entity\\Process');
     $form->setData(array("mode" => $mode));
     return $form;
 }
Example #2
0
 public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('album_dm/default', array('controller' => 'album-dm', 'action' => 'index'));
     }
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $repository = $entityManager->getRepository('AlbumDm\\Entity\\Album');
         $album = $repository->find($id);
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         // this never will be seen if you don't comment the redirect
         return $this->redirect()->toRoute('album_dm/default', array('controller' => 'album-dm', 'action' => 'index'));
     }
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($album);
     $form->setHydrator(new DoctrineHydrator($entityManager, 'AlbumDm\\Entity\\Album'));
     $send = new Element('submit');
     $send->setValue('Go');
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     $form->bind($album);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $entityManager->persist($album);
             $entityManager->flush();
             return $this->redirect()->toRoute('album_dm/default', array('controller' => 'album-dm', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
 /**
  * {@inheritDoc}
  *
  * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     /* @var $entityManager \Doctrine\ORM\EntityManager */
     $entityManager = $container->get('doctrine.entitymanager.' . $this->getName());
     $annotationBuilder = new AnnotationBuilder($entityManager);
     $annotationBuilder->setFormFactory($this->getFormFactory($container));
     return $annotationBuilder;
 }
 /**
  * {@inheritDoc}
  *
  * @return \DoctrineORMModule\Form\Annotation\AnnotationBuilder
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $entityManager \Doctrine\ORM\EntityManager */
     $entityManager = $serviceLocator->get('doctrine.entitymanager.' . $this->getName());
     $annotationBuilder = new AnnotationBuilder($entityManager);
     $annotationBuilder->setFormFactory($this->getFormFactory($serviceLocator));
     return $annotationBuilder;
 }
 /**
  * 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;
 }
 /**
  * {@inheritDoc}
  *
  * @param StorageInterface $cacheStorage
  */
 public function __construct(ObjectManager $objectManager, StorageInterface $cacheStorage = null)
 {
     parent::__construct($objectManager);
     if (null !== $cacheStorage) {
         $this->setCacheStorage($cacheStorage);
     }
 }
Example #7
0
 public function getForm($article, $entityManager, $myEntity, $action)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($article);
     //!!!!!! Start !!!!! Added to make the association tables work with select
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     $form->setHydrator(new DoctrineHydrator($entityManager, $myEntity));
     $oName = new Element('name');
     $oName->setAttributes(array('type' => 'text', 'maxlength' => 255));
     $oName->setOptions(array('label' => 'Название'));
     $form->add($oName, array('priority' => 1000));
     $oDescription = new Element('description');
     $oDescription->setAttributes(array('type' => 'text', 'maxlength' => 255));
     $oDescription->setOptions(array('label' => 'Описание'));
     $form->add($oDescription, array('priority' => 999));
     $send = new Element('send');
     $send->setValue($action);
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     foreach ($form->getElements() as $element) {
         $element->setAttribute('id', $element->getName());
         $element->setAttribute('class', 'form-control');
         /*if ($element->getLabel() === null) {
               $element->setOptions(array('add-on-div' => array('class'  => 'col-sm-offset-2 col-sm-10'), ));
           } else {
               $element->setOptions(array( 'add-on-div' => array('class'  => 'col-sm-10'), 
                                       'label_attributes' => array('class'  => 'col-sm-2 control-label'),
                                 ));
           }*/
     }
     return $form;
 }
 public function getForm()
 {
     $builder = new AnnotationBuilder($this->em);
     if ($this->cache) {
         if (!$this->cache->hasItem($this->keyName)) {
             $form = $builder->createForm(new $this->className());
             $this->cache->setItem($this->keyName, $form);
         } else {
             //var_dump("Cache hit");
             $form = $this->cache->getItem($this->keyName);
         }
     } else {
         //Do not use cache
         $form = $builder->createForm(new $this->className());
     }
     $elements = $form->getElements();
     $fieldsets = $form->getFieldsets();
     $this->settingElements($elements);
     $this->settingFieldsets($fieldsets);
     $hydrator = new \DoctrineModule\Stdlib\Hydrator\DoctrineObject($this->em, $this->className);
     $form->setHydrator($hydrator);
     return $form;
 }
 /**
  * @covers \DoctrineORMModule\Form\Annotation\AnnotationBuilder::getFormSpecification
  */
 public function testAnnotationBuilderSupportsClassNames()
 {
     $spec = $this->builder->getFormSpecification('DoctrineORMModuleTest\\Assets\\Entity\\Issue237');
     $this->assertCount(0, $spec['elements'], 'Annotation builder allows also class names');
 }
Example #10
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id2', 0);
     if (!$id) {
         return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'comment', 'action' => 'add'), true);
     }
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         $repository = $entityManager->getRepository('CsnCms\\Entity\\Comment');
         $comment = $repository->getCommentForEdit($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'comment', 'action' => 'index'), true);
     }
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($comment);
     $form->remove('comCreated');
     $form->remove('author');
     $form->remove('article');
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     $form->setHydrator(new DoctrineHydrator($entityManager, 'GraceDrops\\Entity\\Comment'));
     $send = new Element('send');
     $send->setValue('Edit');
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     $form->bind($comment);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $entityManager->persist($comment);
             $entityManager->flush();
             return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'comment', 'action' => 'index'), true);
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Example #11
0
 /**
  *
  * @return Form
  */
 public function getForm()
 {
     $builder = new AnnotationBuilder($this->getEntityManager());
     return $builder->createForm('Minibus\\Model\\Entity\\Configuration');
 }
Example #12
0
 /**
  * Ensure prefer_form_input_filter is set to true for the generated form
  */
 public function testPreferFormInputFilterIsTrue()
 {
     $entity = new FormEntity();
     $form = $this->builder->createForm($entity);
     $this->assertTrue($form->getPreferFormInputFilter());
 }
Example #13
0
 public function getForm($article, $entityManager, $action)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($article);
     //!!!!!! Start !!!!! Added to make the association tables work with select
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     /*  uncomment if you need to control the data and time		
     		 $form->add(array(
     			 'type' => 'Zend\Form\Element\Date',
     			 'name' => 'artcCreatedDate',
     			 'options' => array(
     					 'label' => 'Created Date'
     			 ),
     			 'attributes' => array(
     					 'min' => '2012-01-01',
     					 'max' => '2020-01-01',
     					 'step' => '1', // days; default step interval is 1 day
     			 )
     		 ));
     
     		 $form->add(array(
     			 'type' => 'Zend\Form\Element\Time',
     			 'name' => 'artcCreatedTime',
     			 'options'=> array(
     					 'label' => 'Created Time'
     			 ),
     			 'attributes' => array(
     					 'min' => '00:00:00',
     					 'max' => '23:59:59',
     					 'step' => '60', // seconds; default step interval is 60 seconds
     			 )
     		 ));
     */
     $form->remove('artcCreated');
     $form->remove('parent');
     $form->remove('author');
     $form->setHydrator(new DoctrineHydrator($entityManager, 'CsnCms\\Entity\\Article'));
     $send = new Element('send');
     $send->setValue($action);
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     return $form;
 }
 public function getForm($product, $entityManager, $action)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($product);
     //!!!!!! Start !!!!! Added to make the association tables work with select
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     $form->setHydrator(new DoctrineHydrator($entityManager, 'BkdRwd\\Entity\\Product'));
     $send = new Element('send');
     $send->setValue($action);
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     return $form;
 }
Example #15
0
 public function manageUserAction()
 {
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     /*		
     		 $user = new User;
     		 $user->setUsrName('Stoyan');
     		 $user->setUsrPassword('Stoyan');
     		 $user->setUsrEmail('Stoyan');
     		 $user->setUsrActive(1);
     		 $entityManager->persist($user);
     		 $entityManager->flush();
     		die('I had to create something');
     */
     // 1) Update
     //		$repository = $entityManager->getRepository('Fmi\Entity\User');
     //		$id = (int)$this->params()->fromQuery('id', 1);
     //		$user = $repository->find($id);
     // instead I will create a new object
     // For new user
     $user = new User();
     // $entityManager->persist($user);
     // $detachedEntity = unserialize($serializedEntity);
     //		$detachedEntity =  new User;
     //		$user = $entityManager->merge($detachedEntity);
     // here comes the magic
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($user);
     // var_dump($builder);
     // die('After builder');
     $form->setHydrator(new DoctrineHydrator($entityManager, 'Fmi\\Entity\\User'));
     // it works both ways. With the above line. and the line bellow
     //- $form->setHydrator(new DoctrineEntity($entityManager, 'Fmi\Entity\User'));
     $form->bind($user);
     $send = new Element('send');
     $send->setValue('Submit');
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     $viewModel = new ViewModel();
     $viewModel->setVariable('form', $form);
     return $viewModel;
 }
 public function addAction()
 {
     //var_dump('asdf');exit;
     $tMarketProduct = new TMarketProduct();
     $tProduct = new TProduct();
     //$tMarketProduct = $this->getEntityManager()->find('GDI\Entity\TMarketProduct', 20);
     //$tProduct = $this->getEntityManager()->find('GDI\Entity\TProduct', 5);
     $mGameCategory = new MGameCategory();
     //$builder = new AnnotationBuilder();
     $builder = new DoctrineAnnotationBuilder($this->getEntityManager());
     $form = $builder->createForm($tMarketProduct);
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($this->getEntityManager());
             }
         }
     }
     $form->setHydrator(new DoctrineHydrator($this->getEntityManager(), 'GDI\\Entity\\TMarketProduct'));
     $form->bind($tMarketProduct);
     /*$form->get('market')->setOptions(
       array(
       'object_manager' => $this->getEntityManager(),
       'property'       => 'marketName',
       )
       );*/
     $storeOptions['find_method'] = array('name' => 'findBy', 'params' => array('criteria' => array(), 'orderBy' => array('marketName' => 'ASC')));
     $form->get('market')->setOptions($storeOptions);
     //$form->get('isActive')->setOptions(array('continue_if_empty' => true));
     /*$gameCategormForm = $builder->createForm($mGameCategory);
       $gameCategormForm->setName('gameCategormForm');*/
     $tProductForm = $builder->createForm($tProduct);
     //$tProductForm->setName('productForm');
     $tProductForm->setHydrator(new DoctrineHydrator($this->getEntityManager(), 'GDI\\Entity\\TProduct'));
     $tProductForm->bind($tProduct);
     $subForm = new \Zend\Form\Form();
     $subForm->setName('subform');
     $subForm->add(array('name' => 'email', 'type' => 'Zend\\Form\\Element\\Text'));
     //$form->add($tProductForm);
     //var_dump($form->get('productForm')->isValid());
     //var_dump($tProductForm->getName());
     //$form->add($subForm);
     /*$form->add(array(
       'type' => 'Zend\Form\Element\Select',
       'name' => 'gender',
       'options' => array(
       'label' => 'Gender',
       'value_options' => array(
       '1' => 'Select your gender',
       '2' => 'Female',
       '3' => 'Male'
       ),
       ),
       'attributes' => array(
       'value' => '1' //set selected to '1'
       )
       ));*/
     //var_dump($form);exit;
     //$form->bind($tMarketProduct);
     $request = $this->getRequest();
     if ($request->isPost()) {
         var_dump($form->getAttributes());
         //var_dump($tProductForm->getHydrator()->extract($tProduct));
         //var_dump($tProductForm->getAttributes());
         //exit;
         $tMarketProduct->setCreateUserId(1);
         $tMarketProduct->setCreateTime(new \DateTime());
         $tMarketProduct->setUpdateUserId(1);
         //$tMarketProduct->setMarketProductId(null);
         //$product = $this->getEntityManager()->find('GDI\Entity\TProduct', 1);
         //$tMarketProduct->setProduct($product);
         //tproduct
         //$tProduct->setControlId(1);
         //$tProduct->setEArtworkSpDate(date('Y-m-d'));
         //$tProduct->setEArtworkTrDate(date('Y-m-d'));
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         //$upload = new Zend_File_Transfer_Adapter_Http();
         var_dump($post);
         //var_dump($form->get('productForm'));
         //exit
         //$form->remove('productForm');
         //$productFormClone = clone($tProductForm);
         //$form->remove('productForm');
         //$form->setInputFilter($tMarketProduct);
         $form->setData($post);
         //$tProductForm->setData($post);
         //$form->setData($request->getPost());
         //$form->getFormFactory()->
         //$form->add($productFormClone);
         //$tProductForm = $productFormClone;
         //$tProductForm->setData($request->getPost());
         //var_dump($request->getPost());
         //var_dump($form->get('productForm'));
         //exit;
         /* if ($form->get('productForm')->isValid())
            {
            die('ok');
            }else {
            }*/
         //var_dump($form->get('TMarketProduct'));
         //$form->get('productForm')->setData($request->getPost());
         //var_dump($form->get('productForm')->isValid());
         if ($form->isValid()) {
             var_dump('ok form');
             //var_dump('asdf');
             //var_dump($form->getData());
             //exit;
             //$hydrator2 = new DoctrineHydrator($this->getEntityManager());
             //$tMarketProduct = new TMarketProduct();
             //$city = $hydrator2->hydrate($form->getData(), $tMarketProduct);
             //var_dump($city);exit;
             //var_dump($tMarketProduct);
             //var_dump($form->getData());
             /*$filter = new \Zend\Filter\File\RenameUpload("./data/uploads/");
                         echo $filter->filter($post['product']['gameImagePass']);
                         // File has been moved to "./data/uploads/php5Wx0aJ"
             
                         // ... or retain the uploaded file name
                         $filter->setUseUploadName(true);
                         echo $filter->filter($filter);
                         exit;*/
             /*$tProduct->setCreateUserId(1);
                         $tProduct->setCreateTime(new \DateTime());
             
                         $this->getEntityManager()->persist($tProductForm->getData());
                         $this->getEntityManager()->flush();*/
             //$tMarketProduct->setProduct($tProduct);
             /* Uploading Document File on Server */
             /*$upload = new Zend_File_Transfer_Adapter_Http();
                         $upload->setDestination("/public/img/uploads/");
                         try {
                             // upload received file(s)
                             $upload->receive();
                         } catch (Zend_File_Transfer_Exception $e) {
                             $e->getMessage();
                         }
             
                         $uploadedData = $form->getValues();
                         var_dump($uploadedData);*/
             $uploadedData = $form->getValue();
             var_dump($uploadedData);
             var_dump($form->getData());
             $this->getEntityManager()->persist($form->getData());
             $this->getEntityManager()->flush();
             //var_dump($tProduct);
         } else {
         }
     }
     return array('form' => $form, 'tProductForm' => $tProductForm);
 }
Example #17
0
 /**
  * Update Action
  * User info change/update
  * Requires `id` as param in order to be sure what model from Database is updated
  * @return ViewModel
  */
 public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('bojev/default', array('controller' => 'index', 'action' => 'index'));
     }
     //Get the Database Mapper Adapter
     $this->_em = $this->getEntityManager();
     try {
         $repository = $this->_em->getRepository('Bojev\\Entity\\User');
         $user = $repository->find($id);
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         // this never will be seen if you don't comment the redirect
         return $this->redirect()->toRoute('bojev/default', array('controller' => 'index', 'action' => 'index'));
     }
     //get builder
     $builder = new DoctrineAnnotationBuilder($this->_em);
     //Create form out of Annotations defined in Entity User Class
     $form = $builder->createForm($user);
     //Set the Hydrator
     $form->setHydrator(new DoctrineHydrator($this->_em, 'Bojev\\Entity\\User'));
     //add Submit Button , since it's not defined into Entity
     $send = new Element('submit');
     $form->add($send);
     //Add button to the form
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->_em->persist($user);
             $this->_em->flush();
             return $this->redirect()->toRoute('bojev/default', array('controller' => 'index', 'action' => 'details', 'id' => $user->getId()));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
 public function updateAction()
 {
     // ------------------------ The block for Authorization
     $auth = new \Zend\Authentication\AuthenticationService();
     echo '<h1>hasIdentity = ' . $auth->hasIdentity() . '</h1>';
     $config = $this->getServiceLocator()->get('Config');
     $acl = new \CsnUser\Acl\Acl($config);
     $role = \CsnUser\Acl\Acl::DEFAULT_ROLE;
     if ($auth->hasIdentity()) {
         $usr = $auth->getIdentity();
         $usrl_id = $usr->usrl_id;
         // Use a view to get the name of the role
         // TODO we don't need that if the names of the roles are comming from the DB
         switch ($usrl_id) {
             case 1:
                 $role = \CsnUser\Acl\Acl::DEFAULT_ROLE;
                 // guest
                 break;
             case 2:
                 $role = 'member';
                 break;
             default:
                 $role = \CsnUser\Acl\Acl::DEFAULT_ROLE;
                 // guest
                 break;
         }
     }
     $controller = $this->params()->fromRoute('controller');
     $action = $this->params()->fromRoute('action');
     echo '<pre>';
     echo "controller = " . $controller . "\n";
     echo "action = " . $action . "\n";
     echo "role = " . $role . "\n";
     echo '</pre>';
     if (!$acl->hasResource($controller)) {
         throw new \Exception('Resource ' . $controller . ' not defined');
     }
     echo '<h1> Acl answer: ' . $acl->isAllowed($role, $controller, $action) . '</h1>';
     if (!$acl->isAllowed($role, $controller, $action)) {
         return $this->redirect()->toRoute('auth/default', array('controller' => 'index', 'action' => 'login'));
     }
     //------------------------- End the block for Authorization
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization-acl', 'action' => 'index'));
     }
     $entityManager = $this->getEntityManager();
     try {
         $repository = $entityManager->getRepository('CsnUser\\Entity\\User');
         $user = $repository->find($id);
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         // this never will be seen fi you don't comment the redirect
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization-acl', 'action' => 'index'));
     }
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($user);
     $form->setHydrator(new DoctrineHydrator($entityManager, 'CsnUser\\Entity\\User'));
     $send = new Element('send');
     $send->setValue('Edit');
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         // $form->setInputFilter(new UserFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // ToDo raplace the code with something that uses user object
             //				$data = $form->getData();
             //				$hydrator = new ReflectionHydrator();
             //				$data  = $hydrator->extract($data); // turn the object to array
             //				unset($data['submit']);
             //				if (empty($data['usr_registration_date'])) $data['usr_registration_date'] = '2013-07-19 12:00:00';
             //				$this->getUsersTable()->update($data, array('usr_id' => $id));
             $entityManager->persist($user);
             $entityManager->flush();
             return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization-acl', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
Example #19
0
 /**
  * @param Entity\Note $note
  * @param string $url
  * @param string $action
  * @param array $members
  * @return \Zend\Form\Form
  */
 public function getNoteForm(Entity\Note $note, $url = '', $action = 'add', $members = null)
 {
     if (is_null($this->noteForm)) {
         $builder = new AnnotationBuilder($this->getEntityManager());
         $this->noteForm = $builder->createForm($note);
         $this->noteForm->setAttribute('action', $url);
         $this->noteForm->setAttribute('id', 'noteForm');
         $this->noteForm->setHydrator(new DoctrineObject($this->getEntityManager(), 'Secretary\\Entity\\Note'));
         $this->noteForm->bind($note);
         if ($action == 'edit' && $note->getPrivate() === false) {
             $this->noteForm->remove('private');
             $group = $note->getGroup();
             $membersString = $this->getMembersString(array_keys($members));
             $this->noteForm->get('groupHidden')->setValue($group->getId());
             $this->noteForm->get('members')->setValue($membersString);
             $this->noteForm->getInputFilter()->remove('__initializer__');
             $this->noteForm->getInputFilter()->remove('__cloner__');
             $this->noteForm->getInputFilter()->remove('__isInitialized__');
             $this->noteForm->getInputFilter()->remove('lazyPropertiesDefaults');
         } else {
             $this->noteForm->get('private')->setAttribute('required', false);
             $this->noteForm->getInputFilter()->get('private')->setRequired(false);
         }
     }
     return $this->noteForm;
 }
 public function updateAction()
 {
     // ------------------------ The block for Authorization
     $auth = new \Zend\Authentication\AuthenticationService();
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toRoute('auth/default', array('controller' => 'index', 'action' => 'login'));
     }
     $user = $auth->getIdentity();
     $usrlId = $user->usrl_id;
     // II) Protect our action
     if ($usrlId < 3) {
         return $this->redirect()->toRoute('auth/default', array('controller' => 'index', 'action' => 'login'));
     }
     //------------------------- End the block for Authorization
     $id = $this->params()->fromRoute('id');
     if (!$id) {
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization', 'action' => 'index'));
     }
     $entityManager = $this->getEntityManager();
     try {
         $repository = $entityManager->getRepository('CsnUser\\Entity\\User');
         $user = $repository->find($id);
     } catch (\Exception $ex) {
         echo $ex->getMessage();
         // this never will be seen fi you don't comment the redirect
         return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization', 'action' => 'index'));
     }
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($user);
     $form->setHydrator(new DoctrineHydrator($entityManager, 'CsnUser\\Entity\\User'));
     $send = new Element('send');
     $send->setValue('Edit');
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         // $form->setInputFilter(new UserFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // ToDo raplace the code with something that uses user object
             //				$data = $form->getData();
             //				$hydrator = new ReflectionHydrator();
             //				$data  = $hydrator->extract($data); // turn the object to array
             //				unset($data['submit']);
             //				if (empty($data['usr_registration_date'])) $data['usr_registration_date'] = '2013-07-19 12:00:00';
             //				$this->getUsersTable()->update($data, array('usr_id' => $id));
             $entityManager->persist($user);
             $entityManager->flush();
             return $this->redirect()->toRoute('csn_user/default', array('controller' => 'user-doctrine-simple-authorization', 'action' => 'index'));
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
 public function addproductAction()
 {
     $tProduct = new TProduct();
     $builder = new DoctrineAnnotationBuilder($this->getEntityManager());
     //$form = $builder->createForm($tProduct);
     /*foreach ($form->getElements() as $element) {
           if (method_exists($element, 'getProxy')) {
               $proxy = $element->getProxy();
               if (method_exists($proxy, 'setObjectManager')) {
                   $proxy->setObjectManager($this->getEntityManager());
               }
           }
       }*/
     //$form->setHydrator(new DoctrineHydrator($this->getEntityManager(),'GDI\Entity\TMarketProduct'));
     //$form->bind($tMarketProduct);
     /* $storeOptions['find_method'] = array(
            'name'   => 'findBy',
            'params' => array(
                'criteria' => array(), // no criteria since I want the whole list
                'orderBy'  => array('marketName' => 'ASC'),
            ),
        );*/
     //$form->get('market')->setOptions($storeOptions);
     $tProductForm = $builder->createForm($tProduct);
     //$tProductForm->setName('productForm');
     //$tProductForm->add($tProductForm);
     $request = $this->getRequest();
     var_dump($request->getPost());
     return array('form' => $tProductForm);
 }
Example #22
0
 public function getForm($article, $entityManager, $action)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($article);
     $form->setAttribute('enctype', 'multipart/form-data');
     //!!!!!! Start !!!!! Added to make the association tables work with select
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     //Image article
     $titleField = new Element\File('art_image_filename');
     $titleField->setLabel('Image article');
     $form->add($titleField);
     //
     //		 $form->add(array(
     //			 'type' => 'Zend\Form\Element\Date',
     //			 'name' => 'artcCreatedDate',
     //			 'options' => array(
     //					 'label' => 'Created Date'
     //			 ),
     //			 'attributes' => array(
     //					 'min' => '2012-01-01',
     //					 'max' => '2020-01-01',
     //					 'step' => '1', // days; default step interval is 1 day
     //				 		'class' => 'datepicker'
     //			 )
     //		 ));
     //
     //		 $form->add(array(
     //			 'type' => 'Zend\Form\Element\Time',
     //			 'name' => 'artcCreatedTime',
     //			 'options'=> array(
     //					 'label' => 'Created Time'
     //			 ),
     //			 'attributes' => array(
     //					 'min' => '00:00:00',
     //					 'max' => '23:59:59',
     //					 'step' => '60', // seconds; default step interval is 60 seconds
     //			 )
     //		 ));
     $form->remove('artcCreated');
     $form->remove('parent');
     $form->remove('author');
     $form->setHydrator(new DoctrineHydrator($entityManager, 'Cms\\Entity\\Article'));
     $send = new Element('send');
     $send->setValue($action);
     // submit
     $send->setAttributes(array('type' => 'submit', 'class' => 'btn waves-effect waves-light'));
     $form->add($send);
     return $form;
 }
Example #23
0
 public function getRegistrationForm($entityManager, $user)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($user);
     $form->setHydrator(new DoctrineHydrator($entityManager, 'AuthDoctrin\\Entity\\User'));
     $filter = $form->getInputFilter();
     $form->remove('usrlId');
     $form->remove('lngId');
     $form->remove('usrActive');
     $form->remove('usrQuestion');
     $form->remove('usrAnswer');
     $form->remove('usrPicture');
     $form->remove('usrPasswordSalt');
     $form->remove('usrRegistrationDate');
     $form->remove('usrRegistrationToken');
     $form->remove('usrEmailConfirmed');
     // ... A lot of work of manually building the form
     $form->add(array('name' => 'usrPasswordConfirm', 'attributes' => array('type' => 'password'), 'options' => array('label' => 'Confirm Password')));
     $form->add(array('type' => 'Zend\\Form\\Element\\Captcha', 'name' => 'captcha', 'options' => array('label' => 'Please verify you are human', 'captcha' => new \Zend\Captcha\Figlet())));
     $send = new Element('submit');
     $send->setValue('Register');
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     // ...
     return $form;
 }
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('fmi', array('action' => 'add'));
     }
     // Get the Album with the specified id.  An exception is thrown
     // if it cannot be found, in which case go to the index page.
     $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     try {
         // $album = $this->getAlbumTable()->getAlbum($id);
         $repository = $entityManager->getRepository('Fmi\\Entity\\User');
         // $id = (int)$this->params()->fromQuery('id', 1);
         $user = $repository->find($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('fmi', array('action' => 'index'));
     }
     // Create the form
     // 2.2)
     // $form  = new AlbumForm();
     // $form->get('submit')->setAttribute('value', 'Edit');
     // 2.2)
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($user);
     $form->setHydrator(new DoctrineHydrator($entityManager, 'Fmi\\Entity\\User'));
     // it works both ways. With the above line. and the line bellow
     //- $form->setHydrator(new DoctrineEntity($entityManager, 'Fmi\Entity\User'));
     $send = new Element('send');
     $send->setValue('Edit');
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     // 3) bind
     $form->bind($user);
     $request = $this->getRequest();
     if ($request->isPost()) {
         // $form->setInputFilter($album->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             // $this->getAlbumTable()->saveAlbum($form->getData());
             $entityManager->persist($user);
             $entityManager->flush();
             // Redirect to list of albums
             return $this->redirect()->toRoute('fmi');
         }
     }
     return array('id' => $id, 'form' => $form);
 }
Example #25
0
 /**
  * @return array
  */
 public function editAction()
 {
     $this->layout('layout/modal');
     $className = $this->getEntityClassName();
     $id = (int) $this->params()->fromRoute('id');
     $entity = $this->getEntityManager()->find($className, $id);
     $builder = new AnnotationBuilder($this->getEntityManager());
     $form = $builder->createForm($entity);
     $form->setAttribute('action', $this->url()->fromRoute(null, array(), true));
     $form->setHydrator(new DoctrineHydrator($this->getEntityManager(), $className));
     $form->add(new Buttons('Edit'));
     $form->bind($entity);
     // TODO validate unique fields
     // TODO validate associations
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getEntityManager()->persist($entity);
             $this->getEntityManager()->flush();
             return $this->response;
         }
     }
     return array('singular' => $this->getDatagrid()->getSingularName(), 'plural' => $this->getDatagrid()->getPluralName(), 'form' => $form, 'entity' => $entity);
 }