Example #1
0
 function viewAction()
 {
     $tblPolling = new App_Model_Db_Table_Poll();
     $tblOption = new App_Model_Db_Table_PollOption();
     $time = time();
     $date = date("Y-m-d H:i:s", $time);
     $rowPoll = $tblPolling->fetchRow("checkedTime < '{$date}'", "checkedTime DESC");
     $this->view->rowPoll = $rowPoll;
     $rowOpt = $tblOption->fetchAll("pollGuid='{$rowPoll->guid}'", "text ASC");
     $this->view->rowOpt = $rowOpt;
 }
Example #2
0
 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');
     }
 }