1<?php 2/** 3 * DokuWiki Plugin struct (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10use plugin\struct\meta\Assignments; 11use plugin\struct\meta\SchemaData; 12 13if (!defined('DOKU_INC')) die(); 14 15class syntax_plugin_struct_list extends DokuWiki_Syntax_Plugin { 16 /** 17 * @return string Syntax mode type 18 */ 19 public function getType() { 20 return 'substition'; 21 } 22 /** 23 * @return string Paragraph type 24 */ 25 public function getPType() { 26 return 'block'; 27 } 28 /** 29 * @return int Sort order - Low numbers go before high numbers 30 */ 31 public function getSort() { 32 return 155; 33 } 34 35 /** 36 * Connect lookup pattern to lexer. 37 * 38 * @param string $mode Parser mode 39 */ 40 public function connectTo($mode) { 41 $this->Lexer->addSpecialPattern('~~STRUCT~~',$mode,'plugin_struct_list'); 42 } 43 44 45 /** 46 * Handle matches of the struct syntax 47 * 48 * @param string $match The match of the syntax 49 * @param int $state The state of the handler 50 * @param int $pos The position in the document 51 * @param Doku_Handler $handler The handler 52 * @return array Data for the renderer 53 */ 54 public function handle($match, $state, $pos, Doku_Handler $handler){ 55 $data = array(); 56 57 return $data; 58 } 59 60 /** 61 * Render xhtml output or metadata 62 * 63 * @param string $mode Renderer mode (supported modes: xhtml) 64 * @param Doku_Renderer $R The renderer 65 * @param array $data The data from the handler() function 66 * @return bool If rendering was successful. 67 */ 68 public function render($mode, Doku_Renderer $R, $data) { 69 global $ID; 70 global $REV; 71 72 $assignments = new Assignments(); 73 $tables = $assignments->getPageAssignments($ID); 74 if(!$tables) return true; 75 76 $R->table_open(); 77 $R->tabletbody_open(); 78 foreach($tables as $table) { 79 $schemadata = new SchemaData($table, $ID, $REV); 80 $data = $schemadata->getData(); 81 82 foreach($data as $field) { 83 $R->tablerow_open(); 84 $R->tableheader_open(); 85 $R->cdata($field->getColumn()->getLabel()); 86 $R->tableheader_close(); 87 $R->tablecell_open(); 88 $field->render($R, $mode); 89 $R->tablecell_close(); 90 $R->tablerow_close(); 91 } 92 } 93 $R->tabletbody_close(); 94 $R->table_close(); 95 96 97 98 if($mode != 'xhtml') return false; 99 100 return true; 101 } 102} 103 104// vim:ts=4:sw=4:et: 105