/** * Displays a particular model. * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $election = Elections::model()->with('tokens')->findByPk($id); $duplicatevotes = Yii::app()->db->createCommand('select count(id) as votecount,token_id,candidate_id from votes group by token_id,candidate_id having count(id)>1')->queryAll(); foreach ($duplicatevotes as $duplicate) { $fixvote = new FixVotes(); $fixvote->token_id = $duplicate['token_id']; $fixvote->candidate_id = $duplicate['candidate_id']; $fixvote->votecount = $duplicate['votecount']; $fixvote->save(); $delcommand = Yii::app()->db->createCommand('delete v1 from votes v1, votes v2 where v1.id<v2.id and v1.token_id=v2.token_id and v1.candidate_id=v2.candidate_id and v1.token_id=' . $duplicate['token_id'] . ' and v1.candidate_id=' . $duplicate['candidate_id']); $delcommand->execute(); } $election->updatecount(); $this->render('view', array('model' => $this->loadModel($id))); }