コード例 #1
1
ファイル: Update.php プロジェクト: Indigo1337/c4d
 public function updateAction()
 {
     $request = $this->getRequest();
     $recipe = $this->readService->findById($this->params('id'));
     if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/update');
     $viewModel->setVariables(['form' => $this->form]);
     $this->form->bind($recipe);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->writeService->save($this->form->getData());
                 $this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
                 $this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     $this->layout('layout/backend');
     return $viewModel;
 }
コード例 #2
0
 public function indexAction()
 {
     $request = $this->getRequest();
     $logContent = '';
     // initialize when no submit anymore
     $data = [];
     $data['logmessage'] = $this->form->get('logmessage')->getValue();
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             $data = $this->form->getData();
             $this->loggerPriority = $data['logpriority'];
             if ($data['logformat'] !== 'simple') {
                 $this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat'];
                 unset($this->loggerConfig['writers'][0]['options']['formatter']['options']);
             }
         }
     }
     $logger = new Logger($this->loggerConfig);
     // save log data to buffer and make it variable
     ob_start();
     $logger->log((int) $this->loggerPriority, $data['logmessage']);
     $logContent = ob_get_clean();
     return new ViewModel(['form' => $this->form, 'logContent' => $logContent]);
 }
コード例 #3
0
ファイル: Manage.php プロジェクト: Indigo1337/c4d
 public function manageAction()
 {
     if (false === $this->authorizationService->isGranted('user.admin')) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $userId = $this->params('id', null);
     if (null === $userId) {
         return $this->listUsers();
     }
     $userObject = $this->userService->findById($userId);
     if (false === $userObject instanceof UserEntity) {
         return $this->listUsers();
     }
     $request = $this->getRequest();
     $viewModel = new ViewModel();
     $viewModel->setTemplate('user/update');
     $viewModel->setVariables(['form' => $this->form]);
     $this->form->bind($userObject);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $this->userService->save($this->form->getData());
                 $this->flashMessenger()->addSuccessMessage('User successfully updated');
                 return $this->redirect()->toRoute('zfcuser/manage');
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         } else {
             var_dump($this->form->getMessages());
         }
     }
     return $viewModel;
 }
コード例 #4
0
ファイル: Dashboard.php プロジェクト: zource/zource
 public function createAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->dashboardForm->setData($this->getRequest()->getPost());
         if ($this->dashboardForm->isValid()) {
             $data = $this->dashboardForm->getData();
             $this->dashboardTaskService->persistFromArray($data);
             return $this->redirect()->toRoute('dashboard/manage');
         }
     }
     return new ViewModel(['dashboardForm' => $this->dashboardForm]);
 }
コード例 #5
0
ファイル: AdminSettings.php プロジェクト: zource/zource
 public function indexAction()
 {
     $this->settingsForm->setData($this->settingsManager->getAll());
     if ($this->getRequest()->isPost()) {
         $this->settingsForm->setData($this->getRequest()->getPost());
         if ($this->settingsForm->isValid()) {
             $data = $this->settingsForm->getData();
             $this->settingsManager->set('application_title', $data['application_title']);
             $this->settingsManager->flush();
             $this->flashMessenger()->addSuccessMessage('The settings have been saved.');
             return $this->redirect()->toRoute('admin/system/settings');
         }
     }
     return new ViewModel(['settingsForm' => $this->settingsForm]);
 }
コード例 #6
0
 /**
  * Use the form to get barcode image from selected barcode object.
  */
 public function indexAction()
 {
     $request = $this->getRequest();
     //default value without post parameter
     $barcodeOptions = ['text' => '123456789'];
     $barcode = Barcode::factory('codabar', 'image', $barcodeOptions);
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             $barcodeOptions = ['text' => $this->form->getData()['barcode-object-text']];
             $barcode = Barcode::factory($this->form->getData()['barcode-object-select'], 'image', $barcodeOptions);
         }
     }
     imagegif($barcode->draw(), './data/barcode.gif');
     return new ViewModel(['form' => $this->form]);
 }
コード例 #7
0
ファイル: Request.php プロジェクト: zource/zource
 public function resetPasswordAction()
 {
     $code = $this->params('code');
     if ($code) {
         $this->resetPasswordForm->get('code')->setValue($code);
     }
     if ($this->getRequest()->isPost()) {
         $this->resetPasswordForm->setData($this->getRequest()->getPost());
         if ($this->resetPasswordForm->isValid()) {
             $data = $this->resetPasswordForm->getData();
             $this->passwordChanger->resetAccountPassword($data['code'], $data['credential']);
             return $this->redirect()->toRoute('login');
         }
     }
     return new ViewModel(['resetPasswordForm' => $this->resetPasswordForm, 'code' => $code]);
 }
