| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?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 getgeography() {
- $difficulty = $this->difficulty();
- $question = e107::getDb()->retrieve("SELECT `word`,`usage`, IFNULL(`cnt`,'0') AS Ncnt FROM
- (SELECT `word`,`usage` FROM e107.e107_tk_wordList WHERE `year` >= '".ceil($difficulty)."' AND `usage` != '' AND CHAR_LENGTH(`word`)>3) AS wList LEFT JOIN
- (SELECT `answer`,COUNT(`answer`)AS `cnt` FROM e107.e107_tkReport
- WHERE `answereddatestamp` > unix_timestamp((NOW()) - INTERVAL 1 MONTH) AND `username` = '".$this->user."'
- AND `subject` = 'anagrams' GROUP BY `answer` ORDER BY COUNT(`answer`)) AS Ans
- ON wList.`word` = Ans.`answer` ORDER BY IFNULL(`cnt`,'0'), RAND() LIMIT 1;");
-
- $questionHtml = $this->anagramsHtml($question);
-
- e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]);
-
- e107::getRender()->tablerender('Anagrams', $questionHtml);
- }
- /**
- * Create a spelling form using the supplied question.
- * And write it into "$this->returnQuestion".
- *
- * @param array() $data Question data to be used.
- */
- private function anagramsHtml($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;
- }
- }
- }
|