예제 #1
0
 public function validate($data)
 {
     $this->form->setData($data);
     $isValid = $this->form->isValid();
     $normalized = $this->form->getData();
     unset($normalized['ViewReportControl']);
     $validated = new \SSRS\Form\ValidateResult();
     $validated->isValid = $isValid;
     $validated->parameters = $normalized;
     return $validated;
 }
예제 #2
0
 /**
  * Create a new image
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $entity = new ImageEntity();
     $em = $this->getEntityManager();
     $form->bind($entity);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
     foreach (ImageEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $entity->setImage($newName);
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
         return false;
     }
 }
예제 #3
0
 /**
  * Create a new post
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $post = new PostEntity();
     $em = $this->getEntityManager();
     $form->bind($post);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     // we rename the file with a unique name
     $newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
     foreach (PostEntity::$thumbnailVariations as $variation) {
         $result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
         if (!$result) {
             $this->message = $result;
             return false;
         }
     }
     $post->setThumbnail($newName);
     $post->setPostDate("now");
     $post->setUrl($this->getPostUrl($post));
     try {
         $em->persist($post);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
         return false;
     }
 }
예제 #4
0
 public function isValid($data)
 {
     if (!empty($data['sysmap_id'])) {
         $this->_appendParamsSubform($data['sysmap_id']);
     }
     return parent::isValid($data);
 }
예제 #5
0
 /**
  * Check array notation for validators
  */
 public function testValidatorsGivenArrayKeysOnValidation()
 {
     $username = new Element('username');
     $username->addValidator('stringLength', true, array('min' => 5, 'max' => 20, 'ignore' => 'something'));
     $form = new Form(array('elements' => array($username)));
     $this->assertTrue($form->isValid(array('username' => 'abcde')));
 }
예제 #6
0
 /**
  * Validate the form
  *
  * @return bool
  * @throws Exception\DomainException
  */
 public function isValid()
 {
     $valid = parent::isValid();
     /*
      * This might seem like a bit of a hack, but this is probably the only way zend framework
      * allows us to do this.
      */
     foreach ($this->get('fields')->getFieldSets() as $fieldset) {
         if ($this->data['language_english']) {
             if (!(new NotEmpty())->isValid($fieldset->get('nameEn')->getValue())) {
                 //TODO: Return error messages
                 $valid = false;
             }
             if ($fieldset->get('type')->getValue() === '3' && !(new NotEmpty())->isValid($fieldset->get('optionsEn')->getValue())) {
                 //TODO: Return error messages
                 $valid = false;
             }
         }
         if ($this->data['language_dutch']) {
             if (!(new NotEmpty())->isValid($fieldset->get('name')->getValue())) {
                 //TODO: Return error messages
                 $valid = false;
             }
             if ($fieldset->get('type')->getValue() === '3' && !(new NotEmpty())->isValid($fieldset->get('options')->getValue())) {
                 //TODO: Return error messages
                 $valid = false;
             }
         }
     }
     $this->isValid = $valid;
     return $valid;
 }
예제 #7
0
 public function testPreserveEntitiesBoundToCollectionAfterValidation()
 {
     $this->form->setInputFilter(new \Zend\InputFilter\InputFilter());
     $fieldset = new TestAsset\ProductCategoriesFieldset();
     $fieldset->setUseAsBaseFieldset(true);
     $product = new Entity\Product();
     $product->setName('Foobar');
     $product->setPrice(100);
     $c1 = new Entity\Category();
     $c1->setId(1);
     $c1->setName('First Category');
     $c2 = new Entity\Category();
     $c2->setId(2);
     $c2->setName('Second Category');
     $product->setCategories(array($c1, $c2));
     $this->form->add($fieldset);
     $this->form->bind($product);
     $data = array('product' => array('name' => 'Barbar', 'price' => 200, 'categories' => array(array('name' => 'Something else'), array('name' => 'Totally different'))));
     $hash1 = spl_object_hash($this->form->getObject()->getCategory(0));
     $this->form->setData($data);
     $this->form->isValid();
     $hash2 = spl_object_hash($this->form->getObject()->getCategory(0));
     // Returned object has to be the same as when binding or properties
     // will be lost. (For example entity IDs.)
     $this->assertTrue($hash1 == $hash2);
 }
