function question_model_test($delete)
{
    include_once "page_model.php";
    $qa_pairs = array("question" => "where would you like to go?", "answers" => array("1" => "left", "2" => "right", "3" => "south"));
    $question = new QuestionModel(PageModel::first()->id, serialize($qa_pairs), date("Y-m-d H:i:s"));
    $question->save();
    $question->print_fields();
    $qa_pairs = array("question" => "Will you open the door?", "answers" => array("1" => "yes", "2" => "no"));
    $question->set("q_and_a", serialize($qa_pairs));
    $question->save();
    $question->print_fields();
    if ($delete) {
        $question->delete();
    }
    $qm = QuestionModel::find(QuestionModel::last()->id);
    $qm->print_fields();
    QuestionModel::find(999);
}
Esempio n. 2
0
 public function answerreplyAction()
 {
     $questionid = $this->getRequest()->getParam('questionid', '0');
     $answerid = $this->getRequest()->getParam('answerid', '0');
     $informuid = $this->getRequest()->getParam('id', '0');
     $content = $this->getRequest()->getParam('content');
     $account = $_COOKIE["account"];
     $usertable = new UserModel();
     $db1 = $usertable->getAdapter();
     $questiontable = new QuestionModel();
     $db2 = $questiontable->getAdapter();
     $answertable = new AnswerModel();
     $db3 = $answertable->getAdapter();
     //查找当前用户ID
     $result = $usertable->fetchRow($db1->quoteInto('email = ?', $account))->toArray();
     $uid = $result['id'];
     //获取当前时间
     $t = time();
     $time = date("Y-m-d H:i:s", $t);
     $set = array('content' => $content, 'agrees' => 0, 'time' => $time, 'replyid' => $answerid, 'userid' => $uid, 'questionid' => $questionid, 'inform_userid' => $informuid);
     $flag0 = $answertable->insert($set);
     //更改question表中answernum值
     $result = $questiontable->find($questionid)->toArray()[0]['answernum'];
     ++$result;
     $numset = array('answernum' => $result);
     $where = $db2->quoteInto('id = ?', $questionid);
     $flag1 = $questiontable->update($numset, $where);
     if ($flag0 > 0 && $flag1 > 0) {
         $this->view->info = 'success';
     } else {
         $this->view->info = 'fail';
     }
     $this->view->id = $questionid;
     $this->_forward('result5', 'globals');
 }