user = $user;
}
public function getContinents() {
$difficulty = $this->difficulty();
$continents = e107::getDb()->retrieve("SELECT DISTINCT `continent` FROM e107.e107_tk_countries;",'','',true);
$continents[] = ['continent'=>'Antarctica'];
$selectedContinent = $continents[array_rand($continents)];
$questionHtml = $this->makeQuestion($selectedContinent['continent']);
//e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]);
e107::getRender()->tablerender('Anagrams', $questionHtml);
}
public function makeQuestion($continent) {
return '
'.print_r(['InputVar'=>$continent],true).'
';
}
/**
* Create a spelling form using the supplied question.
* And write it into "$this->returnQuestion".
*
* @param array() $data Question data to be used.
*/
private function continentHtml($data) {
$frm = e107::getForm();
$fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']);
$fString .= $frm->label('Anagrams
') . "\n";
$fString .= $frm->label('Unjumble the letters to find the word.') . "\n";
$fString .= '';
$data['answer1'] = $data['word'];
$data['question'] = str_split($data['word']);
shuffle($data['question']);
foreach ($data['question'] as $seq) {
$fString .= $frm->label($seq . " ") . "\n";
}
$fString .= '';
$fString .= $frm->text('a1', '', 80, ['placeholder' => 'Write answer here!', 'autocomplete' => "off", 'spellcheck' => "false"]) . "\n";
$fString .= $frm->hidden('checkerData', base64_encode(json_encode($data)), ['id' => 'checkerData']);
$fString .= $frm->hidden('subject', 'anagrams', ['id' => 'subject']);
$fString .= '' . "\n";
$fString .= e107::getForm()->button('Answer', 'Check answer') . "\n";
$fString .= e107::getForm()->close();
$fString .= '';
return $fString;
}
/**
* Return the difficulty based on previously answered questions.
*
* @return array['percent','count'] Difficulty 1-13, Number of questions answered.
*/
private function difficulty() {
$stats = e107::getDb()->retrieve("SELECT (SUM(correct)/COUNT(correct)*13) as percent, COUNT(correct) as count
FROM e107.`e107_tkReport` WHERE
answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH)
AND `username` = '$this->user' AND `subject` = 'continents';"
);
if($stats["count"]>=30) {
return $stats["percent"];
} elseif($stats["count"]>=25) {
return min($stats["percent"],7);
} elseif($stats["count"]>=20) {
return min($stats["percent"],5);
} elseif($stats["count"]>=10) {
return min($stats["percent"],3);
} else {
return 1;
}
}
}