コード例 #8
0
ファイル: Company.php プロジェクト: zource/zource
 public function updateAction()
 {
     $company = $this->contactService->findCompany($this->params('id'));
     if (!$company) {
         return $this->notFoundAction();
     }
     $this->contactForm->bind($company);
     if ($this->getRequest()->isPost()) {
         $this->contactForm->setData($this->getRequest()->getPost());
         if ($this->contactForm->isValid()) {
             $company = $this->contactService->persistContact($this->contactForm->getData());
             return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_COMPANY, 'id' => $company->getId()->toString()]);
         }
     }
     return new ViewModel(['company' => $company, 'contactForm' => $this->contactForm]);
 }
コード例 #9
0
ファイル: FilePostRedirectGet.php プロジェクト: tillk/vufind
 /**
  * @param  FormInterface $form
  * @param  string        $redirect      Route or URL string (default: current route)
  * @param  bool          $redirectToUrl Use $redirect as a URL string (default: false)
  * @return Response
  */
 protected function handlePostRequest(FormInterface $form, $redirect, $redirectToUrl)
 {
     $container = $this->getSessionContainer();
     $request = $this->getController()->getRequest();
     $postFiles = $request->getFiles()->toArray();
     $postOther = $request->getPost()->toArray();
     $post = ArrayUtils::merge($postOther, $postFiles, true);
     // Fill form with the data first, collections may alter the form/filter structure
     $form->setData($post);
     // Change required flag to false for any previously uploaded files
     $inputFilter = $form->getInputFilter();
     $previousFiles = $container->files ?: array();
     $this->traverseInputs($inputFilter, $previousFiles, function ($input, $value) {
         if ($input instanceof FileInput) {
             $input->setRequired(false);
         }
         return $value;
     });
     // Run the form validations/filters and retrieve any errors
     $isValid = $form->isValid();
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $errors = !$isValid ? $form->getMessages() : null;
     // Merge and replace previous files with new valid files
     $prevFileData = $this->getEmptyUploadData($inputFilter, $previousFiles);
     $newFileData = $this->getNonEmptyUploadData($inputFilter, $data);
     $postFiles = ArrayUtils::merge($prevFileData ?: array(), $newFileData ?: array(), true);
     $post = ArrayUtils::merge($postOther, $postFiles, true);
     // Save form data in session
     $container->setExpirationHops(1, array('post', 'errors', 'isValid'));
     $container->post = $post;
     $container->errors = $errors;
     $container->isValid = $isValid;
     $container->files = $postFiles;
     return $this->redirect($redirect, $redirectToUrl);
 }
コード例 #10
0
ファイル: Person.php プロジェクト: zource/zource
 public function updateAction()
 {
     $person = $this->contactService->findPerson($this->params('id'));
     if (!$person) {
         return $this->notFoundAction();
     }
     $this->contactForm->bind($person);
     if ($this->getRequest()->isPost()) {
         $this->contactForm->setData($this->getRequest()->getPost());
         if ($this->contactForm->isValid()) {
             $person = $this->contactService->persistContact($this->contactForm->getData());
             return $this->redirect()->toRoute('contacts/view', ['type' => ContactEntry::TYPE_PERSON, 'id' => $person->getId()->toString()]);
         }
     }
     return new ViewModel(['person' => $person, 'contactForm' => $this->contactForm]);
 }
コード例 #11
0
ファイル: AdminCron.php プロジェクト: zource/zource
 public function updateAction()
 {
     $cronjob = $this->cronManager->find($this->params('id'));
     if (!$cronjob) {
         return $this->notFoundAction();
     }
     $this->cronjobForm->bind($cronjob);
     if ($this->getRequest()->isPost()) {
         $this->cronjobForm->setData($this->getRequest()->getPost());
         if ($this->cronjobForm->isValid()) {
             $data = $this->cronjobForm->getData();
             $this->cronManager->persist($data);
             return $this->redirect()->toRoute('admin/system/cron');
         }
     }
     return new ViewModel(['cronjob' => $cronjob, 'cronjobForm' => $this->cronjobForm]);
 }
コード例 #12
0
ファイル: WriteController.php プロジェクト: asilich/zendtest
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $post = $this->postService->findPost($this->params('id'));
     $this->postForm->bind($post);
     if ($request->isPost()) {
         $this->postForm->setData($request->getPost());
         if ($this->postForm->isValid()) {
             try {
                 $this->postService->savePost($this->postForm->getData());
                 return $this->redirect()->toRoute('blog');
             } catch (\Exception $e) {
             }
         }
     }
     return new ViewModel(array('form' => $this->postForm));
 }
