xref: /plugin/struct/meta/AggregationEditorTable.php (revision 4bffd43680da9f5ab6f22a645c1f04bbe99210f8)
1<?php
2
3namespace dokuwiki\plugin\struct\meta;
4
5/**
6 * Class AggregationEditorTable
7 *
8 * An AggregationTable for editing global and serial tables
9 *
10 * @package dokuwiki\plugin\struct\meta
11 */
12class AggregationEditorTable extends AggregationTable
13{
14    /** @inheritdoc */
15    public function render($showNotFound = false)
16    {
17        parent::render(); // never show not found
18    }
19
20
21    /**
22     * Adds additional info to document and renderer in XHTML mode
23     *
24     * We add the schema name as data attribute
25     *
26     * @see finishScope()
27     */
28    public function startScope()
29    {
30        // unique identifier for this aggregation
31        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
32
33        if ($this->mode != 'xhtml') return;
34
35        $table = $this->columns[0]->getTable();
36
37        $config = $this->searchConfig->getConf();
38        if (isset($config['filter'])) unset($config['filter']);
39        $config = hsc(json_encode($config));
40
41        // wrapping div
42        $classes = $this->getScopeClasses();
43        $classes[] = 'structaggregationeditor';
44        $classes = implode(' ', $classes);
45        $this->renderer->doc .= "<div class=\"$classes\"
46                                      data-schema=\"$table\" data-searchconf=\"$config\">";
47
48        // unique identifier for this aggregation
49        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
50    }
51
52    /**
53     * We do not output a row for empty tables
54     */
55    protected function renderEmptyResult()
56    {
57    }
58
59    /**
60     * Renders the first result row and returns it
61     *
62     * Only used for rendering new rows via JS (where the first row is the only one)
63     *
64     * @return string
65     */
66    public function getFirstRow()
67    {
68        // XHTML renderer doesn't like calling ->tablerow_open() without
69        // ->table_open() first, since it leaves some internal variables unset.
70        // Therefore, call ->table_open() and throw away the generated HTML.
71        $this->renderer->table_open();
72        $this->renderer->doc = '';
73
74        $this->renderResultRow(0, $this->result[0]);
75        return $this->renderer->doc;
76    }
77}
78