Exemplo n.º 1
0
 /**
  * Saves a Warclaim to the db. If the id exists the given dataset will be updated
  * @param Warclaim\Model\Warclaim $warclaim
  *
  * @throws \Exception
  */
 public function saveWarclaim(Warclaim $warclaim)
 {
     $data = ['id' => $warclaim->getId(), 'size' => $warclaim->getSize(), 'opponent' => $warclaim->getOpponent(), 'strategy' => $warclaim->getStrategy(), 'assignments' => serialize($warclaim->getAssignments()), 'cleanup' => serialize($warclaim->getCleanup()), 'info' => serialize($warclaim->getInfo()), 'open' => $warclaim->isOpen()];
     if (!$warclaim->getId()) {
         $this->tableGateway->insert($data);
     } else {
         if ($this->getWarclaim((int) $warclaim->getId())) {
             $this->tableGateway->update($data, ['id' => $warclaim->getId()]);
         } else {
             throw new \Exception('Warclaim id does not exist');
         }
     }
 }
Exemplo n.º 2
0
 public function currentAction()
 {
     $warclaim = $this->getWarclaimTable()->getCurrentWar();
     if (!$warclaim || !PermissionChecker::check(Role::MEMBER)) {
         return $this->redirect()->toRoute('warclaim', ['action' => 'nowar']);
     }
     $members = $this->getAccountTable()->getMembers();
     $session = new \Zend\Session\Container('user');
     $form = new CurrentForm($warclaim->getSize(), $session->role);
     $form->setData($warclaim->getArrayCopy());
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($warclaim->getCurrentInputFilter($warclaim->getSize()));
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $form_warclaim = new Warclaim();
             $form_warclaim->exchangeArray($form->getData());
             $service = new WarclaimService();
             $warclaim = $service->mergeWarclaims($warclaim, $form_warclaim);
             //Validate if info is filled out if a cleanup was set
             $errors = [];
             for ($i = 0; $i < $warclaim->getSize(); $i++) {
                 if ($warclaim->getCleanup()[$i] !== '' && $warclaim->getInfo()[$i] === '') {
                     $errors[$i . 'i'] = ['no_info' => 'You have to give an info, when you attack.'];
                     $form->get($i . 'i')->setMessages($errors);
                 } elseif ($warclaim->getCleanup()[$i] === '' && $warclaim->getInfo()[$i] !== '') {
                     $errors[$i . 'c'] = ['no_info' => 'You have to give a cleanup, when you give an info.'];
                     $form->get($i . 'c')->setMessages($errors);
                 }
             }
             if ($errors) {
                 return ['form' => $form, 'warclaim' => $warclaim, 'errors' => $errors, 'members' => $members, 'user' => $session];
             }
             $this->getWarclaimTable()->saveWarclaim($warclaim);
             return $this->redirect()->toRoute('warclaim');
         } else {
             $errors = $form->getMessages();
             return ['form' => $form, 'warclaim' => $warclaim, 'errors' => $errors, 'members' => $members, 'user' => $session];
         }
     }
     return ['form' => $form, 'warclaim' => $warclaim, 'user' => $session, 'members' => $members];
 }