示例#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;
 }