|
@@ -1,307 +1,164 @@
|
|
|
<?php
|
|
<?php
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * TimeKeeper front page controller: shows the student's stats, checks a
|
|
|
|
|
+ * submitted answer, and asks a question generator for the next question.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Changes from the current repo version:
|
|
|
|
|
+ * - removed adminDev(): for every Main Admin it ran on every page load,
|
|
|
|
|
+ * printed debug dumps (the students' settings and stats, test numbers),
|
|
|
|
|
+ * hard-coded two students' user names, set the time zone, and generated a
|
|
|
|
|
+ * question from the unfinished "continents" generator
|
|
|
|
|
+ * - checkAnswer() called delete(..., true): the third argument is e107's
|
|
|
|
|
+ * debug flag, so the SQL was printed on the page after every answer.
|
|
|
|
|
+ * It's gone, and the user name is escaped
|
|
|
|
|
+ * - generators are loaded with require_once and an absolute path (include
|
|
|
|
|
+ * plus ./relative paths depended on the working directory and could
|
|
|
|
|
+ * redeclare a class)
|
|
|
|
|
+ * - getQuestion(): generalKnowledge fell through into elements (no break);
|
|
|
|
|
+ * countries/flags/capitalCities built an elements2 object after including
|
|
|
|
|
+ * continents.php (class not found). Subjects that aren't built yet now
|
|
|
|
|
+ * show a plain message instead
|
|
|
|
|
+ * - getScores()/getLastQuestion(): MPREFIX instead of `e107.e107_...`, user
|
|
|
|
|
+ * escaped, and a student with no answers this month gets zeros (not
|
|
|
|
|
+ * null) for the stats
|
|
|
|
|
+ * - showMessage(): user name escaped
|
|
|
|
|
+ * - someone with neither the student nor the teacher class now sees a
|
|
|
|
|
+ * message instead of an empty page
|
|
|
|
|
+ */
|
|
|
require_once __DIR__ . '/TkAnswerStore.php';
|
|
require_once __DIR__ . '/TkAnswerStore.php';
|
|
|
|
|
|
|
|
class TK2 {
|
|
class TK2 {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private $data = [];
|
|
private $data = [];
|
|
|
private $subjectsList = [
|
|
private $subjectsList = [
|
|
|
// Math
|
|
// Math
|
|
|
- [['numbers',1,0],// number sequences
|
|
|
|
|
- ['addition',1,10000],// Numeracy adding
|
|
|
|
|
- ['subtraction',1,20000],// Numeracy minus'
|
|
|
|
|
- ['multiplication',1,200000],// Numeracy times'
|
|
|
|
|
- ['division',0,0],// Numeracy deviding
|
|
|
|
|
- ['rounding',0,0],// Numeracy rounding
|
|
|
|
|
- ['worded_add',0,0],// Numeracy worded adding
|
|
|
|
|
- ['worded_sub',0,0],// Numeracy worded minusing
|
|
|
|
|
- ['worded_mult',0,0],// Numeracy worded timesing
|
|
|
|
|
- ['worded_devi',0,0],// Numeracy worded deviding
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['numbers', 1, 0], // number sequences
|
|
|
|
|
+ ['addition', 1, 10000], // Numeracy adding
|
|
|
|
|
+ ['subtraction', 1, 20000], // Numeracy minus'
|
|
|
|
|
+ ['multiplication', 1, 200000], // Numeracy times'
|
|
|
|
|
+ ['division', 0, 0], // Numeracy deviding
|
|
|
|
|
+ ['rounding', 0, 0], // Numeracy rounding
|
|
|
|
|
+ ['worded_add', 0, 0], // Numeracy worded adding
|
|
|
|
|
+ ['worded_sub', 0, 0], // Numeracy worded minusing
|
|
|
|
|
+ ['worded_mult', 0, 0], // Numeracy worded timesing
|
|
|
|
|
+ ['worded_devi', 0, 0], // Numeracy worded deviding
|
|
|
|
|
+ ],
|
|
|
// English
|
|
// English
|
|
|
- [['spelling',1,0],// Plain spelling
|
|
|
|
|
- ['anagrams',1,4000000],// Shuffle letters in a word
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['spelling', 1, 0], // Plain spelling
|
|
|
|
|
+ ['anagrams', 1, 4000000], // Shuffle letters in a word
|
|
|
|
|
+ ],
|
|
|
// General knowledge
|
|
// General knowledge
|
|
|
- [['generalKnowledge',0,0],// Name kinda says it all
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['generalKnowledge', 0, 0], // Name kinda says it all
|
|
|
|
|
+ ],
|
|
|
// Science
|
|
// Science
|
|
|
- [['elements',1,150000],// Periodic table of elements
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['elements', 1, 150000], // Periodic table of elements
|
|
|
|
|
+ ],
|
|
|
// Geography
|
|
// Geography
|
|
|
- [['continents',0,0],// Point to the continent
|
|
|
|
|
- ['countries',0,0],// Point to the country
|
|
|
|
|
- ['flags',0,0],// Name the country by the flag picture
|
|
|
|
|
- ['capitalCities',0,0],// Name the capital for a country
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['continents', 0, 0], // Point to the continent
|
|
|
|
|
+ ['countries', 0, 0], // Point to the country
|
|
|
|
|
+ ['flags', 0, 0], // Name the country by the flag picture
|
|
|
|
|
+ ['capitalCities', 0, 0], // Name the capital for a country
|
|
|
|
|
+ ],
|
|
|
// History
|
|
// History
|
|
|
-
|
|
|
|
|
// Art
|
|
// Art
|
|
|
- [['artists',0,0],// Name the artist for famous paintings
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['artists', 0, 0], // Name the artist for famous paintings
|
|
|
|
|
+ ],
|
|
|
// Technology
|
|
// Technology
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
// language
|
|
// language
|
|
|
- [['malaySpelling',0,0],// This could be interesting
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['malaySpelling', 0, 0], // This could be interesting
|
|
|
|
|
+ ],
|
|
|
// Health - Health and Physical Education
|
|
// Health - Health and Physical Education
|
|
|
- [['nameBodyParts',0,0],// Name the body parts from the images or point to the part
|
|
|
|
|
- ['nameBodyOrgans',0,0],// Name the organs or what they do
|
|
|
|
|
- ['basicFirstAid',0,0],// Some BASIC things to know for first aid
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ [['nameBodyParts', 0, 0], // Name the body parts from the images or point to the part
|
|
|
|
|
+ ['nameBodyOrgans', 0, 0], // Name the organs or what they do
|
|
|
|
|
+ ['basicFirstAid', 0, 0], // Some BASIC things to know for first aid
|
|
|
|
|
+ ],
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Run the timekeeper functionality
|
|
* Run the timekeeper functionality
|
|
|
*/
|
|
*/
|
|
|
public function run(): void {
|
|
public function run(): void {
|
|
|
- if (check_class("TIMEKEEPER_STUDENT")) {
|
|
|
|
|
|
|
+ $isStudent = check_class("TIMEKEEPER_STUDENT");
|
|
|
|
|
+ $isTeacher = check_class("TIMEKEEPER_TEACHER");
|
|
|
|
|
+
|
|
|
|
|
+ if ($isStudent) {
|
|
|
$this->student();
|
|
$this->student();
|
|
|
}
|
|
}
|
|
|
- if (check_class("TIMEKEEPER_TEACHER")) {
|
|
|
|
|
|
|
+ if ($isTeacher) {
|
|
|
$this->teacher();
|
|
$this->teacher();
|
|
|
}
|
|
}
|
|
|
- if (check_class("Main Admin")) {
|
|
|
|
|
- $this->adminDev();
|
|
|
|
|
|
|
+ if (!$isStudent && !$isTeacher) {
|
|
|
|
|
+ e107::getRender()->tablerender('TimeKeeper', USER ? 'Your account has no TimeKeeper role (student or teacher).' : 'Please log in to use TimeKeeper.');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 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
|
|
* Run the sequence for teachers
|
|
|
*/
|
|
*/
|
|
|
private function teacher(): void {
|
|
private function teacher(): void {
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Run the sequence for students
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Run the sequence for students
|
|
* Run the sequence for students
|
|
|
*/
|
|
*/
|
|
|
private function student(): void {
|
|
private function student(): void {
|
|
|
-
|
|
|
|
|
- $this->checkAnswer(e107::getUser()->getLoginName());
|
|
|
|
|
-
|
|
|
|
|
- $this->getScores(e107::getUser()->getLoginName());
|
|
|
|
|
|
|
+ $user = e107::getUser()->getLoginName();
|
|
|
|
|
+
|
|
|
|
|
+ $this->checkAnswer($user);
|
|
|
|
|
+
|
|
|
|
|
+ $this->getScores($user);
|
|
|
$this->showMessage();
|
|
$this->showMessage();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// If the last question has not been answered ask again.
|
|
// If the last question has not been answered ask again.
|
|
|
- if($this->getLastQuestion()){
|
|
|
|
|
|
|
+ if ($this->getLastQuestion()) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->getSubject();
|
|
$this->getSubject();
|
|
|
$this->getQuestion();
|
|
$this->getQuestion();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Check if the last question was answered and check the answer
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 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
|
|
* @param string $user
|
|
|
*/
|
|
*/
|
|
|
private function checkAnswer($user): void {
|
|
private function checkAnswer($user): void {
|
|
|
- $subject = filter_input(INPUT_POST,'subject');
|
|
|
|
|
- if(isset($subject)){
|
|
|
|
|
- include './answerChecker2.php';
|
|
|
|
|
|
|
+ $subject = filter_input(INPUT_POST, 'subject');
|
|
|
|
|
+ if (is_string($subject) && $subject !== '') {
|
|
|
|
|
+ require_once __DIR__ . '/answerChecker2.php';
|
|
|
$ac = new answerChecker2();
|
|
$ac = new answerChecker2();
|
|
|
- $ac->checkQuestionSubject($subject,$user);
|
|
|
|
|
- e107::getDb()->delete('tkLastQuestion',"user = '".$user."'",true);
|
|
|
|
|
|
|
+ $ac->checkQuestionSubject($subject, $user);
|
|
|
|
|
+
|
|
|
|
|
+ $db = e107::getDb();
|
|
|
|
|
+ $db->delete('tkLastQuestion', "user = '" . $db->escape($user) . "'");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Get the the last question asked if available
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * Get the last question asked if available
|
|
|
|
|
- * @return bool
|
|
|
|
|
|
|
+ * Show the last question asked if it hasn't been answered.
|
|
|
|
|
+ * @return bool True when a question was shown.
|
|
|
*/
|
|
*/
|
|
|
private function getLastQuestion(): 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)){
|
|
|
|
|
|
|
+ $db = e107::getDb();
|
|
|
|
|
+ $lastQuestion = $db->retrieve("SELECT LastQuestionHtml FROM `" . MPREFIX . "tkLastQuestion` WHERE user = '" . $db->escape($this->data['user']) . "' ORDER BY id DESC LIMIT 1");
|
|
|
|
|
+
|
|
|
|
|
+ if (!empty($lastQuestion)) {
|
|
|
e107::getRender()->tablerender('Last Question', base64_decode($lastQuestion));
|
|
e107::getRender()->tablerender('Last Question', base64_decode($lastQuestion));
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Get the list of available subjects and select a random one.
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Get the question based on selected subject
|
|
* Get the question based on selected subject
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
private function getQuestion(): void {
|
|
private function getQuestion(): void {
|
|
|
switch ($this->data['selectedSubject']) {
|
|
switch ($this->data['selectedSubject']) {
|
|
|
- case 'numbers':
|
|
|
|
|
- include './questionGenerators/math/numbers2.php';
|
|
|
|
|
|
|
+ case 'numbers':
|
|
|
|
|
+ require_once __DIR__ . '/questionGenerators/math/numbers2.php';
|
|
|
$questionGen = new numbers2($this->data['user']);
|
|
$questionGen = new numbers2($this->data['user']);
|
|
|
$questionGen->getNumbers();
|
|
$questionGen->getNumbers();
|
|
|
break;
|
|
break;
|
|
@@ -310,8 +167,8 @@ if(false)
|
|
|
case 'multiplication':
|
|
case 'multiplication':
|
|
|
case 'division':
|
|
case 'division':
|
|
|
case 'rounding':
|
|
case 'rounding':
|
|
|
- include './questionGenerators/math/numeracy2.php';
|
|
|
|
|
- $questionGen = new numeracy2($this->data['user'],$this->data['selectedSubject']);
|
|
|
|
|
|
|
+ require_once __DIR__ . '/questionGenerators/math/numeracy2.php';
|
|
|
|
|
+ $questionGen = new numeracy2($this->data['user'], $this->data['selectedSubject']);
|
|
|
$questionGen->getNumeracy();
|
|
$questionGen->getNumeracy();
|
|
|
break;
|
|
break;
|
|
|
case 'worded_add':
|
|
case 'worded_add':
|
|
@@ -319,115 +176,94 @@ if(false)
|
|
|
case 'worded_mult':
|
|
case 'worded_mult':
|
|
|
case 'worded_devi':
|
|
case 'worded_devi':
|
|
|
case 'spelling':
|
|
case 'spelling':
|
|
|
- include './questionGenerators/english/spelling2.php';
|
|
|
|
|
|
|
+ require_once __DIR__ . '/questionGenerators/english/spelling2.php';
|
|
|
$questionGen = new spelling2($this->data['user']);
|
|
$questionGen = new spelling2($this->data['user']);
|
|
|
$questionGen->getSpellingWord();
|
|
$questionGen->getSpellingWord();
|
|
|
break;
|
|
break;
|
|
|
case 'anagrams':
|
|
case 'anagrams':
|
|
|
- include './questionGenerators/english/anagrams.php';
|
|
|
|
|
|
|
+ require_once __DIR__ . '/questionGenerators/english/anagrams.php';
|
|
|
$questionGen = new anagrams($this->data['user']);
|
|
$questionGen = new anagrams($this->data['user']);
|
|
|
$questionGen->getanagram();
|
|
$questionGen->getanagram();
|
|
|
break;
|
|
break;
|
|
|
- case 'generalKnowledge':
|
|
|
|
|
- include './questionGenerators/general/generalKnowledge.php';//=========================== TODO:not working yet
|
|
|
|
|
- $questionGen = new generalKnowledge($this->data['user']);
|
|
|
|
|
- $questionGen->getgeneralKnowledge();
|
|
|
|
|
case 'elements':
|
|
case 'elements':
|
|
|
- include './questionGenerators/science/elements2.php';
|
|
|
|
|
|
|
+ require_once __DIR__ . '/questionGenerators/science/elements2.php';
|
|
|
$questionGen = new elements2($this->data['user']);
|
|
$questionGen = new elements2($this->data['user']);
|
|
|
$questionGen->getElements();
|
|
$questionGen->getElements();
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 'generalKnowledge':
|
|
|
case 'continents':
|
|
case 'continents':
|
|
|
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
|
|
|
|
|
- $questionGen = new continents($this->data['user']);
|
|
|
|
|
- $questionGen->getContinents();
|
|
|
|
|
- break;
|
|
|
|
|
case 'countries':
|
|
case 'countries':
|
|
|
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
|
|
|
|
|
- $questionGen = new elements2($this->data['user']);
|
|
|
|
|
- $questionGen->getElements();
|
|
|
|
|
- break;
|
|
|
|
|
case 'flags':
|
|
case 'flags':
|
|
|
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
|
|
|
|
|
- $questionGen = new elements2($this->data['user']);
|
|
|
|
|
- $questionGen->getElements();
|
|
|
|
|
- break;
|
|
|
|
|
case 'capitalCities':
|
|
case 'capitalCities':
|
|
|
- include './questionGenerators/geography/continents.php';//=========================== TODO:not working yet
|
|
|
|
|
- $questionGen = new elements2($this->data['user']);
|
|
|
|
|
- $questionGen->getElements();
|
|
|
|
|
- break;
|
|
|
|
|
case 'artists':
|
|
case 'artists':
|
|
|
case 'malaySpelling':
|
|
case 'malaySpelling':
|
|
|
case 'nameBodyParts':
|
|
case 'nameBodyParts':
|
|
|
case 'nameBodyOrgans':
|
|
case 'nameBodyOrgans':
|
|
|
case 'basicFirstAid':
|
|
case 'basicFirstAid':
|
|
|
-
|
|
|
|
|
default:
|
|
default:
|
|
|
- print_a('An error has been detected in the question selector. Please report this and refresh the page.');
|
|
|
|
|
|
|
+ // Not built yet (or unknown): none of these are in the random pool.
|
|
|
|
|
+ e107::getRender()->tablerender('TimeKeeper', 'This subject is not available yet. Please refresh the page.');
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Get the list of available subjects and select a random one.
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Get the list of available subjects and select a random one.
|
|
* Get the list of available subjects and select a random one.
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
private function getSubject(): void {
|
|
private function getSubject(): void {
|
|
|
$usableSubjects = [];
|
|
$usableSubjects = [];
|
|
|
- foreach ($this->subjectsList as $subjects){
|
|
|
|
|
- foreach ($subjects as $subject){
|
|
|
|
|
- if($subject[1]===1&&$this->data['difficulty']>=$subject[2]){
|
|
|
|
|
|
|
+ foreach ($this->subjectsList as $subjects) {
|
|
|
|
|
+ foreach ($subjects as $subject) {
|
|
|
|
|
+ if ($subject[1] === 1 && $this->data['difficulty'] >= $subject[2]) {
|
|
|
$usableSubjects[] = $subject[0];
|
|
$usableSubjects[] = $subject[0];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $this->data['selectedSubject'] = $usableSubjects[mt_rand('0',count($usableSubjects)-1)];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($usableSubjects)) {
|
|
|
|
|
+ $usableSubjects[] = 'numbers';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $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.
|
|
* Show an initial stats message to the user.
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
private function showMessage(): void {
|
|
private function showMessage(): void {
|
|
|
- $ns = e107::getRender();
|
|
|
|
|
- $text = "You have answered ".$this->data['cntr']." questions this month.<br/>"
|
|
|
|
|
- . "Your accuacy for the month is ".$this->data['percent']."%.<br/>"
|
|
|
|
|
- . "Your difficulty is set at ".$this->data['difficulty'].".<br/><br/>";
|
|
|
|
|
-
|
|
|
|
|
- $ns->tablerender('Your stats '.ucfirst($this->data['user']), $text);
|
|
|
|
|
|
|
+ $text = "You have answered " . (int) $this->data['cntr'] . " questions this month.<br/>"
|
|
|
|
|
+ . "Your accuacy for the month is " . htmlspecialchars((string) $this->data['percent']) . "%.<br/>"
|
|
|
|
|
+ . "Your difficulty is set at " . htmlspecialchars((string) $this->data['difficulty']) . ".<br/><br/>";
|
|
|
|
|
+
|
|
|
|
|
+ e107::getRender()->tablerender('Your stats ' . htmlspecialchars(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.
|
|
* Get the initial values needed to generate a sane question.
|
|
|
* @param string $user
|
|
* @param string $user
|
|
|
* @return void
|
|
* @return void
|
|
|
*/
|
|
*/
|
|
|
private function getScores($user): void {
|
|
private function getScores($user): void {
|
|
|
|
|
+ $db = e107::getDb();
|
|
|
|
|
+ $u = $db->escape($user);
|
|
|
|
|
+
|
|
|
$returnArray = [];
|
|
$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'];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $returnArray['totalQuestionCount'] = (int) $db->count('tkReport', '(id)', "username = '{$u}'");
|
|
|
|
|
+
|
|
|
|
|
+ $db->gen("SELECT COUNT(id) AS cntr, CAST((SUM(correct)/COUNT(id)*100) AS DECIMAL(5,2)) AS percent
|
|
|
|
|
+ FROM `" . MPREFIX . "tkReport` WHERE username = '{$u}'
|
|
|
|
|
+ AND answereddatestamp >= UNIX_TIMESTAMP(CURRENT_DATE() - INTERVAL 1 MONTH)
|
|
|
|
|
+ AND answereddatestamp <= UNIX_TIMESTAMP(CURRENT_DATE() + INTERVAL 1 DAY)");
|
|
|
|
|
+ $row = $db->fetch();
|
|
|
|
|
+
|
|
|
|
|
+ $returnArray['cntr'] = is_array($row) ? (int) $row['cntr'] : 0;
|
|
|
|
|
+ $returnArray['percent'] = (is_array($row) && $row['percent'] !== null) ? (float) $row['percent'] : 0;
|
|
|
|
|
+ $returnArray['user'] = $user;
|
|
|
|
|
+ $returnArray['difficulty'] = $returnArray['totalQuestionCount'] * $returnArray['percent'];
|
|
|
|
|
+
|
|
|
$this->data = $returnArray;
|
|
$this->data = $returnArray;
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|