Beispiel #1
0
 /**
  * @param int $articleId
  * @return void Odstranuje propojeni clanku a ankety
  */
 public function handleDeleteArticleVote($articleId)
 {
     $em = $this->articleRepository->getEntityManager();
     $rArticle = $em->getReference(Model\Entities\Article::class, $articleId);
     $this->myVote->removeArticle($rArticle);
     $em->flush();
     $this->redirect('this');
 }
Beispiel #2
0
 /**
  * Odstraneni konkretni ankety, vcetne odpovedi
  * @param \App\Model\Entities\Vote $vote
  * @return boolean
  */
 public function deleteVote(Entities\Vote $vote)
 {
     try {
         $options = $vote->getOptions();
         //odstraneni ankety/otazky
         $this->em->remove($vote);
         //odstraneni odpovedi otazky
         foreach ($options as $option) {
             if ($option !== NULL) {
                 $this->em->remove($option);
             }
         }
         //provedeni zmen
         $result = $this->em->flush();
     } catch (\Doctrine\ORM\ORMException $e) {
         Debugger::log($e, Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @param Vote $vote
  * @param array $requestInfo
  * @param \Nette\Utils\ArrayHash $values
  * @return boolean Ulozeni hlasovani
  */
 protected function processPoll($vote, $requestInfo, $values)
 {
     $voter_id = \App\Model\Entities\Poll::generateVoteIdentificator();
     $answers = $this->parsePoll($values);
     foreach ($answers as $key => $value) {
         if ($key != 'text') {
             $myOption = $this->em->getReference(\App\Model\Entities\Option::class, $key);
         } else {
             $myOption = NULL;
         }
         $myNewPoll = new \App\Model\Entities\Poll($myOption, $value);
         $myNewPoll->setVoterIdentification($voter_id);
         $myNewPoll->setIp($requestInfo['ip']);
         $myNewPoll->setAgent($requestInfo['agent']);
         $myNewPoll->setCookie($requestInfo['cookie']);
         $vote->addPoll($myNewPoll);
     }
     try {
         $this->em->flush();
         $result = TRUE;
     } catch (\Exception $e) {
         \Tracy\Debugger::log($e, \Tracy\Debugger::INFO);
         $result = FALSE;
     }
     return $result;
 }
Beispiel #4
0
 /**
  * @param \App\Model\Entities\Vote $vote
  * @return array Vychozi hodnoty pro formular
  */
 protected function getDefaults($vote)
 {
     $result = [];
     $result['id'] = $vote->getId();
     $result['question'] = $vote->getQuestion();
     $result['type'] = $vote->getTypeVote()->getId();
     $expiration = $vote->getExpire();
     if ($expiration) {
         $result['expiration'] = $vote->getExpire()->format(self::$dateMask);
     }
     $options = $vote->getOptions();
     $result['options'] = [];
     $i = 1;
     //containery v replicatoru se cislu od jednicky
     foreach ($options as $option) {
         $result['options'][$i] = ['option' => $option->getValue()];
         $i++;
     }
     //$result['options']
     return $result;
 }