xref: /plugin/struct/syntax/output.php (revision 17560ecbb3470cf2f90ee861205d92f6adf36b5b)
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
82        $assignments = new Assignments();
83        $tables = $assignments->getPageAssignments($ID);
84        if(!$tables) return true;
85
86        $R->table_open();
87        $R->tabletbody_open();
88        foreach($tables as $table) {
89            $schemadata = new SchemaData($table, $ID, $REV);
90            $data = $schemadata->getData();
91
92            foreach($data as $field) {
93                $R->tablerow_open();
94                $R->tableheader_open();
95                $R->cdata($field->getColumn()->getTranslatedLabel());
96                $R->tableheader_close();
97                $R->tablecell_open();
98                $field->render($R, $mode);
99                $R->tablecell_close();
100                $R->tablerow_close();
101            }
102        }
103        $R->tabletbody_close();
104        $R->table_close();
105
106        return true;
107    }
108}
109
110// vim:ts=4:sw=4:et:
111