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 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-item' . $classes . '" data-question="' . $data['question'] . '" ' . ($data['answer'] != '' ? 'data-answer="' . $data['answer'] . '"' : '') . '>'; 35 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-question">' . $data['question'] . '</div>'; 36 if($data['text'] != '') $renderer->doc .= '<p>' . $data['text'] . '</p>'; 37 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-options">'; 38 39 switch(strtolower($data['type'])) { 40 case 'choice': 41 $name = rand(10000, 99999); 42 43 $options = explode('|', $data['options']); 44 $scores = explode('|', $data['scores']); 45 foreach($options as $key => $option) { 46 $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] . '" ' : '') . '/>' . $option . '</label></div>'; 47 } 48 break; 49 case 'multiple': 50 $name = rand(10000, 99999); 51 52 $options = explode('|', $data['options']); 53 $scores = explode('|', $data['scores']); 54 foreach($options as $key => $option) { 55 $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] . '" ' : '') . '/>' . $option . '</label></div>'; 56 } 57 break; 58 } 59 60 $renderer->doc .= '</div>'; 61 $renderer->doc .= '</div>'; 62 } 63} 64?> 65