1257dd7f8SAndreas Gohr<?php 2257dd7f8SAndreas Gohr/** 3257dd7f8SAndreas Gohr * DokuWiki Plugin struct (Syntax Component) 4257dd7f8SAndreas Gohr * 5257dd7f8SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6257dd7f8SAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 7257dd7f8SAndreas Gohr */ 8257dd7f8SAndreas Gohr 9257dd7f8SAndreas Gohr// must be run within Dokuwiki 10257dd7f8SAndreas Gohruse plugin\struct\meta\Assignments; 11257dd7f8SAndreas Gohruse plugin\struct\meta\SchemaData; 12257dd7f8SAndreas Gohr 13257dd7f8SAndreas Gohrif(!defined('DOKU_INC')) die(); 14257dd7f8SAndreas Gohr 1582c064c1SAndreas Gohrclass syntax_plugin_struct_output extends DokuWiki_Syntax_Plugin { 16257dd7f8SAndreas Gohr /** 17257dd7f8SAndreas Gohr * @return string Syntax mode type 18257dd7f8SAndreas Gohr */ 19257dd7f8SAndreas Gohr public function getType() { 20257dd7f8SAndreas Gohr return 'substition'; 21257dd7f8SAndreas Gohr } 22*da30fdd3SAndreas Gohr 23257dd7f8SAndreas Gohr /** 24257dd7f8SAndreas Gohr * @return string Paragraph type 25257dd7f8SAndreas Gohr */ 26257dd7f8SAndreas Gohr public function getPType() { 27257dd7f8SAndreas Gohr return 'block'; 28257dd7f8SAndreas Gohr } 29*da30fdd3SAndreas Gohr 30257dd7f8SAndreas Gohr /** 31257dd7f8SAndreas Gohr * @return int Sort order - Low numbers go before high numbers 32257dd7f8SAndreas Gohr */ 33257dd7f8SAndreas Gohr public function getSort() { 34257dd7f8SAndreas Gohr return 155; 35257dd7f8SAndreas Gohr } 36257dd7f8SAndreas Gohr 37257dd7f8SAndreas Gohr /** 38257dd7f8SAndreas Gohr * Connect lookup pattern to lexer. 39257dd7f8SAndreas Gohr * 4082c064c1SAndreas Gohr * We do not connect any pattern here, because the call to this plugin is not 4182c064c1SAndreas Gohr * triggered from syntax but our action component 4282c064c1SAndreas Gohr * 4382c064c1SAndreas Gohr * @asee action_plugin_struct_output 44257dd7f8SAndreas Gohr * @param string $mode Parser mode 45257dd7f8SAndreas Gohr */ 46257dd7f8SAndreas Gohr public function connectTo($mode) { 4782c064c1SAndreas Gohr 48257dd7f8SAndreas Gohr } 49257dd7f8SAndreas Gohr 50257dd7f8SAndreas Gohr /** 51257dd7f8SAndreas Gohr * Handle matches of the struct syntax 52257dd7f8SAndreas Gohr * 53257dd7f8SAndreas Gohr * @param string $match The match of the syntax 54257dd7f8SAndreas Gohr * @param int $state The state of the handler 55257dd7f8SAndreas Gohr * @param int $pos The position in the document 56257dd7f8SAndreas Gohr * @param Doku_Handler $handler The handler 57257dd7f8SAndreas Gohr * @return array Data for the renderer 58257dd7f8SAndreas Gohr */ 59257dd7f8SAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) { 6082c064c1SAndreas Gohr // this is never called 6182c064c1SAndreas Gohr return array(); 62257dd7f8SAndreas Gohr } 63257dd7f8SAndreas Gohr 64257dd7f8SAndreas Gohr /** 6582c064c1SAndreas Gohr * Render schema data 66257dd7f8SAndreas Gohr * 6782c064c1SAndreas Gohr * Currently completely renderer agnostic 6882c064c1SAndreas Gohr * 6982c064c1SAndreas Gohr * @todo we currently have no schema headlines 7082c064c1SAndreas Gohr * 7182c064c1SAndreas Gohr * @param string $mode Renderer mode 72257dd7f8SAndreas Gohr * @param Doku_Renderer $R The renderer 73257dd7f8SAndreas Gohr * @param array $data The data from the handler() function 74257dd7f8SAndreas Gohr * @return bool If rendering was successful. 75257dd7f8SAndreas Gohr */ 76257dd7f8SAndreas Gohr public function render($mode, Doku_Renderer $R, $data) { 77257dd7f8SAndreas Gohr global $ID; 7882c064c1SAndreas Gohr global $INFO; 79257dd7f8SAndreas Gohr global $REV; 8082c064c1SAndreas Gohr if($ID != $INFO['id']) return true; 812f1a213bSAndreas Gohr if(!$INFO['exists']) return true; 82257dd7f8SAndreas Gohr 83257dd7f8SAndreas Gohr $assignments = new Assignments(); 84257dd7f8SAndreas Gohr $tables = $assignments->getPageAssignments($ID); 85257dd7f8SAndreas Gohr if(!$tables) return true; 86257dd7f8SAndreas Gohr 875a1eab78SAndreas Gohr if($mode == 'xhtml') $R->doc .= '<div id="plugin__struct_output">'; 885a1eab78SAndreas Gohr $R->header($this->getLang('headline'), 1, $data['pos']); 895a1eab78SAndreas Gohr 90257dd7f8SAndreas Gohr foreach($tables as $table) { 91257dd7f8SAndreas Gohr $schemadata = new SchemaData($table, $ID, $REV); 9233e429a8SAndreas Gohr $data = $schemadata->getData(true); 93*da30fdd3SAndreas Gohr if(!count($data)) continue; 94257dd7f8SAndreas Gohr 95*da30fdd3SAndreas Gohr $R->table_open(); 96*da30fdd3SAndreas Gohr 97*da30fdd3SAndreas Gohr $R->tablethead_open(); 98*da30fdd3SAndreas Gohr $R->tablerow_open(); 99*da30fdd3SAndreas Gohr $R->tableheader_open(2); 100*da30fdd3SAndreas Gohr $R->cdata($table); 101*da30fdd3SAndreas Gohr $R->tableheader_close(); 102*da30fdd3SAndreas Gohr $R->tablerow_close(); 103*da30fdd3SAndreas Gohr $R->tablethead_open(); 104*da30fdd3SAndreas Gohr 105*da30fdd3SAndreas Gohr $R->tabletbody_open(); 106257dd7f8SAndreas Gohr foreach($data as $field) { 107257dd7f8SAndreas Gohr $R->tablerow_open(); 108257dd7f8SAndreas Gohr $R->tableheader_open(); 1099e9bee91SAndreas Gohr $R->cdata($field->getColumn()->getTranslatedLabel()); 110257dd7f8SAndreas Gohr $R->tableheader_close(); 111257dd7f8SAndreas Gohr $R->tablecell_open(); 112257dd7f8SAndreas Gohr $field->render($R, $mode); 113257dd7f8SAndreas Gohr $R->tablecell_close(); 114257dd7f8SAndreas Gohr $R->tablerow_close(); 115257dd7f8SAndreas Gohr } 116257dd7f8SAndreas Gohr $R->tabletbody_close(); 117257dd7f8SAndreas Gohr $R->table_close(); 118*da30fdd3SAndreas Gohr } 119257dd7f8SAndreas Gohr 1205a1eab78SAndreas Gohr if($mode == 'xhtml') $R->doc .= '</div>'; 1215a1eab78SAndreas Gohr 122257dd7f8SAndreas Gohr return true; 123257dd7f8SAndreas Gohr } 124257dd7f8SAndreas Gohr} 125257dd7f8SAndreas Gohr 126257dd7f8SAndreas Gohr// vim:ts=4:sw=4:et: 127