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