예제 #8
0
파일: Comment.php 프로젝트: zfury/cmf
 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return Entity\Comment|null
  * @throws \Exception
  */
 public function add(\Zend\Form\Form $form, $data)
 {
     $serviceLocator = $this->getServiceLocator();
     $entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
     $entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
     if (!$entityType) {
         throw new EntityNotFoundException();
     }
     $form->setData($data);
     if ($form->isValid()) {
         if ($entityType->getIsEnabled()) {
             $data = $form->getData();
             $comment = new Entity\Comment();
             $comment->setEntityType($entityType);
             $user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
             $comment->setUser($user);
             $comment->setComment($data['comment']);
             $entityManager->getConnection()->beginTransaction();
             try {
                 $hydrator = new DoctrineHydrator($entityManager);
                 $hydrator->hydrate($data, $comment);
                 $entityType->getComments()->add($comment);
                 $entityManager->persist($comment);
                 $entityManager->persist($entityType);
                 $entityManager->flush();
                 $entityManager->getConnection()->commit();
                 return $comment;
             } catch (\Exception $e) {
                 $entityManager->getConnection()->rollback();
                 throw $e;
             }
         }
     }
     return null;
 }
예제 #9
0
파일: User.php 프로젝트: veniva/zcms
 public function isValid($action = null, $currentUserName = null, $currentEmail = null, $editOwn = false)
 {
     if ($action == 'edit') {
         $this->getInputFilter()->get('password_fields')->get('password')->setRequired(false);
     }
     if (!empty($this->get('password_fields')->get('password')->getValue()) || $action != 'edit') {
         $this->getInputFilter()->get('password_fields')->get('password_repeat')->setRequired(true);
     }
     if ($editOwn) {
         $this->getInputFilter()->get('role')->setRequired(false);
     }
     $userEntityClassName = get_class($this->loggedInUser);
     //region attach NoRecordExists validator to the user name
     $field = 'uname';
     $validatorOptions = array('entityClass' => $userEntityClassName, 'field' => $field);
     if ($currentUserName) {
         $validatorOptions['exclude'][] = array('field' => $field, 'value' => $currentUserName);
     }
     $validator = new NoRecordExists($this->entityManager, $validatorOptions);
     $this->getInputFilter()->get($field)->getValidatorChain()->attach($validator);
     //endregion
     //region attach NoRecordExists validator to the email
     $field = 'email';
     $validatorOptions = array('entityClass' => $userEntityClassName, 'field' => $field);
     if ($currentEmail) {
         $validatorOptions['exclude'][] = array('field' => $field, 'value' => $currentEmail);
     }
     $validator = new NoRecordExists($this->entityManager, $validatorOptions);
     $this->getInputFilter()->get($field)->getValidatorChain()->attach($validator);
     //endregion
     return parent::isValid();
 }
예제 #10
0
파일: Form.php 프로젝트: Andyyang1981/pi
 /**
  * {@inheritDoc}
  *
  * Load translation for validators
  */
 public function isValid()
 {
     if ($this->hasValidated) {
         return $this->isValid;
     }
     Pi::service('i18n')->load('validator');
     return parent::isValid();
 }
예제 #11
0
 public function updateAction()
 {
     if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
         return $this->redirect()->toRoute('seo', array('action' => 'list'));
     }
     $this->seoForm->bind($seo);
     if ($this->request->isPost()) {
         $this->seoForm->setData($this->request->getPost());
         if ($this->seoForm->isValid()) {
             $this->seoService->update($this->seoForm->getData());
             $this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
             return $this->redirect()->toRoute('seo', array('action' => 'list'));
         }
     }
     $view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
     $view->setTerminal(true);
     return $view;
 }
예제 #12
0
 public function setRegisterForm(Form $registerForm)
 {
     $this->registerForm = $registerForm;
     $fm = $this->flashMessenger()->setNamespace('zfcuser-register-form')->getMessages();
     if (isset($fm[0])) {
         $this->registerForm->isValid($fm[0]);
     }
     return $this;
 }
