本文整理汇总了PHP中Question::addAnswer方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::addAnswer方法的具体用法?PHP Question::addAnswer怎么用?PHP Question::addAnswer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Question
的用法示例。
在下文中一共展示了Question::addAnswer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: import
public static function import($file)
{
$fd = fopen($file, 'r');
$quiz = new QuaranteDeuxCases();
$quiz->title = fgets($fd);
$quiz->filename = $file;
$quiz->savetime = filemtime($file);
$level_count = 0;
while (!feof($fd)) {
$lines = array();
while (($line = trim(fgets($fd))) != '') {
$lines[] = $line;
}
if (count($lines) > 0) {
$question = new Question();
$question->setStatement(array_shift($lines));
$question->addAnswer(implode(' ', $lines), true);
$quiz->addQuestion($question, $level_count++);
}
}
while ($level_count < 7) {
$question = new Question();
$question->setStatement('');
$question->addAnswer('', true);
$quiz->addQuestion($question, $level_count++);
}
fclose($fd);
if (!$quiz->isCompleted()) {
throw new Exception("Quiz file incomplete");
}
return $quiz;
}
示例2: copy
public function copy($user_id)
{
$this->question = str_replace("\n", " ", $this->question);
$this->question = str_replace("<br>", " ", $this->question);
$id = $this->dbInsert('questions', array('item_id' => $this->item_id, 'based_on' => $this->based_on, 'mark' => $this->mark, 'difficulty' => $this->difficulty, 'diff_count' => 0, 'user_id' => $user_id, 'question' => $this->question));
$copy = new Question();
$copy->id = $id;
foreach ($this->answers as $answer) {
$copy->addAnswer(stripslashes($answer['answer']), stripslashes($answer['explanation']), $answer['is_right']);
}
return $id;
}
示例3: import
public static function import($file)
{
$quiz = new YouVSTheWorld();
$quiz->filename = $file;
$quiz->savetime = filemtime($file);
$dom = new DOMDocument();
$dom->loadXML(file_get_contents($file));
$quiz->title = $dom->getElementsByTagName('defi')->item(0)->getAttribute('titre');
if ($quiz->title == '') {
$quiz->title = trim(str_replace(array('YTW', '.xml'), '', basename($file)));
}
$questionsnodes = $dom->getElementsByTagName('question');
foreach ($questionsnodes as $level => $questionnode) {
$question = new Question();
foreach ($questionnode->childNodes as $node) {
switch ($node->nodeName) {
case 'texte':
$question->setStatement($node->textContent);
break;
case 'reponse_list':
$goodanswerindex = (int) $node->attributes->getNamedItem('rep_valid')->value - 1;
$answerindex = 0;
$question->setVerified($node->attributes->getNamedItem('verified')->value == 'true');
foreach ($node->childNodes as $answer) {
if ($answer->nodeName == 'reponse') {
$question->addAnswer($answer->textContent, $goodanswerindex == $answerindex++);
}
}
break;
}
}
$quiz->addQuestion($question, $level);
}
if (!$quiz->isCompleted()) {
throw new Exception("Quiz file incomplete");
}
return $quiz;
}
示例4: translateQuestions
public function translateQuestions($old_slide_id, $new_slide_id, $source_arr, $language)
{
$questions_array = array();
$questions = array();
$translator = new LanguageTranslator('AIzaSyBlwXdmxJZ__ZNScwe4zq5r3qh3ebXb26k');
$questions_array = $this->dbQuery('SELECT *
FROM questions INNER JOIN users on questions.user_id = users.id
WHERE questions.based_on IS NULL AND questions.mark = "accepted" AND questions.item_id=' . $old_slide_id);
if (count($questions_array)) {
foreach ($questions_array as $row) {
$question = new Question();
$question->createFromID($row['0']);
$lastId = $question->getLastRevision();
$lastRevision = new Question();
$lastRevision->createFromID($lastId);
$questions[] = $lastRevision;
}
}
if (count($questions)) {
$source = $source_arr['id'];
$target_arr = explode('-', $language);
$target = $target_arr[0];
foreach ($questions as $question) {
$answers = array();
$answers = $question->getAnswers();
$q = $question->question;
$question->question = $translator->translate($q, $target, $source);
$question->item_id = $new_slide_id;
$question->based_on = NULL;
$question->user->id = $this->user->id;
$question->id = $question->create();
if (count($answers)) {
foreach ($answers as $answer) {
$q = $answer['answer'];
$answer['answer'] = $translator->translate($q, $target, $source);
$q = $answer['explanation'];
if ($q != '') {
$answer['explanation'] = $translator->translate($q, $target, $source);
}
$question->addAnswer($answer['answer'], $answer['explanation'], $answer['is_right']);
}
}
}
}
}
示例5: importFromParsedJson
public static function importFromParsedJson(stdClass $object)
{
require_once $object->info->type . '.php';
$quiz = new $object->info->type();
$quiz->title = $object->title;
$quiz->filename = $object->filename;
$quiz->savetime = $object->savetime;
foreach ($object->questions as $levelnumber => $level) {
foreach ($level as $questionimport) {
$question = new Question();
$question->setStatement($questionimport->statement);
foreach ($questionimport->answers as $answerindex => $answer) {
if ($answerindex < $quiz->answers_by_level[$levelnumber]) {
$question->addAnswer($answer, $questionimport->goodanswerindex == $answerindex);
}
}
$question->setVerified($questionimport->verified);
$quiz->addQuestion($question, $levelnumber);
}
}
if (!$quiz->isCompleted()) {
throw new Exception("Invalid quiz data");
}
return $quiz;
}
示例6: Question
function test_getAnswers()
{
//Arrange
$test_field = "What is their name?";
$test_description = "What you want to call your character.";
$test_question = new Question($test_field, $test_description);
$test_question->save();
$test_field = "Joe GetAll";
$test_quest_id = $test_question->getId();
$test_answer = new Answer($test_field, $test_quest_id);
$test_answer->save();
//Act
$test_question->addAnswer($test_answer->getId());
//Assert
$result = $test_question->getAnswers($test_answer->getId());
$this->assertEquals($test_answer, $result[0]);
}