예제 #1
0
 /**
  * If $recruiter is set, vanilla will be false. If $recruiter is null,
  * vanilla will be true.
  */
 private static function create($text, MongoId $recruiter = null)
 {
     // Check if question already exists (model function). If so, return
     // the question.
     $existingQuestion = QuestionModel::getByExactText($text);
     if (!is_null($existingQuestion)) {
         return self::parseRawData($existingQuestion);
     }
     // Construct question with parameters.
     $vanilla = is_null($recruiter);
     $question = new Question(['text' => $text, 'recruiter' => $recruiter, 'vanilla' => $vanilla]);
     // Pass (question object or raw data?) to model to store in database with
     // custom flag.
     $id = QuestionModel::insert($question->getData());
     $question->setId($id);
     // Return created question.
     return $question;
 }
예제 #2
0
 public function addnewpostAction()
 {
     $account = $_COOKIE["account"];
     $title = $this->getRequest()->getParam('title');
     $content = $this->getRequest()->getParam('context');
     $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);
     //添加question信息
     $set = array('userid' => $uid, 'title' => $title, 'content' => $content, 'answernum' => 0, 'time' => $time);
     if ($questiontable->insert($set) > 0) {
         $this->view->info = 'success';
     } else {
         $this->view->info = 'fail';
     }
     $this->_forward('result4', 'globals');
 }