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 addAction() { $this->_helper->layout->setLayout('layout-newpolling'); $this->preProcessSession(); $request = $this->getRequest(); if ($request->isPost()) { $title = $request->getPost('title'); $answers = $request->getPost('answers'); $pollingDb = new App_Model_Db_Table_Poll(); $pollingOptionDb = new App_Model_Db_Table_PollOption(); $newRow = $pollingDb->fetchNew(); $newRow->title = $title; $newRow->checkedTime = date("Y-m-d H:i:s"); $guid = $newRow->save(); for ($i = 0; $i < count($answers); $i++) { $dataNewRow = $pollingOptionDb->fetchNew(); $dataNewRow->pollGuid = $guid; $dataNewRow->text = $answers[$i]; $dataNewRow->hits = 0; $dataNewRow->save(); } $this->_helper->getHelper('FlashMessenger')->addMessage('The poll has been added successfully.'); $this->_redirect($this->view->serverUrl() . '/' . $this->view->getLanguage() . '/polling/manager/list'); } }