Example #1
0
 public function actionGenerate($id)
 {
     $station = $this->loadModel($id);
     $election = Elections::model()->findAll();
     $oldtokens = Tokens::model()->findAll('station_id=:station_id', array(':station_id' => $id));
     foreach ($oldtokens as $oldtoken) {
         Votes::model()->deleteAll('token_id=:token_id', array(':token_id' => $oldtoken->id));
     }
     Tokens::model()->deleteAll('station_id=:station_id', array(':station_id' => $id));
     $tokens = array();
     for ($i = 0; $i < $station->voters_count; $i++) {
         $token = new Tokens();
         $token->election_id = $election[0]->id;
         $token->station_id = $id;
         $token->token = $this->generatePassword();
         $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         while ($prevtoken) {
             $token->token = $this->generatePassword();
             $prevtoken = Tokens::model()->findAll('token=:token', array(':token' => $token->token));
         }
         $token->done_vote = 0;
         $token->save();
         $tokens[] = $token;
     }
     $this->render('generate', array('election' => $election[0], 'tokens' => $tokens, 'station' => $station));
 }
Example #2
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Tokens::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #3
0
 public function actionThanks()
 {
     $this->layout = "vote";
     if (isset($_POST['election_id'])) {
         $chosen = Yii::app()->session['chosenones'];
         $donevote = true;
         if (isset($_POST['token_id'])) {
             $token = Tokens::model()->find('id=:token', array(':token' => $_POST['token_id']));
             if (!$token->done_vote) {
                 $token->done_vote = 1;
                 $token->date_vote = date('Y-m-d H:i');
                 $token->save();
                 $donevote = false;
             }
         }
         if (!$donevote) {
             $seats = Seats::model()->findAll(array("condition" => "election_id=" . $_POST['election_id'], "order" => "priority asc"));
             foreach ($seats as $seat) {
                 foreach ($chosen[$seat->id] as $candidate_id) {
                     $vote = new Votes();
                     $vote->token_id = $token->id;
                     $vote->candidate_id = $candidate_id;
                     $vote->save();
                 }
             }
         }
         $this->render('thanks', array('election' => Elections::model()->find('id=:election_id', array(':election_id' => $_POST['election_id']))));
     }
 }
Example #4
0
 public function actionResultform($id)
 {
     $this->layout = 'blankback';
     $seats = Seats::model()->with(array('candidates.votes' => array('order' => 'candidates.votescount desc')))->findAll(array('condition' => 't.election_id=' . $id, 'order' => 'priority asc'));
     $election = Elections::model()->with('tokens')->findByPk($id);
     $usedtokens = Tokens::model()->used($id)->findAll();
     $mPDF1 = Yii::app()->ePdf->mpdf();
     $mPDF1->WriteHTML($this->render('resultform', array('seats' => $seats, 'election' => $election, 'usedtokens' => $usedtokens), true));
     $mPDF1->Output('results-' . $election->name . '.pdf', 'I');
 }