1<?php
2/**
3 * DokuWiki Plugin tablelayout (Helper Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Michael Große <dokuwiki@cosmocode.de>
7 */
8
9// must be run within Dokuwiki
10if (!defined('DOKU_INC')) {
11    die();
12}
13
14/** @noinspection AutoloadingIssuesInspection */
15class helper_plugin_tablelayout extends DokuWiki_Plugin
16{
17
18    public function buildSyntaxFromJSON($json)
19    {
20        $layout = json_decode($json);
21        // todo check for decoding errors
22        $syntax = array();
23        if (!empty($layout->rowsHeaderSource)) {
24            $syntax[] = 'rowsHeaderSource=' . $layout->rowsHeaderSource;
25        }
26        if (!empty($layout->rowsVisible)) {
27            $syntax[] = 'rowsVisible=' . $layout->rowsVisible;
28        }
29        if (!empty($layout->colwidth)) {
30            $syntax[] = 'colwidth="' . implode(',', $layout->colwidth) . '"';
31        }
32        if (!empty($layout->float)) {
33            $syntax[] = 'float=' . $layout->float;
34        }
35        if (!empty($layout->tableSort)) {
36            $syntax[] = 'tableSort=1';
37        }
38        if (!empty($layout->tableSearch)) {
39            $syntax[] = 'tableSearch=1';
40        }
41        if (!empty($layout->tablePrint)) {
42            $syntax[] = 'tablePrint=1';
43        }
44
45        if (count($syntax) === 0) {
46            return '';
47        }
48        $syntax = '{{tablelayout?' . implode('&', $syntax) . '}}';
49
50        return $syntax;
51    }
52}
53