xref: /plugin/mikioplugin/syntax/quiz.php (revision 4d21e14836aefa3e73fe3ba22067c4af4c1fd79a)
1<?php
2/**
3 * Mikio Syntax Plugin: Quiz
4  *
5 * @link        http://github.com/nomadjimbob/mikioplugin
6 * @license     GPL 2 (http://www.gnu.org/licenses/gpl.html)
7 * @author      James Collins <james.collins@outlook.com.au>
8 */
9if (!defined('DOKU_INC')) die();
10if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
11require_once(dirname(__FILE__).'/core.php');
12
13class syntax_plugin_mikioplugin_quiz extends syntax_plugin_mikioplugin_core {
14    public $tag                 = 'quiz';
15    public $hasEndTag           = true;
16    public $options             = array(
17        'resettable'   => array('type'     => 'boolean',          'default'   => 'false'),
18        'reset-text'   => array('type'     => 'text',          'default'   => 'Retry'),
19        'submit-text'   => array('type'     => 'text',          'default'   => 'Submit'),
20        'prev-text'   => array('type'     => 'text',          'default'   => 'Prev'),
21        'next-text'   => array('type'     => 'text',          'default'   => 'Next'),
22        'correct-text'   => array('type'     => 'text',          'default'   => 'Correct'),
23        'incorrect-text'   => array('type'     => 'text',          'default'   => 'Incorrect'),
24        'status-text'   => array('type'     => 'text',          'default'   => 'Question $1 of $2'),
25        'result-correct-text'   => array('type'     => 'text',          'default'   => 'You got $1 out of $2 correct'),
26        'result-score-text'   => array('type'     => 'text',          'default'   => 'Score: $1'),
27        'result-score-total-text'   => array('type'     => 'text',          'default'   => 'Total score: $1'),
28    );
29
30
31    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
32        $classes = $this->buildClass($data);
33        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz ' . $classes . '" data-status="' . $data['status-text'] . '" data-result-correct="' . $data['result-correct-text'] . '" data-result-score="' . $data['result-score-text'] . '" data-result-score-total="' . $data['result-score-total-text'] . '" data-correct="' . $data['correct-text'] . '" data-incorrect="' . $data['incorrect-text'] . '">';
34    }
35
36
37    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
38        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-result"></div>';
39        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-status">';
40        $renderer->doc .= '<span class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-status-text"></span>';
41        $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-prev">&laquo; ' . $data['prev-text'] . '</button>';
42        $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-submit">' . $data['submit-text'] . '</button>';
43        if($data['resettable'] == true) {
44            $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-reset">' . $data['reset-text'] . '</button>';
45        }
46        $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-next">' . $data['next-text'] . ' &raquo;</button>';
47        $renderer->doc .= '</div>';
48        $renderer->doc .= '</div>';
49    }
50}
51?>