student(); } if (check_class("TIMEKEEPER_TEACHER")) { $this->teacher(); } if (check_class("Main Admin")) { $this->adminDev(); } } /** * Run the sequence for admin/developer */ /** * Run the sequence for admin/developer */ private function adminDev(): void { e107::getRender()->tablerender('Developer', '================================================================='); /////////////////////// //// testing !!!!!!! /////////////////////// $sign = 'X'; $difficulty = [ 'count' => 64, 'percent' => 75 ]; if($sign=='X'||$sign=='/') { $difficulty['count'] = (int)$difficulty['count'] / 4; $difficulty['percent'] = (int)$difficulty['percent'] / 6; } if($difficulty['count'] >= 300) { $startingNumber = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2)); $endingNumber = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2)); $returnNumbers = [$startingNumber, $endingNumber]; } elseif($difficulty['count'] >= 200) { $startingNumber = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/100)*2); $endingNumber = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/100)*2); $returnNumbers = [$startingNumber, $endingNumber]; } elseif($difficulty['count'] >= 100) { $startingNumber = mt_rand(0, (int) ($difficulty['percent'])*2); $endingNumber = mt_rand(0, (int) ($difficulty['percent'])*2); $returnNumbers = [$startingNumber, $endingNumber]; } else { $startingNumber = mt_rand(0, $difficulty['count'] + 1); $endingNumber = mt_rand(0, $difficulty['count'] + 1); $returnNumbers = [$startingNumber, $endingNumber]; } print_a(['testingData'=>['$sign'=>$sign,'$difficulty[\'count\']'=>$difficulty['count'],'$difficulty[\'percent\']'=>$difficulty['percent'],'$startingNumber'=>$startingNumber,'$endingNumber'=>$endingNumber,'$returnNumbers'=>$returnNumbers]]); /////////////////////// //// Overrides !!!!!!! /////////////////////// $this->data['user'] = 'silas'; $this->getScores($this->data['user']); $this->showMessage(); $this->data['user'] = 'silas';//'gregory'; $this->getScores($this->data['user']); $this->showMessage(); $this->data['user'] = 'elliot';//'gregory'; $this->getScores($this->data['user']); $this->showMessage(); // ===================================================================== // =========== Testing area ============================================ // ===================================================================== //$difficulty = ['count'=>22,'percent'=>63.6364]; // Silas add //$difficulty = ['count'=>213,'percent'=>99.0610]; // Elliot add //$difficulty = ['count'=>21,'percent'=>33.3333]; // Silas sub //$difficulty = ['count'=>207,'percent'=>97.5845]; // Elliot sub //$difficulty = ['count'=>0,'percent'=>null]; // Silas mult $difficulty = ['count'=>201,'percent'=>98.5075]; // Elliot mult $startingNumber4 = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2)); $endingNumber4 = mt_rand(0, (int) pow($difficulty['count'], ($difficulty['percent']/100)*2)); $startingNumber3 = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/50)*2); $endingNumber3 = mt_rand(0, (int) $difficulty['count'] + ($difficulty['percent']/50)*2); $startingNumber2 = mt_rand(0, (int) ($difficulty['percent']/10)*4); $endingNumber2 = mt_rand(0, (int) ($difficulty['percent']/10)*4); $startingNumber1 = mt_rand(0, $difficulty['count'] + 5); $endingNumber1 = mt_rand(0, 10); print_a([['startingNumber1'=>$startingNumber1,'endingNumber1'=>$endingNumber1], ['startingNumber2'=>$startingNumber2,'endingNumber2'=>$endingNumber2], ['startingNumber3'=>$startingNumber3,'endingNumber3'=>$endingNumber3], ['startingNumber4'=>$startingNumber4,'endingNumber4'=>$endingNumber4],]); // ===================================================================== // =========== End Testing area ======================================== // ===================================================================== //$this->checkAnswer(); // If the last question has not been answered ask again. // if($this->getLastQuestion()){ // return; // } //$this->data['selectedSubject'] = 'addition'; //$this->getQuestion(); //$this->data['selectedSubject'] = 'subtraction'; //$this->getQuestion(); //$this->data['selectedSubject'] = 'multiplication'; $this->data['selectedSubject'] = 'continents'; $this->getQuestion(); //$this->data['selectedSubject'] = 'division'; //$this->getQuestion(); //$this->data['selectedSubject'] = 'rounding'; //$this->getQuestion(); date_default_timezone_set('Australia/Perth'); $QuestionsAnswered = e107::getDb()->retrieve('tkReport', 'COUNT(id)', 'username="elliot" ' . 'AND answereddatestamp >= "' . mktime(0, 0, 0, date('n'), date('j')) . '" ' . 'AND answereddatestamp <= "' . mktime(23, 59, 59, date('n'), date('j')) . '"'); $settings = e107::getDb()->retrieve('timekeeper', '*', 'username="elliot"'); print_a(['ElliotsCounter'=>$QuestionsAnswered,'ElliotsSettings'=>$settings]); //print_a($this->subjectsList); print_a($this->data); $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 = 'elliot' AND subject = 'multiplication';"); print_a($stats); // Look inside data bases if(false) { //e107_timekeeper //e107_timekeeperPending //e107_timekeeperQuestions //e107_timekeeperReport //e107_timekeeperScore //e107_timekeeperStatistics //e107_timekeeperStats //e107_tkLastQuestion //e107_tkReport //e107_tk_wordList //e107::getDb()->gen("SHOW TABLES;"); e107::getDb()->gen("SHOW COLUMNS FROM e107_tkReport;"); while ($row = e107::getDb()->fetch()) { print_a( $row ); } } e107::getRender()->tablerender('Developer.', '================================================================='); } /** * Run the sequence for teachers */ /** * Run the sequence for teachers */ private function teacher(): void { } /** * Run the sequence for students */ /** * Run the sequence for students */ private function student(): void { $this->checkAnswer(e107::getUser()->getLoginName()); $this->getScores(e107::getUser()->getLoginName()); $this->showMessage(); // If the last question has not been answered ask again. if($this->getLastQuestion()){ return; } $this->getSubject(); $this->getQuestion(); } /** * Check if the last question was answered and check the answer */ /** * Check if the last question was answered and check the answer * @param string $user */ private function checkAnswer($user): void { $subject = filter_input(INPUT_POST,'subject'); if(isset($subject)){ include './answerChecker2.php'; $ac = new answerChecker2(); $ac->checkQuestionSubject($subject,$user); e107::getDb()->delete('tkLastQuestion',"user = '".$user."'",true); } } /** * Get the the last question asked if available */ /** * Get the last question asked if available * @return bool */ private function getLastQuestion(): bool { $lastQuestion = e107::getDb()->retrieve("SELECT LastQuestionHtml FROM e107.`e107_tkLastQuestion` WHERE user = '".$this->data['user']."';"); //print_a(base64_decode($lastQuestion)); if(isset($lastQuestion)){ e107::getRender()->tablerender('Last Question', base64_decode($lastQuestion)); return true; } return false; } /** * Get the list of available subjects and select a random one. */ /** * Get the question based on selected subject * @return void */ private function getQuestion(): void { switch ($this->data['selectedSubject']) { case 'numbers': include './questionGenerators/math/numbers2.php'; $questionGen = new numbers2($this->data['user']); $questionGen->getNumbers(); break; case 'addition': case 'subtraction': case 'multiplication': case 'division': case 'rounding': include './questionGenerators/math/numeracy2.php'; $questionGen = new numeracy2($this->data['user'],$this->data['selectedSubject']); $questionGen->getNumeracy(); break; case 'worded_add': case 'worded_sub': case 'worded_mult': case 'worded_devi': case 'spelling': include './questionGenerators/english/spelling2.php'; $questionGen = new spelling2($this->data['user']); $questionGen->getSpellingWord(); break; case 'anagrams': include './questionGenerators/english/anagrams.php'; $questionGen = new anagrams($this->data['user']); $questionGen->getanagram(); break; case 'generalKnowledge': include './questionGenerators/general/generalKnowledge.php';//=========================== TODO:not working yet $questionGen = new generalKnowledge($this->data['user']); $questionGen->getgeneralKnowledge(); case 'elements': include './questionGenerators/science/elements2.php'; $questionGen = new elements2($this->data['user']); $questionGen->getElements(); break; case 'continents': include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet $questionGen = new continents($this->data['user']); $questionGen->getContinents(); break; case 'countries': include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet $questionGen = new elements2($this->data['user']); $questionGen->getElements(); break; case 'flags': include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet $questionGen = new elements2($this->data['user']); $questionGen->getElements(); break; case 'capitalCities': include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet $questionGen = new elements2($this->data['user']); $questionGen->getElements(); break; case 'artists': case 'malaySpelling': case 'nameBodyParts': case 'nameBodyOrgans': case 'basicFirstAid': default: print_a('An error has been detected in the question selector. Please report this and refresh the page.'); break; } } /** * Get the list of available subjects and select a random one. */ /** * Get the list of available subjects and select a random one. * @return void */ private function getSubject(): void { $usableSubjects = []; foreach ($this->subjectsList as $subjects){ foreach ($subjects as $subject){ if($subject[1]===1&&$this->data['difficulty']>=$subject[2]){ $usableSubjects[] = $subject[0]; } } } $this->data['selectedSubject'] = $usableSubjects[mt_rand('0',count($usableSubjects)-1)]; } /** * Show an initial stats message to the user. */ /** * Show an initial stats message to the user. * @return void */ private function showMessage(): void { $ns = e107::getRender(); $text = "You have answered ".$this->data['cntr']." questions this month.
" . "Your accuacy for the month is ".$this->data['percent']."%.
" . "Your difficulty is set at ".$this->data['difficulty'].".

"; $ns->tablerender('Your stats '.ucfirst($this->data['user']), $text); } /** * Get the initial values needed to generate a sane question. * @param type $user */ /** * Get the initial values needed to generate a sane question. * @param string $user * @return void */ private function getScores($user): void { $returnArray = []; $returnArray['totalQuestionCount'] = e107::getDb()->count("tkReport", "(id)", "username = '" . $user . "'"); e107::getDb()->gen("SELECT COUNT(id) as cntr, CAST((SUM(correct)/COUNT(id)*100) as DECIMAL(5,2)) as percent FROM e107.`e107_tkReport` WHERE username = '" . $user . "' AND answereddatestamp >= unix_timestamp(CURRENT_DATE() - INTERVAL 1 MONTH) AND answereddatestamp <= unix_timestamp(CURRENT_DATE() + INTERVAL 1 DAY)"); while ($row = e107::getDb()->fetch()) { $returnArray = array_merge($returnArray,$row); } $returnArray['user'] = $user; $returnArray['difficulty'] = $returnArray['totalQuestionCount']*$returnArray['percent']; $this->data = $returnArray; } }