setData() публичный метод

Updates the field with default data.
public setData ( array $appData ) : Form
$appData array The data formatted as expected for the underlying object
Результат Form The current form
 /**
  * @param EntityManager $user
  *
  * @return bool
  */
 public function process(ProjetModel $projet)
 {
     $this->form->setData($projet);
     if ('POST' == $this->request->getMethod()) {
         $this->form->bind($this->request);
         if ($this->form->isValid()) {
             $projet->setUser($this->connectedUser);
             ############ Edit settings ##############
             $DestinationDirectory = __DIR__ . '/../../../../../web/uploads/';
             //specify upload directory ends with / (slash)
             $Quality = 90;
             //jpeg quality
             ##########################################
             //Let's check allowed $ImageType, we use PHP SWITCH statement here
             $ext = $projet->file->getMimeType();
             switch (strtolower($projet->file->getMimeType())) {
                 case 'image/png':
                     //Create a new image from file
                     $CreatedImage = imagecreatefrompng($projet->file->getRealPath());
                     break;
                 case 'image/gif':
                     $CreatedImage = imagecreatefromgif($projet->file->getRealPath());
                     break;
                 case 'image/jpeg':
                 case 'image/pjpeg':
                     $CreatedImage = imagecreatefromjpeg($projet->file->getRealPath());
                     break;
                 default:
                     die('Unsupported File!');
                     //output error and exit
             }
             // Crop and save image to upload directory
             $cropService = $this->cropper;
             $destImage = uniqid() . '.' . $projet->file->guessExtension();
             if (!$cropService->cropImage($projet->getX(), $projet->getY(), $projet->getW(), $projet->getH(), $DestinationDirectory . $destImage, $CreatedImage, $Quality, $projet->file->getMimeType())) {
                 die('Erreur lors du rognage de l\'image');
             }
             $projet->setPhoto($destImage);
             // Create entity project
             $entity = new Projet();
             $entity->setNomprojet($projet->getNomprojet());
             $entity->setDescription($projet->getDescription());
             $entity->setDuree($projet->getDuree());
             $entity->setDaterealisation($projet->getDaterealisation());
             $entity->setGains($projet->getGains());
             $entity->setFinancement($projet->getFinancement());
             $entity->setPhoto($projet->getPhoto());
             $entity->setCout($projet->getCout());
             $entity->setUser($projet->getUser());
             $this->entityManager->persist($entity);
             $this->entityManager->flush();
             return true;
         }
     }
     return false;
 }
Пример #2
0
 /**
  * @param UserInterface $user
  *
  * @return bool
  */
 public function process(UserInterface $user)
 {
     $this->form->setData($user);
     if ('POST' == $this->request->getMethod()) {
         $this->form->bind($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($user);
             return true;
         }
         // Reloads the user to reset its username. This is needed when the
         // username or password have been changed to avoid issues with the
         // security layer.
         $this->userManager->reloadUser($user);
     }
     return false;
 }
 /**
  * checkFilters
  * 
  * Build filters form
  * If the method POST filters are constructed and written to the session
  * else if in session is a form of filter-it is Otherwise,
  * if there is a default filters-they are  
  * 
  * @param array $default (stand default filter (option))
  * @return 
  */
 protected function checkFilters($default = array())
 {
     if ($this->filter_fields) {
         $this->filter_form = $this->createForm(new BuilderFormFilterType($this->filter_fields));
         if (count($default)) {
             $this->filter_form->setData($default);
         }
         $method = $this->query instanceof NativeQuery ? 'buildNativeQuery' : 'buildQuery';
         if ($this->get('request')->getMethod() == 'POST') {
             $this->get('session')->remove('_filter_' . $this->get('request')->get('_route'));
             $this->get('session')->remove('_pager_' . $this->get('request')->get('_route'));
             $this->filter_form->bind($this->get('request'));
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
             $filterService = $this->get('zk2_admin_panel.form_filter_session');
             $filterService->serialize($this->filter_form->getData(), '_filter_' . $this->get('request')->get('_route'));
         } elseif ($this->get('session')->has('_filter_' . $this->get('request')->get('_route'))) {
             $filterService = $this->get('zk2_admin_panel.form_filter_session');
             $data = $filterService->unserialize('_filter_' . $this->get('request')->get('_route'), $this->em_name);
             $this->filter_form->setData($data);
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
         } elseif (count($default)) {
             $this->get('zk2_admin_panel.query_builder')->{$method}($this->filter_form, $this->query);
         }
     }
 }
 public function setData($collection)
 {
     if (!is_array($collection) && !$collection instanceof \Traversable) {
         throw new UnexpectedTypeException($collection, 'array or \\Traversable');
     }
     foreach ($this as $name => $field) {
         if (!$this->getOption('modifiable') || '$$key$$' != $name) {
             $this->remove($name);
         }
     }
     foreach ($collection as $name => $value) {
         $this->add($this->newField($name, $name));
     }
     parent::setData($collection);
 }
 /**
  * {@inheritDoc}
  */
 public function process(Request $request, Form $form, UserResponseInterface $userInformation)
 {
     $user = $this->userManager->createUser();
     // Try to get some properties for the initial form when coming from github
     if ('GET' === $request->getMethod()) {
         $user->setUsername($this->getUniqueUsername($userInformation->getNickname()));
         $user->setEmail($userInformation->getEmail());
     }
     $form->setData($user);
     if ('POST' === $request->getMethod()) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $randomPassword = $this->tokenGenerator->generateToken();
             $user->setPlainPassword($randomPassword);
             $user->setEnabled(true);
             $apiToken = substr($this->tokenGenerator->generateToken(), 0, 20);
             $user->setApiToken($apiToken);
             return true;
         }
     }
     return false;
 }
 /**
  * Takes a form and query builder and returns filtered and paginated entities
  * @param QueryBuilder   $filterBuilder
  * @param Form           $form
  * @param string         $session_key
  * @param int            $limit
  * @param int            $page_number
  *
  * @return mixed
  */
 public function filterNate($filterBuilder, &$form, $session_key, $limit = 5, $page_number = 1)
 {
     $em = $this->container->get('doctrine')->getManager();
     $paginator = $this->container->get('knp_paginator');
     $lexik = $this->container->get('lexik_form_filter.query_builder_updater');
     $session = $this->container->get('session');
     $request = $this->container->get('request');
     if ($request->getMethod() == "POST") {
         // bind values from the request
         $form->bind($request);
         // build the query from the given form object
         $session->set("filternator_{$session_key}", $form->getData());
     } else {
         if ($session->has("filternator_{$session_key}")) {
             $data = $session->get("filternator_{$session_key}");
             $this->manageObjects($data, $em);
             $form->setData($data);
         }
     }
     $lexik->addFilterConditions($form, $filterBuilder);
     $entities = $filterBuilder->getQuery()->getResult();
     $pagination = $paginator->paginate($entities, $request->query->get('page', $page_number), $limit);
     return $pagination;
 }
