1<?php
2/**
3 * Mikio Syntax Plugin: Quiz Item
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 */
9
10if (!defined('DOKU_INC')) die();
11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(dirname(__FILE__).'/core.php');
13
14class syntax_plugin_mikioplugin_quizitem extends syntax_plugin_mikioplugin_core {
15    public $tag                 = 'quiz-item';
16    public $hasEndTag           = false;
17    public $options             = array(
18        'type'          => array('type'     => 'choice',
19                                 'data'     => array('choice'),
20                                 'default'  => ''),
21        'question'      => array('type'     => 'text',          'default'   => ''),
22        'options'       => array('type'     => 'text',          'default'   => ''),
23        'submit-text'   => array('type'     => 'text',          'default'   => 'Submit'),
24        'answer'        => array('type'     => 'text',          'default'   => ''),
25        'text'          => array('type'     => 'text',          'default'   => ''),
26    );
27
28    // public function getAllowedTypes() {  return array(); }
29
30    public function render_lexer_special(Doku_Renderer $renderer, $data) {
31        $classes = $this->buildClass($data);
32
33        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-item' . $classes . '" data-question="' . $data['question'] . '" data-answer="' . $data['answer'] . '">';
34        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-question">' . $data['question'] . '</div>';
35        if($data['text'] != '') $renderer->doc .= '<p>' . $data['text'] . '</p>';
36        $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-options">';
37
38        switch(strtolower($data['type'])) {
39            case 'choice':
40                $name = rand(10000, 99999);
41
42                $options = explode('|', $data['options']);
43                foreach($options as $option) {
44                    $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-option"><label><input type="radio" name="' . $name . '" value="' . $option . '" />' . $option . '</label></div>';
45                }
46                break;
47        }
48
49        $renderer->doc .= '</div>';
50        $renderer->doc .= '</div>';
51    }
52}
53?>
54