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 dokuwiki\plugin\struct\meta\AccessTable; 11use dokuwiki\plugin\struct\meta\Assignments; 12use dokuwiki\plugin\struct\meta\AccessTableData; 13 14if(!defined('DOKU_INC')) die(); 15 16class syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin { 17 18 protected $hasBeenRendered = false; 19 20 /** 21 * @return string Syntax mode type 22 */ 23 public function getType() { 24 return 'substition'; 25 } 26 27 /** 28 * @return string Paragraph type 29 */ 30 public function getPType() { 31 return 'block'; 32 } 33 34 /** 35 * @return int Sort order - Low numbers go before high numbers 36 */ 37 public function getSort() { 38 return 155; 39 } 40 41 /** 42 * Connect lookup pattern to lexer. 43 * 44 * We do not connect any pattern here, because the call to this plugin is not 45 * triggered from syntax but our action component 46 * 47 * @asee action_plugin_struct_output 48 * @param string $mode Parser mode 49 */ 50 public function connectTo($mode) { 51 52 } 53 54 /** 55 * Handle matches of the struct syntax 56 * 57 * @param string $match The match of the syntax 58 * @param int $state The state of the handler 59 * @param int $pos The position in the document 60 * @param Doku_Handler $handler The handler 61 * @return array Data for the renderer 62 */ 63 public function handle($match, $state, $pos, Doku_Handler $handler) { 64 // this is never called 65 return array(); 66 } 67 68 /** 69 * Render schema data 70 * 71 * Currently completely renderer agnostic 72 * 73 * @todo we currently have no schema headlines 74 * 75 * @param string $mode Renderer mode 76 * @param Doku_Renderer $R The renderer 77 * @param array $data The data from the handler() function 78 * @return bool If rendering was successful. 79 */ 80 public function render($mode, Doku_Renderer $R, $data) { 81 global $ID; 82 global $INFO; 83 global $REV; 84 if($ID != $INFO['id']) return true; 85 if(!$INFO['exists']) return true; 86 if($this->hasBeenRendered) return true; 87 88 // do not render the output twice on the same page, e.g. when another page has been included 89 $this->hasBeenRendered = true; 90 91 $assignments = new Assignments(); 92 $tables = $assignments->getPageAssignments($ID); 93 if(!$tables) return true; 94 95 if($mode == 'xhtml') $R->doc .= '<div id="plugin__struct_output">'; 96 97 foreach($tables as $table) { 98 $schemadata = AccessTable::byTableName($table, $ID, $REV); 99 $schemadata->optionSkipEmpty(true); 100 $data = $schemadata->getData(); 101 if(!count($data)) continue; 102 103 $R->table_open(); 104 105 $R->tablethead_open(); 106 $R->tablerow_open(); 107 $R->tableheader_open(2); 108 $R->cdata($table); 109 $R->tableheader_close(); 110 $R->tablerow_close(); 111 $R->tablethead_open(); 112 113 $R->tabletbody_open(); 114 foreach($data as $field) { 115 $R->tablerow_open(); 116 $R->tableheader_open(); 117 $R->cdata($field->getColumn()->getTranslatedLabel()); 118 $R->tableheader_close(); 119 $R->tablecell_open(); 120 $field->render($R, $mode); 121 $R->tablecell_close(); 122 $R->tablerow_close(); 123 } 124 $R->tabletbody_close(); 125 $R->table_close(); 126 } 127 128 if($mode == 'xhtml') $R->doc .= '</div>'; 129 130 return true; 131 } 132} 133 134// vim:ts=4:sw=4:et: 135