Пример #7
0
    public function getForm()
    {
        $instance = new Form(
            $this->getName(),
            $this->buildDispatcher(),
            $this->getTypes(),
            $this->getClientTransformers(),
            $this->getNormTransformers(),
            $this->getDataMapper(),
            $this->getValidators(),
            $this->getRequired(),
            $this->getReadOnly(),
            $this->getErrorBubbling(),
            $this->getEmptyData(),
            $this->getAttributes()
        );

        foreach ($this->buildChildren() as $child) {
            $instance->add($child);
        }

        if ($this->getData()) {
            $instance->setData($this->getData());
        }

        return $instance;
    }
Пример #8
0
 public function testSubformAlwaysInsertsIntoArrays()
 {
     $ref1 = new Author();
     $ref2 = new Author();
     $author = array('referenceCopy' => $ref1);
     $form = new Form('author', array('validator' => $this->createMockValidator()));
     $form->setData($author);
     $refForm = new FormTest_FormThatReturns('referenceCopy');
     $refForm->setReturnValue($ref2);
     $form->add($refForm);
     $form->bind($this->createPostRequest(array('author' => array('referenceCopy' => array()))));
     // the new reference was inserted into the array
     $author = $form->getData();
     $this->assertSame($ref2, $author['referenceCopy']);
 }
Пример #9
0
 /**
  * @expectedException \Symfony\Component\Form\Exception\RuntimeException
  */
 public function testSetDataCannotInvokeItself()
 {
     // Cycle detection to prevent endless loops
     $config = new FormConfigBuilder('name', 'stdClass', $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $event->getForm()->setData('bar');
     });
     $form = new Form($config);
     $form->setData('foo');
 }
Пример #10
0
 /**
  * {@inheritDoc}
  */
 public function setData($data)
 {
     if ($this->mode === self::FORM) {
         parent::setData($data);
     } else {
         Field::setData($data);
     }
 }
Пример #11
0
 /**
  * @expectedException Symfony\Component\Form\Exception\FormException
  */
 public function testClientDataMustBeObjectIfDataClassIsSet()
 {
     $config = new FormConfig('name', 'stdClass', $this->dispatcher);
     $config->addViewTransformer(new FixedDataTransformer(array('' => '', 'foo' => array('bar' => 'baz'))));
     $form = new Form($config);
     $form->setData('foo');
 }
Пример #12
0
 public function testUpdatePropertyIsNotIgnoredIfFormHasNoObject()
 {
     $author = new Author();
     $child = new Author();
     $form = new Form('child');
     $form->setData($child);
     $form->updateProperty($author);
     // $author->child was set
     $this->assertSame($child, $author->child);
 }