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 $requires_tag = 'quiz'; 17 public $hasEndTag = false; 18 public $options = array( 19 'type' => array('type' => 'choice', 20 'data' => array('choice', 'multiple'), 21 'default' => 'choice'), 22 'question' => array('type' => 'text', 'default' => ''), 23 'options' => array('type' => 'text', 'default' => ''), 24 'answer' => array('type' => 'text', 'default' => ''), 25 'scores' => array('type' => 'text', 'default' => ''), 26 'text' => array('type' => 'text', 'default' => ''), 27 ); 28 29 // public function getAllowedTypes() { return array(); } 30 31 public function render_lexer_special(Doku_Renderer $renderer, $data) { 32 $classes = $this->buildClass($data); 33 34 $data['question'] = $this->applyMarkdownEffects($data['question']); 35 $data['text'] = $this->applyMarkdownEffects($data['text']); 36 37 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-item' . $classes . '" data-question="' . $data['question'] . '" ' . ($data['answer'] != '' ? 'data-answer="' . $data['answer'] . '"' : '') . '>'; 38 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-question">' . $data['question'] . '</div>'; 39 if($data['text'] != '') $renderer->doc .= '<p>' . $data['text'] . '</p>'; 40 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-options">'; 41 42 switch(strtolower($data['type'])) { 43 case 'choice': 44 $name = rand(10000, 99999); 45 46 $options = explode('|', $data['options']); 47 $scores = explode('|', $data['scores']); 48 foreach($options as $key => $option) { 49 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-option"><label><input type="radio" name="' . $name . '" value="' . $option . '" ' . (isset($scores[$key]) && $scores[$key] != "" ? 'data-score="' . $scores[$key] . '" ' : '') . '/>' . $this->applyMarkdownEffects($option) . '</label></div>'; 50 } 51 break; 52 case 'multiple': 53 $name = rand(10000, 99999); 54 55 $options = explode('|', $data['options']); 56 $scores = explode('|', $data['scores']); 57 foreach($options as $key => $option) { 58 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-option"><label><input type="checkbox" name="' . $name . '-' . $key . '" value="' . $option . '" ' . (isset($scores[$key]) && $scores[$key] != "" ? 'data-score="' . $scores[$key] . '" ' : '') . '/>' . $this->applyMarkdownEffects($option) . '</label></div>'; 59 } 60 break; 61 } 62 63 $renderer->doc .= '</div>'; 64 $renderer->doc .= '</div>'; 65 } 66} 67?> 68