| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Create various forms for timekeeper.
- *
- * @author gregory
- */
- class forms {
- private $questionData;
- private $returnQuestion;
- /**
- * __construct()
- * @param array() $question Question data to insert into template data
- */
- public function __construct($question) {
- $this->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 .= "<audio controls><source src='audio/" . md5($data['answer1']) . "2v.wav' type='audio/wav'>Your browser does not support the audio element.</audio>\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('<h4>' . ucfirst($label) . '.</h4>') . "</br>\n";
- $fString .= $frm->label($caption) . "\n";
- $fString .= '</br>';
- return $fString;
- }
- private function formEnd($data) {
- $frm = e107::getForm();
- $fString = '</br></br>';
- $fString .= $frm->text('a1', '', 80, ['placeholder' => 'Write answer here!', 'autocomplete' => "off", 'spellcheck' => "false"]) . "\n";
- $fString .= $frm->hidden('checkerData', base64_encode(json_encode($data)), ['id' => 'checkerData']);
- $fString .= '</br>';
- $fString .= e107::getForm()->button('Answer', 'Check answer') . "\n";
- $fString .= e107::getForm()->close();
- $fString .= '</br></br>';
- return $fString;
- }
- }
|