Пример #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');
 }
Пример #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');
 }
Пример #3
0
 public function exportAction()
 {
     $_type = $this->getRequest()->getParam("type");
     $_table = null;
     if ($_type === "p") {
         $_table = new ParticipantsTable();
     } else {
         if ($_type === "v") {
             $_table = new VoteTable();
         } else {
             throw new Exception("What the hell? What do you mean with that?");
         }
     }
     //TODO: Find the ZF equivalent...
     header("Content-type: application/csv");
     header("Content-Disposition: attachment; filename=export.csv");
     header("Pragma: no-cache");
     header("Expires: 0");
     $_result = $_table->toCsv();
     echo $_result;
     exit;
 }
Пример #4
0
 public function getVotes()
 {
     return VoteTable::getInstance()->getVotesList($this->getId());
 }
Пример #5
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;
 }
 public function subscriptionsAction()
 {
     if (null === $this->_participant) {
         throw new Exception("We don't like trespassers, do you know that? Either knock the door or don't come at all...");
     }
     parent::isParticipanActive();
     $this->view->title = "Votes I'm Subscribed";
     $_voteTable = new VoteTable();
     $_votes = $_voteTable->findVotesSubscribedBy($this->_participant->id);
     $_answers = array();
     $_selectedAnswers = array();
     $_forms = array();
     foreach ($_votes as $_v) {
         $_answers[$_v->id] = $_v->findAnswers();
         $_selectedAnswers[$_v->id] = $_v->isVotedBy($this->_participant->id);
         if (null === $_selectedAnswers[$_v->id]) {
             $_f = new VoteForm();
             $_f->setAnswers($_answers[$_v->id]);
             $_f->setVote($_v->id);
             $_forms[$_v->id] = clone $_f;
         }
     }
     $this->view->votes = $_votes;
     $this->view->answers = $_answers;
     $this->view->selectedAnswers = $_selectedAnswers;
     $this->view->forms = $_forms;
 }