| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of spelling
- *
- * @author gregory
- */
- class spelling {
- public $state = "error";
- private $debug = false;
- private $sql;
- private $user;
- private $returnData;
- /**
- * Setup new spelling engine
- *
- * @param bool $test Enable debug mode.
- */
- public function __construct($test = false) {
-
- if ($test) {
- $this->debug = true;
- }
- $this->sql = e107::getDB();
- $this->user = e107::getUser()->getLoginName();
- $this->state = "ready";
- }
- public function getSpellingWord() {
- $difficulty = $this->difficulty();
- $query = "SELECT `word`,`usage`, IFNULL(`cnt`,'0') AS Ncnt FROM
- (SELECT `word`,`usage` FROM e107.e107_tk_wordList WHERE `year` <= '$difficulty' AND `usage` != '') 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` = '".__CLASS__."' GROUP BY `answer` ORDER BY COUNT(`answer`)) AS Ans
- ON wList.`word` = Ans.`answer`
- ORDER BY IFNULL(`cnt`,'0'), RAND() LIMIT 1;";
-
- if($this->debug) {
- $this->returnData['difficulty'] = $difficulty;
- $this->returnData['getWordSQL'] = $query;
- }
-
- $this->sql->gen($query);
- while ($row = $this->sql->fetch()) {
- $this->returnData['question'] = ['answer1' => $row['word'], 'question' => $row['usage'], 'type'=>__CLASS__];
- }
- return $this->returnData;
- }
- /**
- * Return the difficulty based on previously answered questions.
- *
- * @return int Difficulty 1-13.
- */
- private function difficulty() {
- $query = "SELECT (SUM(correct)/COUNT(correct)*13) as percent
- FROM e107.`e107_tkReport` WHERE
- answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH)
- AND `username` = '$this->user' AND `subject` = '".__CLASS__."';";
- if($this->debug) {
- $this->returnData['difficultySQL'] = $query;
- }
-
- $this->sql->gen($query);
- while ($row = $this->sql->fetch()) {
- //zprint_a(['PercentIs'=>$row["percent"]]);
- if (is_numeric($row["percent"])) {
- return $row["percent"];
- } else {
- return 1;
- }
-
- }
-
- }
- }
|