flags.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /*
  3. * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  4. * Click nbfs://nbhost/SystemFileSystem/Templates/Scripting/EmptyPHP.php to edit this template
  5. */
  6. class continents
  7. {
  8. private $user;
  9. /**
  10. * Setup new spelling engine
  11. *
  12. * @param bool $user user to supply question for.
  13. */
  14. public function __construct($user) {
  15. $this->user = $user;
  16. }
  17. public function getgeography() {
  18. $difficulty = $this->difficulty();
  19. $question = e107::getDb()->retrieve("SELECT `word`,`usage`, IFNULL(`cnt`,'0') AS Ncnt FROM
  20. (SELECT `word`,`usage` FROM e107.e107_tk_wordList WHERE `year` >= '".ceil($difficulty)."' AND `usage` != '' AND CHAR_LENGTH(`word`)>3) AS wList LEFT JOIN
  21. (SELECT `answer`,COUNT(`answer`)AS `cnt` FROM e107.e107_tkReport
  22. WHERE `answereddatestamp` > unix_timestamp((NOW()) - INTERVAL 1 MONTH) AND `username` = '".$this->user."'
  23. AND `subject` = 'anagrams' GROUP BY `answer` ORDER BY COUNT(`answer`)) AS Ans
  24. ON wList.`word` = Ans.`answer` ORDER BY IFNULL(`cnt`,'0'), RAND() LIMIT 1;");
  25. $questionHtml = $this->anagramsHtml($question);
  26. e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]);
  27. e107::getRender()->tablerender('Anagrams', $questionHtml);
  28. }
  29. /**
  30. * Create a spelling form using the supplied question.
  31. * And write it into "$this->returnQuestion".
  32. *
  33. * @param array() $data Question data to be used.
  34. */
  35. private function anagramsHtml($data) {
  36. $frm = e107::getForm();
  37. $fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']);
  38. $fString .= $frm->label('<h4>Anagrams</h4>') . "</br>\n";
  39. $fString .= $frm->label('Unjumble the letters to find the word.') . "\n";
  40. $fString .= '</br>';
  41. $data['answer1'] = $data['word'];
  42. $data['question'] = str_split($data['word']);
  43. shuffle($data['question']);
  44. foreach ($data['question'] as $seq) {
  45. $fString .= $frm->label($seq . " &nbsp; ") . "\n";
  46. }
  47. $fString .= '</br></br>';
  48. $fString .= $frm->text('a1', '', 80, ['placeholder' => 'Write answer here!', 'autocomplete' => "off", 'spellcheck' => "false"]) . "\n";
  49. $fString .= $frm->hidden('checkerData', base64_encode(json_encode($data)), ['id' => 'checkerData']);
  50. $fString .= $frm->hidden('subject', 'anagrams', ['id' => 'subject']);
  51. $fString .= '</br>' . "\n";
  52. $fString .= e107::getForm()->button('Answer', 'Check answer') . "\n";
  53. $fString .= e107::getForm()->close();
  54. $fString .= '</br></br>';
  55. return $fString;
  56. }
  57. /**
  58. * Return the difficulty based on previously answered questions.
  59. *
  60. * @return array['percent','count'] Difficulty 1-13, Number of questions answered.
  61. */
  62. private function difficulty() {
  63. $stats = e107::getDb()->retrieve("SELECT (SUM(correct)/COUNT(correct)*13) as percent, COUNT(correct) as count
  64. FROM e107.`e107_tkReport` WHERE
  65. answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH)
  66. AND `username` = '$this->user' AND `subject` = 'continents';"
  67. );
  68. if($stats["count"]>=30) {
  69. return $stats["percent"];
  70. } elseif($stats["count"]>=25) {
  71. return min($stats["percent"],7);
  72. } elseif($stats["count"]>=20) {
  73. return min($stats["percent"],5);
  74. } elseif($stats["count"]>=10) {
  75. return min($stats["percent"],3);
  76. } else {
  77. return 1;
  78. }
  79. }
  80. }