user = $user; } public function getNumbers() { $difficulty = $this->difficulty(); $question = $this->getSequence($difficulty); $questionHtml = $this->htmlify($question); e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]); e107::getRender()->tablerender('Numbers', $questionHtml); } /** * Return the difficulty based on previously answered questions. * * @return int Difficulty as percent. */ private function difficulty() { $stats = e107::getDb()->retrieve("SELECT (SUM(correct)/COUNT(correct)*100) as percent,COUNT(correct) as count FROM e107.`e107_tkReport` WHERE answereddatestamp >= unix_timestamp((NOW()) - INTERVAL 1 MONTH) AND username = '$this->user' AND subject = 'numbers';"); if ($stats["count"]==0) { return 1; } else { return $stats; } } private function getSequence($difficulty) { //print_a(['slide'=>($difficulty['percent']/100)*2,'diff'=>$difficulty,'pow'=>(int)pow($difficulty['count'],($difficulty['percent']/100)*2)]); $startingNumber = mt_rand(0, (int) pow($difficulty['count'],($difficulty['percent']/100)*2)); if($difficulty['count']>=300) { $incrementalNumber = mt_rand(1, 100 ); }elseif($difficulty['count']>=200){ $incrementalNumber = mt_rand(1, 10 ); }elseif($difficulty['count']>=100){ $incrementalNumber = mt_rand(1, 5 ); }else{ $incrementalNumber = mt_rand(1, 2); } $missingNumber = mt_rand(1, 10); $TempQuestion = []; for ($i = 1; $i <= 10; $i++) { if ($i == $missingNumber) { $TempQuestion[] = "___,"; $solution = round($startingNumber); } elseif ($i == 10) { $TempQuestion[] = round($startingNumber); } else { $TempQuestion[] = round($startingNumber) . ","; } if($difficulty['percent']>=90 && $difficulty['count']>=200){ $startingNumber += round((2*$incrementalNumber)/$i); }elseif($difficulty['percent']>=80 && $difficulty['count']>=100){ $startingNumber += $incrementalNumber*($i*15); }else{ $startingNumber += $incrementalNumber; } } return [ 'answer1'=>$solution, 'question'=>$TempQuestion, 'type'=>'numbers']; } private function htmlify($question) { $frm = e107::getForm(); $fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']); $fString .= $frm->label('