| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHP.php to edit this template
- */
- class continents
- {
- private $user;
- /**
- * Setup new spelling engine
- *
- * @param bool $user user to supply question for.
- */
- public function __construct($user) {
- $this->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 '<pre>'.print_r(['InputVar'=>$continent],true).'</pre>';
- }
- /**
- * 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('<h4>Anagrams</h4>') . "</br>\n";
- $fString .= $frm->label('Unjumble the letters to find the word.') . "\n";
- $fString .= '</br>';
-
- $data['answer1'] = $data['word'];
- $data['question'] = str_split($data['word']);
- shuffle($data['question']);
-
- foreach ($data['question'] as $seq) {
- $fString .= $frm->label($seq . " ") . "\n";
- }
-
- $fString .= '</br></br>';
- $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 .= '</br>' . "\n";
- $fString .= e107::getForm()->button('Answer', 'Check answer') . "\n";
- $fString .= e107::getForm()->close();
- $fString .= '</br></br>';
-
- 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;
- }
- }
- }
|