function save($aData) { $title = $aData['title'] ? $aData['title'] : ''; $tblPolling = new App_Model_Db_Table_Poll(); $tblOption = new App_Model_Db_Table_PollOption(); $newRow = $tblPolling->fetchNew(); $newRow->title = $title; $newRow->checkedTime = date("Y-m-d H:i:s"); $guid = $newRow->save(); $uid = $aData['id'] ? $aData['id'] : ''; $id = 1 + ($uid - 1); for ($j = 1; $j <= $id; $j++) { $pollingopt = $aData['polloption' . $j] ? $aData['polloption' . $j] : ''; if (empty($pollingopt)) { continue; } else { $dataNewRow = $tblOption->fetchNew(); $dataNewRow->pollGuid = $guid; $dataNewRow->text = $pollingopt; $dataNewRow->hits = 0; $dataNewRow->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'); } }