xref: /plugin/mikioplugin/syntax/quiz.php (revision e230d7cf2be6c3bfe6edd69c4aecd6373cd3c159)
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        'full'   => array('type'     => 'boolean',          'default'   => 'false'),
19        'reset-text'   => array('type'     => 'text',          'default'   => 'Retry'),
20        'submit-text'   => array('type'     => 'text',          'default'   => 'Submit'),
21        'prev-text'   => array('type'     => 'text',          'default'   => 'Prev'),
22        'next-text'   => array('type'     => 'text',          'default'   => 'Next'),
23        'correct-text'   => array('type'     => 'text',          'default'   => 'Correct'),
24        'incorrect-text'   => array('type'     => 'text',          'default'   => 'Incorrect'),
25        'status-text'   => array('type'     => 'text',          'default'   => 'Question $1 of $2'),
26        'result-correct-text'   => array('type'     => 'text',          'default'   => 'You got $1 out of $2 correct'),
27        'result-score-text'   => array('type'     => 'text',          'default'   => 'Score: $1'),
28        'result-score-total-text'   => array('type'     => 'text',          'default'   => 'Total score: $1'),
29    );
30
31
32    public function render_lexer_enter(Doku_Renderer $renderer, $data) {
33        $classes = $this->buildClass($data);
34        $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'] . '"' . ($data['full'] == true ? ' data-full="true"' : '') . '>';
35    }
36
37
38    public function render_lexer_exit(Doku_Renderer $renderer, $data) {
39        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-result"></div>';
40        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-status">';
41        if($data['full'] == false) {
42            $renderer->doc .= '<span class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-status-text"></span>';
43            $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-prev">&laquo; ' . $data['prev-text'] . '</button>';
44        }
45        $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-submit">' . $data['submit-text'] . '</button>';
46        if($data['resettable'] == true) {
47            $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-reset">' . $data['reset-text'] . '</button>';
48        }
49        if($data['full'] == false) {
50            $renderer->doc .= '<button class="' . $this->elemClass . ' ' . $this->classPrefix . 'button ' . $this->classPrefix . 'quiz-button-next">' . $data['next-text'] . ' &raquo;</button>';
51        }
52        $renderer->doc .= '</div>';
53        $renderer->doc .= '</div>';
54    }
55}
56?>