function poll($aData) { $voteid = isset($aData['poll']) ? $aData['poll'] : ''; $id = $aData['id'] ? $aData['id'] : ''; $tblPolliP = new App_Model_Db_Table_PollIp(); $ip_result = $tblPolliP->fetchRow("ip='" . Pandamp_Lib_Formater::getRealIpAddr() . "' AND pollGuid='" . $id . "'"); if (!isset($ip_result)) { $rowIp = $tblPolliP->fetchNew(); $rowIp->dateOfPoll = date("Y-m-d H:i:s"); $rowIp->ip = Pandamp_Lib_Formater::getRealIpAddr(); $rowIp->voteId = $voteid; $rowIp->pollGuid = $id; $rowIp->save(); if ($voteid) { $tblPoll = new App_Model_Db_Table_Poll(); $rowPoll = $tblPoll->find($id)->current(); if ($rowPoll) { $rowPoll->voters = $rowPoll->voters + 1; $rowPoll->save(); } $tblOption = new App_Model_Db_Table_PollOption(); $rowOption = $tblOption->fetchRow("guid='{$voteid}' AND pollGuid='{$id}'"); if ($rowOption) { $rowOption->hits = $rowOption->hits + 1; $rowOption->save(); } } } }
public function editAction() { $this->_helper->layout->setLayout('layout-newpolling'); $this->preProcessSession(); $request = $this->getRequest(); $questionId = $request->getParam('pollid'); $pollingDb = new App_Model_Db_Table_Poll(); $pollingOptionDb = new App_Model_Db_Table_PollOption(); $question = $pollingDb->find($questionId)->current(); $answers = $pollingOptionDb->fetchAll("pollGuid='{$questionId}'"); $this->view->assign('question', $question); $this->view->assign('answers', $answers); if ($request->isPost()) { $title = $request->getPost('title'); $answers = $request->getPost('answers'); $purifier = new HTMLPurifier(); $question->title = $purifier->purify($title); $question->save(); if ($answers != null && $questionId != null) { $pollingOptionDb->delete(['pollGuid=?' => $questionId]); for ($i = 0; $i < count($answers); $i++) { if (empty($answers[$i])) { continue; } $dataNewRow = $pollingOptionDb->fetchNew(); $dataNewRow->pollGuid = $questionId; $dataNewRow->text = $purifier->purify($answers[$i]); $dataNewRow->hits = 0; $dataNewRow->save(); } } $this->_helper->getHelper('FlashMessenger')->addMessage('The poll has been updated successfully.'); $this->_redirect($this->view->serverUrl() . '/' . $this->view->getLanguage() . '/polling/manager/list'); } }