コード例 #13
0
ファイル: ClientController.php プロジェクト: DavidHavl/Ajasta
 public function editAction()
 {
     $client = $this->clientRepository->find($this->params('clientId'));
     if ($client === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $this->clientForm->bind($client);
     if ($this->getRequest()->isPost()) {
         $this->clientForm->setData($this->getRequest()->getPost());
         if ($this->clientForm->isValid()) {
             $this->clientService->persist($this->clientForm->getData());
             $this->redirect()->toRoute('clients/show', ['clientId' => $client->getId()]);
         }
     }
     return new ViewModel(['form' => $this->clientForm]);
 }
コード例 #14
0
ファイル: AdminPlugins.php プロジェクト: zource/zource
 public function indexAction()
 {
     if ($this->getRequest()->isPost()) {
         $this->installForm->setData(array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()));
         if ($this->installForm->isValid()) {
             $data = $this->installForm->getData();
             if ($data['plugin']['error'] === 0) {
                 $this->pluginManager->installFile($data['plugin']['tmp_name']);
             } else {
                 $this->pluginManager->installExternal($data['location']);
             }
             $this->flashMessenger()->addSuccessMessage('The plugin has been installed.');
             return $this->redirect()->toRoute('admin/system/plugins');
         }
     }
     return new ViewModel(['plugins' => $this->pluginManager->getPlugins(), 'installForm' => $this->installForm]);
 }
コード例 #15
0
ファイル: AdminGroups.php プロジェクト: zource/zource
 public function updateAction()
 {
     $group = $this->groupTaskService->find($this->params('id'));
     if (!$group) {
         return $this->notFoundAction();
     }
     $this->groupForm->bind($group);
     if ($this->getRequest()->isPost()) {
         $this->groupForm->setData($this->getRequest()->getPost());
         if ($this->groupForm->isValid()) {
             $group = $this->groupForm->getData();
             $this->groupTaskService->persist($group);
             $this->flashMessenger()->addSuccessMessage('The group has been updated.');
             return $this->redirect()->toRoute('admin/usermanagement/groups');
         }
     }
     return new ViewModel(['group' => $group, 'groupForm' => $this->groupForm]);
 }
コード例 #16
0
 public function editAction()
 {
     $project = $this->projectRepository->find($this->params('projectId'));
     if ($project === null) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $this->projectForm->get('client')->setValue($project->getClient()->getName());
     $this->projectForm->bind($project);
     if ($this->getRequest()->isPost()) {
         $this->projectForm->setData($this->getRequest()->getPost());
         if ($this->projectForm->isValid()) {
             $this->projectService->persist($this->projectForm->getData());
             $this->redirect()->toRoute('clients/show', ['clientId' => $project->getClient()->getId()], ['fragment' => 'project-table']);
         }
     }
     return new ViewModel(['form' => $this->projectForm]);
 }
コード例 #17
0
ファイル: WriteController.php プロジェクト: edorosh/dcms
 public function addAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->pageForm->setData($request->getPost());
         if ($this->pageForm->isValid()) {
             try {
                 $this->pageService->savePage($this->pageForm->getData());
                 return $this->redirect()->toRoute('admin');
             } catch (\Exception $e) {
                 // Some DB Error happened
                 $view = new ViewModel(array('message' => $e->getMessage()));
                 $view->setTemplate('error/error');
                 return $view;
             }
         }
     }
     return new ViewModel(array('form' => $this->pageForm));
 }
コード例 #18
0
 public function updateAction()
 {
     $application = $this->applicationService->getApplication($this->params('id'));
     if (!$application) {
         return $this->notFoundAction();
     }
     if ($application->getAccount() !== $this->zourceAccount()) {
         return $this->notFoundAction();
     }
     $this->applicationForm->bind($application);
     if ($this->getRequest()->isPost()) {
         $this->applicationForm->setData($this->getRequest()->getPost());
         if ($this->applicationForm->isValid()) {
             $updatedApplication = $this->applicationForm->getData();
             $this->applicationService->persistApplication($updatedApplication);
             return $this->redirect()->toRoute('settings/applications');
         }
     }
     return new ViewModel(['application' => $application, 'applicationForm' => $this->applicationForm]);
 }