예제 #13
0
 /**
  * Metodo para validar o isPost e isValid
  *
  * @param Form $form Formulario a ser validado
  *
  * @return int 0 -> invalid, 1 valid, 2 not isPost
  */
 public function checkFormIsValid(Form $form)
 {
     $objRequest = $this->getRequest();
     if ($objRequest->isPost()) {
         $form->setData($objRequest->getPost());
         return $form->isValid() ? self::CHECK_FORM_IS_VALID : self::CHECK_FORM_IS_NOT_VALID;
     } else {
         return self::CHECK_FORM_IS_NOT_POST;
     }
 }
예제 #14
0
 public function __invoke(Form $form)
 {
     $out = "";
     if ($form->hasValidated() && !$form->isValid()) {
         $out .= '<div class="alert alert-error">';
         $out .= '<strong>Validation problems:</strong> Please check your form input';
         $out .= '</div>';
     }
     return $out;
 }
 /**
  * Metodo para validar o isPost e isValid
  *
  * @param Form $form Formulario a ser validado
  *
  * @return Form
  */
 public function checkFormIsValid(Form $form)
 {
     $objRequest = $this->getRequest();
     if ($objRequest->isPost()) {
         $form->setData($objRequest->getPost());
         if ($form->isValid()) {
             return true;
         }
     }
     return false;
 }
예제 #16
0
파일: Auth.php 프로젝트: JoshBour/karolina
 /**
  * @param \Zend\Form\Form $form
  * @param $data
  * @return bool
  */
 public function login(&$form, $data)
 {
     $user = new User();
     $form->bind($user);
     $form->setData($data);
     if ($form->isValid()) {
         return true;
     } else {
         return false;
     }
 }
예제 #17
0
 /** {@inheritdoc} */
 public function isValid()
 {
     if (empty($_POST) and empty($_FILES) and strtoupper(@$_SERVER['REQUEST_METHOD']) == 'POST') {
         // post_max_size has been exceeded. Set a flag for further
         // evaluation and fail without further validation which would not
         // give any useful results in this situation.
         $this->_errorPostMaxSize = true;
         return false;
     }
     return parent::isValid();
 }
예제 #18
0
 public function setupForm()
 {
     $form1 = new SubForm();
     $form1->addElement('text', 'foo', array('label' => 'Sub Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('label' => 'Sub Bar: ', 'required' => true, 'validators' => array('Alpha', 'Alnum')));
     $form2 = new Form();
     $form2->addElement('text', 'foo', array('label' => 'Master Foo: ', 'required' => true, 'validators' => array('NotEmpty', 'Alpha')))->addElement('text', 'bar', array('required' => true, 'validators' => array('Alpha', 'Alnum')))->addSubForm($form1, 'sub');
     $form2->isValid(array('foo' => '', 'bar' => 'foo 2 u 2', 'sub' => array('foo' => '', 'bar' => 'foo 2 u 2')));
     $form2->setView($this->getView());
     $this->decorator->setElement($form2);
     $this->form = $form2;
     return $form2;
 }
예제 #19
0
 /**
  * createFromForm
  *
  * @param Form $form
  * @return CdliTwoStageSignup\Model\EmailVerification
  */
 public function createFromForm(Form $form)
 {
     $form->bind(new Model());
     if (!$form->isValid()) {
         return false;
     }
     $model = $form->getData();
     $model->generateRequestKey();
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('record' => $model, 'form' => $form));
     $this->getEmailVerificationMapper()->insert($model);
     return $model;
 }
예제 #20
0
 public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
 {
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $createService->create($form->getData());
             return $redirect->toRoute('admin-translate-words');
         }
     }
     $view->setForm($form);
     $view->setTemplate('translate/admin/word/edit');
     return $view;
 }
