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_output 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 * We do not connect any pattern here, because the call to this plugin is not 39 * triggered from syntax but our action component 40 * 41 * @asee action_plugin_struct_output 42 * @param string $mode Parser mode 43 */ 44 public function connectTo($mode) { 45 46 } 47 48 49 /** 50 * Handle matches of the struct syntax 51 * 52 * @param string $match The match of the syntax 53 * @param int $state The state of the handler 54 * @param int $pos The position in the document 55 * @param Doku_Handler $handler The handler 56 * @return array Data for the renderer 57 */ 58 public function handle($match, $state, $pos, Doku_Handler $handler){ 59 // this is never called 60 return array(); 61 } 62 63 /** 64 * Render schema data 65 * 66 * Currently completely renderer agnostic 67 * 68 * @todo add some classes for nicer styling when $mode = 'xhtml' 69 * @todo we currently have no schema headlines 70 * 71 * @param string $mode Renderer mode 72 * @param Doku_Renderer $R The renderer 73 * @param array $data The data from the handler() function 74 * @return bool If rendering was successful. 75 */ 76 public function render($mode, Doku_Renderer $R, $data) { 77 global $ID; 78 global $INFO; 79 global $REV; 80 if($ID != $INFO['id']) return true; 81 if(!$INFO['exists']) return true; 82 83 $assignments = new Assignments(); 84 $tables = $assignments->getPageAssignments($ID); 85 if(!$tables) return true; 86 87 if($mode == 'xhtml') $R->doc .= '<div id="plugin__struct_output">'; 88 $R->header($this->getLang('headline'), 1, $data['pos']); 89 90 $R->table_open(); 91 $R->tabletbody_open(); 92 foreach($tables as $table) { 93 $schemadata = new SchemaData($table, $ID, $REV); 94 $data = $schemadata->getData(); 95 96 foreach($data as $field) { 97 $R->tablerow_open(); 98 $R->tableheader_open(); 99 $R->cdata($field->getColumn()->getTranslatedLabel()); 100 $R->tableheader_close(); 101 $R->tablecell_open(); 102 $field->render($R, $mode); 103 $R->tablecell_close(); 104 $R->tablerow_close(); 105 } 106 } 107 $R->tabletbody_close(); 108 $R->table_close(); 109 110 if($mode == 'xhtml') $R->doc .= '</div>'; 111 112 return true; 113 } 114} 115 116// vim:ts=4:sw=4:et: 117