xref: /plugin/struct/syntax/output.php (revision 33e429a8d9965918d4772b31235df1e31b85d4ef)
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 we currently have no schema headlines
6982c064c1SAndreas Gohr     *
7082c064c1SAndreas Gohr     * @param string         $mode      Renderer mode
71257dd7f8SAndreas Gohr     * @param Doku_Renderer  $R         The renderer
72257dd7f8SAndreas Gohr     * @param array          $data      The data from the handler() function
73257dd7f8SAndreas Gohr     * @return bool If rendering was successful.
74257dd7f8SAndreas Gohr     */
75257dd7f8SAndreas Gohr    public function render($mode, Doku_Renderer $R, $data) {
76257dd7f8SAndreas Gohr        global $ID;
7782c064c1SAndreas Gohr        global $INFO;
78257dd7f8SAndreas Gohr        global $REV;
7982c064c1SAndreas Gohr        if($ID != $INFO['id']) return true;
802f1a213bSAndreas Gohr        if(!$INFO['exists']) return true;
81257dd7f8SAndreas Gohr
82257dd7f8SAndreas Gohr        $assignments = new Assignments();
83257dd7f8SAndreas Gohr        $tables = $assignments->getPageAssignments($ID);
84257dd7f8SAndreas Gohr        if(!$tables) return true;
85257dd7f8SAndreas Gohr
865a1eab78SAndreas Gohr        if($mode == 'xhtml') $R->doc .= '<div id="plugin__struct_output">';
875a1eab78SAndreas Gohr        $R->header($this->getLang('headline'), 1, $data['pos']);
885a1eab78SAndreas Gohr
89257dd7f8SAndreas Gohr        $R->table_open();
90257dd7f8SAndreas Gohr        $R->tabletbody_open();
91257dd7f8SAndreas Gohr        foreach($tables as $table) {
92257dd7f8SAndreas Gohr            $schemadata = new SchemaData($table, $ID, $REV);
93*33e429a8SAndreas Gohr            $data = $schemadata->getData(true);
94257dd7f8SAndreas Gohr
95257dd7f8SAndreas Gohr            foreach($data as $field) {
96257dd7f8SAndreas Gohr                $R->tablerow_open();
97257dd7f8SAndreas Gohr                $R->tableheader_open();
989e9bee91SAndreas Gohr                $R->cdata($field->getColumn()->getTranslatedLabel());
99257dd7f8SAndreas Gohr                $R->tableheader_close();
100257dd7f8SAndreas Gohr                $R->tablecell_open();
101257dd7f8SAndreas Gohr                $field->render($R, $mode);
102257dd7f8SAndreas Gohr                $R->tablecell_close();
103257dd7f8SAndreas Gohr                $R->tablerow_close();
104257dd7f8SAndreas Gohr            }
105257dd7f8SAndreas Gohr        }
106257dd7f8SAndreas Gohr        $R->tabletbody_close();
107257dd7f8SAndreas Gohr        $R->table_close();
108257dd7f8SAndreas Gohr
1095a1eab78SAndreas Gohr        if($mode == 'xhtml') $R->doc .= '</div>';
1105a1eab78SAndreas Gohr
111257dd7f8SAndreas Gohr        return true;
112257dd7f8SAndreas Gohr    }
113257dd7f8SAndreas Gohr}
114257dd7f8SAndreas Gohr
115257dd7f8SAndreas Gohr// vim:ts=4:sw=4:et:
116