Esempio n. 1
0
 /**
  * Executes addVote action
  *
  * @param sfWebRequest $request
  */
 public function executeAddVote(sfWebRequest $request)
 {
     $user = $this->getUser()->getGuardUser();
     if ($user->isVoted() || $user->hasVote()->count() != 0) {
         $this->redirect('profile_p_vote1k_all');
     }
     $vote = $this->getRoute()->getObject();
     $vote->setWeight($user->getWeight() + $vote->getWeight());
     $vote->setJoins($vote->getJoins() + 1);
     $vote->save();
     $voter = new Voters();
     $voter->setUser($user);
     $voter->setVote($vote);
     $voter->save();
     VoteTable::getInstance()->setPositions();
     $this->redirect('profile_p_vote1k_all');
 }
Esempio n. 2
0
 public function executeVote(sfWebRequest $request)
 {
     $liste_id = $request->getParameter('id');
     if ($liste_id != 0) {
         $liste = $this->getRoute()->getObject();
     } else {
         $liste = 0;
     }
     if ($liste_id != 0 && !$liste) {
         $this->getUser()->setFlash('error', 'Cette liste n\'existe pas.');
     } else {
         if ($liste_id != 0 && $liste->getSemestreId() != sfConfig::get('app_portail_current_semestre')) {
             $this->getUser()->setFlash('error', 'Vous ne pouvez pas voter pour cette liste.');
         } else {
             if (!$this->isCotisant()) {
                 $this->getUser()->setFlash('error', 'Vous n\'êtes pas cotisant. Vous ne pouvez pas participer aux élections du BDE.');
             } else {
                 if (VoteTable::getInstance()->getVoteForUserAndSemestre($this->getUser()->getGuardUser()->getPrimaryKey(), sfConfig::get('app_portail_current_semestre'))->fetchOne()) {
                     $this->getUser()->setFlash('error', 'Vous avez déjà voté.');
                 } else {
                     $vote = new Vote();
                     $vote->setIp($_SERVER['REMOTE_ADDR']);
                     $vote->setSemestreId(sfConfig::get('app_portail_current_semestre'));
                     $vote->setUserId($this->getUser()->getGuardUser()->getId());
                     $vote->setLogin($this->getUser()->getGuardUser()->getUsername());
                     $vote->save();
                     if ($liste_id != 0) {
                         $pdo = Doctrine_Manager::getInstance()->getCurrentConnection()->getDbh();
                         $stmt = $pdo->prepare('UPDATE `vote_liste` SET `count`=(`count`+1) WHERE `id` = :id');
                         $stmt->bindParam(':id', $liste->getPrimaryKey(), PDO::PARAM_INT);
                         $stmt->execute();
                     }
                     $this->getUser()->setFlash('success', 'Votre vote a été pris en compte.');
                 }
             }
         }
     }
     $this->redirect('homepage');
 }
Esempio n. 3
0
 public function getVotes()
 {
     return VoteTable::getInstance()->getVotesList($this->getId());
 }
Esempio n. 4
0
 /**
  * Returns vote id or false on failure
  *
  * @return <mixed> bool|integer
  */
 public function isVoted()
 {
     $vote = VoteTable::getInstance()->getUserVotersVote($this->getId());
     if ($vote) {
         return $vote->getId();
     }
     return false;
 }