xref: /plugin/struct/syntax/output.php (revision 2f1a213bfd713cc8211decd12ca66d5cb8c3b50b)
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    }
22257dd7f8SAndreas Gohr    /**
23257dd7f8SAndreas Gohr     * @return string Paragraph type
24257dd7f8SAndreas Gohr     */
25257dd7f8SAndreas Gohr    public function getPType() {
26257dd7f8SAndreas Gohr        return 'block';
27257dd7f8SAndreas Gohr    }
28257dd7f8SAndreas Gohr    /**
29257dd7f8SAndreas Gohr     * @return int Sort order - Low numbers go before high numbers
30257dd7f8SAndreas Gohr     */
31257dd7f8SAndreas Gohr    public function getSort() {
32257dd7f8SAndreas Gohr        return 155;
33257dd7f8SAndreas Gohr    }
34257dd7f8SAndreas Gohr
35257dd7f8SAndreas Gohr    /**
36257dd7f8SAndreas Gohr     * Connect lookup pattern to lexer.
37257dd7f8SAndreas Gohr     *
3882c064c1SAndreas Gohr     * We do not connect any pattern here, because the call to this plugin is not
3982c064c1SAndreas Gohr     * triggered from syntax but our action component
4082c064c1SAndreas Gohr     *
4182c064c1SAndreas Gohr     * @asee action_plugin_struct_output
42257dd7f8SAndreas Gohr     * @param string $mode Parser mode
43257dd7f8SAndreas Gohr     */
44257dd7f8SAndreas Gohr    public function connectTo($mode) {
4582c064c1SAndreas Gohr
46257dd7f8SAndreas Gohr    }
47257dd7f8SAndreas Gohr
48257dd7f8SAndreas Gohr
49257dd7f8SAndreas Gohr    /**
50257dd7f8SAndreas Gohr     * Handle matches of the struct syntax
51257dd7f8SAndreas Gohr     *
52257dd7f8SAndreas Gohr     * @param string $match The match of the syntax
53257dd7f8SAndreas Gohr     * @param int    $state The state of the handler
54257dd7f8SAndreas Gohr     * @param int    $pos The position in the document
55257dd7f8SAndreas Gohr     * @param Doku_Handler    $handler The handler
56257dd7f8SAndreas Gohr     * @return array Data for the renderer
57257dd7f8SAndreas Gohr     */
58257dd7f8SAndreas Gohr    public function handle($match, $state, $pos, Doku_Handler $handler){
5982c064c1SAndreas Gohr        // this is never called
6082c064c1SAndreas Gohr        return array();
61257dd7f8SAndreas Gohr    }
62257dd7f8SAndreas Gohr
63257dd7f8SAndreas Gohr    /**
6482c064c1SAndreas Gohr     * Render schema data
65257dd7f8SAndreas Gohr     *
6682c064c1SAndreas Gohr     * Currently completely renderer agnostic
6782c064c1SAndreas Gohr     *
6882c064c1SAndreas Gohr     * @todo add some classes for nicer styling when $mode = 'xhtml'
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;
81*2f1a213bSAndreas 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
87257dd7f8SAndreas Gohr        $R->table_open();
88257dd7f8SAndreas Gohr        $R->tabletbody_open();
89257dd7f8SAndreas Gohr        foreach($tables as $table) {
90257dd7f8SAndreas Gohr            $schemadata = new SchemaData($table, $ID, $REV);
91257dd7f8SAndreas Gohr            $data = $schemadata->getData();
92257dd7f8SAndreas Gohr
93257dd7f8SAndreas Gohr            foreach($data as $field) {
94257dd7f8SAndreas Gohr                $R->tablerow_open();
95257dd7f8SAndreas Gohr                $R->tableheader_open();
969e9bee91SAndreas Gohr                $R->cdata($field->getColumn()->getTranslatedLabel());
97257dd7f8SAndreas Gohr                $R->tableheader_close();
98257dd7f8SAndreas Gohr                $R->tablecell_open();
99257dd7f8SAndreas Gohr                $field->render($R, $mode);
100257dd7f8SAndreas Gohr                $R->tablecell_close();
101257dd7f8SAndreas Gohr                $R->tablerow_close();
102257dd7f8SAndreas Gohr            }
103257dd7f8SAndreas Gohr        }
104257dd7f8SAndreas Gohr        $R->tabletbody_close();
105257dd7f8SAndreas Gohr        $R->table_close();
106257dd7f8SAndreas Gohr
107257dd7f8SAndreas Gohr        return true;
108257dd7f8SAndreas Gohr    }
109257dd7f8SAndreas Gohr}
110257dd7f8SAndreas Gohr
111257dd7f8SAndreas Gohr// vim:ts=4:sw=4:et:
112