user = $user; } public function getElements() { $difficulty = $this->difficulty(); $switchValue = rand(0,(int)$difficulty['percent']/20); $question = $this->elementSwitch($switchValue,$difficulty); $questionHtml = $this->htmlify($question); e107::getDb()->insert('tkLastQuestion', ['user'=>$this->user,'LastQuestionHtml'=>base64_encode($questionHtml)]); e107::getRender()->tablerender('Elements', $questionHtml); } private function elementSwitch($switchValue,$difficulty) { switch ($switchValue) { case 0: return $this->elementValues('symbol',$difficulty); break; case 1: return $this->elementValues('phase',$difficulty); break; case 2: return $this->elementValues('name',$difficulty); break; case 3: return $this->elementValues('number',$difficulty); break; case 4: default: return $this->elementValues('atomic_mass',$difficulty); break; } } /** * 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 = 'elements';"); if ($stats["count"]==0) { return 1; } else { return $stats; } } private function elementValues($sign,$difficulty) { if($difficulty['count']>=300) { $incrementalNumber = mt_rand(1, 100 ); }elseif($difficulty['count']>=200){ $incrementalNumber = mt_rand(1, 50 ); }elseif($difficulty['count']>=100){ $incrementalNumber = mt_rand(1, 20 ); }else{ $incrementalNumber = mt_rand(1, 10); } $elements = json_decode(file_get_contents('resources/periodicTable.json'), true)['elements']; $selectedElement = rand(0, (int) ($incrementalNumber * 1.18)); $TempQuestion = []; $TempQuestion['element'] = $elements[$selectedElement]; $TempQuestion[] = $selectedElement; $TempQuestion[] = $sign; return [ 'answer1'=>$TempQuestion['element'][$sign], 'question'=>$TempQuestion, 'type'=>'elements']; } private function htmlify($question) { $frm = e107::getForm(); $tp = e107::getParser(); $sc = e107::getScBatch('timekeeper', TRUE); $fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']); $fString .= $frm->label('