コード例 #19
0
ファイル: Create.php プロジェクト: Indigo1337/c4d
 public function createAction()
 {
     if (false === $this->authorizationService->isGranted('recipe.add')) {
         throw new UnauthorizedException('Insufficient Permissions');
     }
     $viewModel = new ViewModel();
     $viewModel->setTemplate('recipe/add');
     $viewModel->setVariables(['form' => $this->form]);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $this->form->setData($request->getPost());
         if ($this->form->isValid()) {
             try {
                 $recipe = $this->form->getData();
                 $this->writeService->save($recipe);
                 return $this->redirect()->toRoute('recipe/read', ['id' => $recipe->getId()]);
             } catch (\Exception $e) {
                 var_dump($e->getMessage());
             }
         }
     }
     $this->layout('layout/backend');
     return $viewModel;
 }
コード例 #20
0
ファイル: PageManager.php プロジェクト: andreas-serlo/athene2
 public function editPageRepository(FormInterface $form)
 {
     $page = $form->getObject();
     if (!$form->isValid()) {
         throw new RuntimeException(print_r($form->getMessages(), true));
     }
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $formClone = clone $form;
     $formClone->bind($page);
     $formClone->setData($data);
     $formClone->isValid();
     $this->assertGranted('page.update', $page);
     $this->getObjectManager()->persist($page);
     return $page;
 }
コード例 #21
0
ファイル: AdminAccounts.php プロジェクト: zource/zource
 public function updateAction()
 {
     /** @var \ZourceUser\Entity\Account $account */
     $account = $this->accountTaskService->find($this->params('id'));
     if (!$account) {
         return $this->notFoundAction();
     }
     $this->accountForm->bind($account);
     if ($this->getRequest()->isPost()) {
         $this->accountForm->setData($this->getRequest()->getPost());
         if ($this->accountForm->isValid()) {
             $account = $this->accountForm->getData();
             $this->accountTaskService->persist($account);
             return $this->redirect()->toRoute('admin/usermanagement/accounts');
         }
     }
     return new ViewModel(['account' => $account, 'accountForm' => $this->accountForm]);
 }
コード例 #22
0
 /**
  * @param CommentInterface $comment
  * @param FormInterface    $form
  * @return CommentInterface
  * @throws Exception\RuntimeException
  */
 protected function bind(CommentInterface $comment, FormInterface $form)
 {
     if (!$form->isValid()) {
         throw new Exception\RuntimeException(print_r($form->getMessages(), true));
     }
     $processForm = clone $form;
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $processForm->bind($comment);
     $processForm->setData($data);
     if (!$processForm->isValid()) {
         throw new Exception\RuntimeException($processForm->getMessages());
     }
     return $comment;
 }
コード例 #23
0
 /**
  * @param FormInterface $form
  * @param Content       $content
  *
  * @return object|null
  */
 private function saveFormData(FormInterface $form, Content $content)
 {
     if (!$form->isValid()) {
         return $this->setLayoutMessages($form->getMessages(), 'error');
     }
     $content->setAuthor($this->UserData()->getIdentity());
     /*
      * We only need the name. All images ar stored in the same folder, based on the month and year
      */
     $content->setPreview($form->getData()->getPreview()['name']);
     /*
      * Insert categories
      */
     $contentCategories = $content->getCategory();
     if (count($contentCategories) > 0) {
         $id = $content->getId();
         $str = [];
         foreach ($contentCategories as $key => $cat) {
             $str[] = "('" . $id . "','" . $cat . "')";
         }
         $str = implode(', ', $str);
         $this->contentTable->queryBuilder()->getEntityManager()->getConnection()->exec("INSERT INTO contents_categories (content_id, category_id)\n                                                VALUES {$str}\n                                                ON DUPLICATE KEY\n                                                UPDATE content_id = VALUES(content_id), category_id = VALUES(category_id)");
     }
     $this->contentTable->saveContent($content);
     $this->setLayoutMessages('«' . $content->getTitle() . '» ' . $this->translate('SAVE_SUCCESS'), 'success');
     return $this->redirect()->toUrl('/admin/content');
 }
コード例 #24
0
 /**
  * @param TaxonomyTermInterface $object
  * @param FormInterface         $form
  * @return TaxonomyTermInterface
  * @throws \Taxonomy\Exception\RuntimeException
  */
 protected function bind(TaxonomyTermInterface $object, FormInterface $form)
 {
     if (!$form->isValid()) {
         throw new RuntimeException(print_r([$form->getMessages(), $form->getData(FormInterface::VALUES_AS_ARRAY)], true));
     }
     $processingForm = clone $form;
     $data = $form->getData(FormInterface::VALUES_AS_ARRAY);
     $processingForm->bind($object);
     $processingForm->setData($data);
     $processingForm->isValid();
     $this->objectManager->persist($object);
     return $object;
 }