questionData = $question; } /** * Select which template to use to create the needed form. * * @return type */ public function templater() { foreach ($this->questionData as $key => $question) { switch ($key) { case 'numbers': $this->numbers($question['question']); break; case 'spelling': $this->spelling($question['question']); break; case 'numeracy': $this->numeracy($question['question']); break; case 'math_word_problems': $this->math_word_problems($question['question']); break; case 'elements': $this->elements($question['question']); break; case 'DebugSubjects': break; default: $this->returnQuestion = 'form error.'; print_a([$key => $this->questionData]); break; } } return $this->returnQuestion; } /** * Create a number sequence form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function numbers($data) { $frm = e107::getForm(); $qString = $this->formStart('Number sequences', 'Find the missing number.', $data); foreach ($data['question'] as $seq) { $qString .= $frm->label($seq . " ") . "\n"; } $qString .= $this->formEnd($data); $this->returnQuestion = $qString; } /** * Create a spelling form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function spelling($data) { $tp = e107::getParser(); $qString = $this->formStart(__FUNCTION__, 'Spell the word in the sentence.', $data); if (!file_exists('./audio/' . md5($data['answer1']) . '2v.wav')) { exec('./audio/flite-2.0.0-release/bin/flite -voice ./audio/voices/cmu_us_aew.flitevox -o "./audio/' . md5($data['answer1']) . '2v.wav" "Spell the word, ' . $tp->toHTML($data['answer1']) . '. ' . $tp->toHTML($data['question']) . '"'); } $qString .= "\n"; $qString .= $this->formEnd($data); $this->returnQuestion = $qString; } /** * Create a numeracy form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function numeracy($data) { $frm = e107::getForm(); $qString = $this->formStart(__FUNCTION__, $this->captionSupport($data['question']), $data); if ($data['question'][1] == 'r') { $qString .= $frm->label('$' . $data['question'][0]) . "\n"; } elseif ($data['question'][1] == '/') { $qString .= $frm->label($data['question'][0] . " " . "÷ " . $data['question'][2]) . "\n"; } else { $qString .= $frm->label($data['question'][0] . " " . $data['question'][1] . " " . $data['question'][2]) . "\n"; } $qString .= $this->formEnd($data); $this->returnQuestion = $qString; } /** * Create a math_word_problems form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function math_word_problems($data) { $frm = e107::getForm(); $qString = $this->formStart(str_replace('_', ' ', __FUNCTION__), 'Solve the following. (Round off to the nearest whole number)', $data); $qString .= $frm->label($data['question']) . "\n"; $qString .= $this->formEnd($data); $this->returnQuestion = $qString; } /** * Create a elements form using the supplied question. * And write it into "$this->returnQuestion". * * @param array() $data Question data to be used. */ private function elements($data) { //$frm = e107::getForm(); $tp = e107::getParser(); $sc = e107::getScBatch('timekeeper', TRUE); $elementData = $data['question']['element']; $elementData[$data['question'][1]] = '???'; $sc->setVars($elementData); $qString = $this->formStart(str_replace('_', ' ', __FUNCTION__), 'Periodic Table of Elements. Fill in the missing information.', $data); $qString .= $tp->parseTemplate(file_get_contents('templates/elementTable.html'), true, $sc); //$qString .= $frm->label($data['question']) . "\n"; $qString .= $this->formEnd($data); $this->returnQuestion = $qString; } private function captionSupport($questionData) { $descriptions = [ '+' => 'Add the following together.', '-' => 'Subtract one amount from the other.', 'x' => 'Multiplication, times one number by another.', '/' => 'Divide one number from another.', 'r' => 'Round the following off to the nearest 5 cents.', ]; return $descriptions[$questionData[1]]; } private function formStart($label, $caption) { $frm = e107::getForm(); $fString = $frm->open('questionForm', 'post', '', ['autocomplete' => 'off', 'class' => 'formclass']); $fString .= $frm->label('