예제 #21
0
 /**
  * @param $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     if (!empty($data['setting']['aboutProfileImage']['name'])) {
         if (!($newName = FileUtilService::rename($data['setting']['aboutProfileImage'], 'images', null, "about-profile"))) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         } else {
             FileUtilService::resize($newName, 'images', 400, null, 'png');
             FileUtilService::deleteFile(ROOT_PATH . '/images/' . $newName);
         }
     }
     if (!empty($data['setting']['homeImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['homeImage'], 'images', null, "home-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['aboutImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['aboutImage'], 'images', null, "about-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['galleriesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['galleriesImage'], 'images', null, "galleries-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['servicesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['servicesImage'], 'images', null, "services-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['contactImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['contactImage'], 'images', null, "contact-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_UPDATED"]);
     return true;
 }
예제 #22
0
파일: Category.php 프로젝트: veniva/zcms
 public function isValid()
 {
     $contentCollection = $this->contentCollection;
     $contentClassName = get_class(new CategoryContent());
     //check if the 'title' field is unique in the database
     $validatorOptions = ['entityClass' => $contentClassName, 'field' => 'title', 'exclude' => null];
     if ($contentCollection instanceof Collection) {
         foreach ($contentCollection as $content) {
             $validatorOptions['exclude'][] = array('field' => 'category', 'value' => $content->getCategory());
             break;
         }
     }
     $validator = new \Application\Validator\Doctrine\NoRecordExists($this->entityManager, $validatorOptions);
     $this->getInputFilter()->get('content')->getInputFilter()->get('title')->getValidatorChain()->attach($validator);
     return parent::isValid();
 }
예제 #23
0
파일: MyForm.php 프로젝트: usban/entilocali
 /**
  * Override isValid() to set an validation group of all elements that do not
  * have an 'exclude' option, if at least one element has this option set.
  *
  * @return boolean
  */
 public function isValid()
 {
     if ($this->hasValidated) {
         return $this->isValid;
     }
     if ($this->getValidationGroup() === null) {
         // Add all non-excluded elements to the validation group
         $validationGroup = null;
         foreach ($this->getElements() as $element) {
             if ($element->getOption('exclude') !== true) {
                 $validationGroup[] = $element->getName();
             }
         }
         if ($validationGroup) {
             $this->setValidationGroup($validationGroup);
         }
     }
     return parent::isValid();
 }
예제 #24
0
파일: Listing.php 프로젝트: veniva/zcms
 public function isValid()
 {
     //region attach NoRecordExists filter to the field alias to ensure uniqueness
     $listingContent = $this->listingContentCollection;
     $listingContentClassName = isset($listingContent[0]) ? get_class($listingContent[0]) : get_class(new Entity\ListingContent());
     //check if the 'alias' field is unique in the database
     $validatorOptions = ['entityClass' => $listingContentClassName, 'field' => 'alias', 'exclude' => null];
     //if the listing's content is being edited, don't compare it's aliases
     if ($listingContent instanceof Collection) {
         foreach ($listingContent as $content) {
             $validatorOptions['exclude'][] = array('field' => 'listing', 'value' => $content->getListing());
             break;
         }
     }
     $validator = new \Application\Validator\Doctrine\NoRecordExists($this->entityManager, $validatorOptions);
     $this->getInputFilter()->get('content')->getInputFilter()->get('alias')->getValidatorChain()->attach($validator);
     //endregion
     return parent::isValid();
 }
예제 #25
0
 public function testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed()
 {
     $fieldset = new Fieldset('example');
     $fieldset->add(array('name' => 'foo'));
     // Add an hydrator that ignores if values does not exist in the
     $fieldset->setObject(new Entity\SimplePublicProperty());
     $fieldset->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     $this->form->add($fieldset);
     $this->form->setBaseFieldset($fieldset);
     $this->form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     // Add some inputs that do not belong to the base fieldset
     $this->form->add(array('type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit'));
     $object = new Entity\SimplePublicProperty();
     $this->form->bind($object);
     $this->form->setData(array('submit' => 'Confirm', 'example' => array('foo' => 'value example')));
     $this->assertTrue($this->form->isValid());
     // Make sure the object was not hydrated at the "form level"
     $this->assertFalse(isset($object->submit));
 }
