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 /** 24 * @return string Paragraph type 25 */ 26 public function getPType() { 27 return 'block'; 28 } 29 30 /** 31 * @return int Sort order - Low numbers go before high numbers 32 */ 33 public function getSort() { 34 return 155; 35 } 36 37 /** 38 * Connect lookup pattern to lexer. 39 * 40 * We do not connect any pattern here, because the call to this plugin is not 41 * triggered from syntax but our action component 42 * 43 * @asee action_plugin_struct_output 44 * @param string $mode Parser mode 45 */ 46 public function connectTo($mode) { 47 48 } 49 50 /** 51 * Handle matches of the struct syntax 52 * 53 * @param string $match The match of the syntax 54 * @param int $state The state of the handler 55 * @param int $pos The position in the document 56 * @param Doku_Handler $handler The handler 57 * @return array Data for the renderer 58 */ 59 public function handle($match, $state, $pos, Doku_Handler $handler) { 60 // this is never called 61 return array(); 62 } 63 64 /** 65 * Render schema data 66 * 67 * Currently completely renderer agnostic 68 * 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 foreach($tables as $table) { 91 $schemadata = new SchemaData($table, $ID, $REV); 92 $data = $schemadata->getData(true); 93 if(!count($data)) continue; 94 95 $R->table_open(); 96 97 $R->tablethead_open(); 98 $R->tablerow_open(); 99 $R->tableheader_open(2); 100 $R->cdata($table); 101 $R->tableheader_close(); 102 $R->tablerow_close(); 103 $R->tablethead_open(); 104 105 $R->tabletbody_open(); 106 foreach($data as $field) { 107 $R->tablerow_open(); 108 $R->tableheader_open(); 109 $R->cdata($field->getColumn()->getTranslatedLabel()); 110 $R->tableheader_close(); 111 $R->tablecell_open(); 112 $field->render($R, $mode); 113 $R->tablecell_close(); 114 $R->tablerow_close(); 115 } 116 $R->tabletbody_close(); 117 $R->table_close(); 118 } 119 120 if($mode == 'xhtml') $R->doc .= '</div>'; 121 122 return true; 123 } 124} 125 126// vim:ts=4:sw=4:et: 127