Beispiel #1
1
 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;
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 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]);
 }
Beispiel #4
0
 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]);
 }
Beispiel #5
0
 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]);
 }
Beispiel #6
0
 /**
  * @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));
 }
Beispiel #7
0
 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]);
 }
Beispiel #8
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]);
 }
Beispiel #9
0
 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]);
 }
Beispiel #10
0
 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]);
 }
 /**
  * get form
  * 
  * @param int $id
  * @return \Zend\Form\FormInterface
  */
 public function getForm($id = 0)
 {
     if ((int) $id > 0) {
         $entity = $this->find($id);
         if ($entity) {
             $this->form->bind($entity);
         }
     }
     return $this->form;
 }
Beispiel #12
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]);
 }
Beispiel #13
0
 public function editAction()
 {
     $request = $this->getRequest();
     $page = $this->pageService->findPage($this->params('id'));
     $this->pageForm->bind($page);
     if ($request->isPost()) {
         $this->pageForm->setData($request->getPost());
         if ($this->pageForm->isValid()) {
             try {
                 $this->pageService->savePage($page);
                 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));
 }
Beispiel #14
0
 /**
  * Maps entity property to forms or child containers.
  *
  * @param \Zend\Form\FormInterface $form
  * @param \Core\Entity\EntityInterface $entity
  * @param string $property
  * @return void
  */
 protected function mapEntity($form, $entity, $property)
 {
     if (false === $property) {
         return;
     }
     if (true === $property) {
         $mapEntity = $entity;
     } else {
         if ($entity->hasProperty($property) || is_callable([$entity, "get{$property}"])) {
             $getter = "get{$property}";
             $mapEntity = $entity->{$getter}();
         } else {
             return;
         }
     }
     if ($form instanceof Container) {
         $form->setEntity($mapEntity);
     } else {
         $form->bind($mapEntity);
     }
 }
 protected function bindForm(FormInterface $form)
 {
     $form->setAttribute('type', 'create');
     $id = $this->getIdentifier();
     if ($id !== false) {
         $entity = $this->entityService->getEntityByIdentifier($id);
         if (!$entity) {
             //404
         }
         $form->setAttribute('type', 'edit');
     } else {
         $entityClass = $this->entityClass;
         $entity = new $entityClass();
     }
     $form->bind($entity);
     return $form;
 }
Beispiel #16
0
 /**
  * Maps entity property to forms or child containers.
  *
  * @param \Zend\Form\FormInterface $form
  * @param string $key
  * @param \Core\Entity\EntityInterface $entity
  * @return void
  */
 protected function mapEntity($form, $key, $entity)
 {
     if (true === $key) {
         $mapEntity = $entity;
     } elseif (isset($entity->{$key})) {
         $mapEntity = $entity->{$key};
     } else {
         return;
     }
     if ($form instanceof Container) {
         $form->setEntity($mapEntity);
     } else {
         $form->bind($mapEntity);
     }
 }