예제 #26
0
 /**
  * Create a new gallery
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create(&$data, &$form)
 {
     $entity = new GalleryEntity();
     $em = $this->getEntityManager();
     if (isset($data['gallery']['images'])) {
         $data['gallery']['images'] = json_decode($data['gallery']['images'], true);
     }
     $form->bind($entity);
     $form->setData($data);
     $form->setBindOnValidate(Form::BIND_MANUAL);
     if (!$form->isValid()) {
         return false;
     }
     $entity->setName($data['gallery']['name']);
     $entity->setUrl($this->getGalleryUrl($entity));
     if (isset($data['gallery']['parentGallery']) && !empty($data['gallery']['parentGallery'])) {
         $parent = $this->getGalleryRepository()->find($data['gallery']['parentGallery']);
         if ($parent) {
             $entity->setParentGallery($parent);
         }
     }
     // WHY THE F**K DO I HAVE TO FLUSH HERE
     $em->persist($entity);
     $em->flush();
     foreach ($data['gallery']['images'] as $join) {
         $image = $this->getImageRepository()->find($join['joinId']);
         if ($image) {
             $galleryImage = new GalleryImage($join['title'], $join['position']);
             $image->addGalleries($galleryImage);
             $entity->addImages($galleryImage);
         }
     }
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_NOT_CREATED"]);
         return false;
     }
 }
예제 #27
0
파일: Storage.php 프로젝트: buse974/dms
 /**
  * {@inheritdoc}
  *
  * @param \Dms\Document\Document $document
  *
  * @see \Dms\Storage\StorageInterface::write()
  */
 public function write(\Dms\Document\Document $document)
 {
     $ret = null;
     $name = $document->getId();
     $nameMod = substr($name, 4);
     $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
     $path = $this->getBasePath() . $f;
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $p = $path . $nameMod . '.dat';
     if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) {
         $fileInput = new FileInput(key($document->getDatas()));
         $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]);
         $inputFilter = new InputFilter();
         $inputFilter->add($fileInput);
         $form = new Form();
         $form->setInputFilter($inputFilter);
         $form->setData($document->getDatas());
         if ($form->isValid()) {
             $form->getData();
         }
     } else {
         $fp = fopen($p, 'w');
         fwrite($fp, $document->getDatas());
         $document->setWeight(strlen($document->getDatas()));
         fclose($fp);
     }
     $conf_storage = $this->options->getStorage();
     if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') {
         print_r($_FILES);
         $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']);
     }
     $document->setSupport(Document::SUPPORT_FILE_STR);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name));
     $serialize = serialize($document);
     $fp = fopen($path . $nameMod . '.inf', 'w');
     $ret += fwrite($fp, $serialize);
     fclose($fp);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name));
     return $ret;
 }
예제 #28
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_no_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
     $gateway->create(Argument::any(), Argument::any())->shouldNotBeCalled();
     $form->hasValidated()->shouldBeCalled()->willreturn(false);
     $form->bind(Argument::any())->shouldBeCalled();
     $form->bindOnValidate()->shouldBeCalled();
     $form->setData(Argument::any())->shouldNotBeCalled();
     $form->isValid()->shouldNotBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setForm($form);
     $this->run(null, null)->shouldReturnAnInstanceOf('Phpro\\SmartCrud\\Service\\SmartServiceResult');
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_CREATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_CREATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_CREATE))->shouldNotBeCalled();
 }
예제 #29
0
 /**
  * Create a new user
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $user = new UserEntity();
     $em = $this->getEntityManager();
     $form->bind($user);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     $user->setPassword(UserEntity::hashPassword($user->getPassword()));
     try {
         $em->persist($user);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_NOT_CREATED"]);
         return false;
     }
 }
 /**
  * Process form
  * 
  * @return Response|null
  */
 public function processForm()
 {
     $request = $this->getRequest();
     $this->form->setData($request->getPost());
     $fm = $this->flashMessenger();
     if (!$this->form->isValid()) {
         $fm->addErrorMessage('The form was not valid. ' . var_export($this->form->getMessages(), true), 'error');
         return;
     }
     try {
         $object = $this->saveObject();
     } catch (\Exception $exception) {
     }
     if (isset($exception)) {
         $fm->addErrorMessage('The object was not saved. ' . $exception->getMessage());
         return;
     } else {
         $fm->addSuccessMessage('The object has been successfully saved!');
     }
     return $this->redirectTo($object);
 }