xref: /plugin/struct/meta/AggregationEditorTable.php (revision 308cc83fd5391df29d21d2bc1306c8da49fdb335)
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
15    /**
16     * @var bool skip full table when no results found
17     */
18    protected $simplenone = false;
19
20    /**
21     * Adds additional info to document and renderer in XHTML mode
22     *
23     * We add the schema name as data attribute
24     *
25     * @see finishScope()
26     */
27    protected function startScope()
28    {
29        // unique identifier for this aggregation
30        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
31
32        if ($this->mode != 'xhtml') return;
33
34        $table = $this->columns[0]->getTable();
35
36        $config = $this->searchConfig->getConf();
37        if (isset($config['filter'])) unset($config['filter']);
38        $config = hsc(json_encode($config));
39
40        // wrapping div
41        $this->renderer->doc .= "<div class=\"structaggregation structaggregationeditor\" data-schema=\"$table\" data-searchconf=\"$config\">";
42
43        // unique identifier for this aggregation
44        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
45    }
46
47    /**
48     * We do not output a row for empty tables
49     */
50    protected function renderEmptyResult()
51    {
52    }
53
54    /**
55     * Renders the first result row and returns it
56     *
57     * Only used for rendering new rows via JS (where the first row is the only one)
58     *
59     * @return string
60     */
61    public function getFirstRow()
62    {
63        // XHTML renderer doesn't like calling ->tablerow_open() without
64        // ->table_open() first, since it leaves some internal variables unset.
65        // Therefore, call ->table_open() and throw away the generated HTML.
66        $this->renderer->table_open();
67        $this->renderer->doc = '';
68
69        $this->renderResultRow(0, $this->result[0]);
70        return $this->renderer->doc;
71    }
72}
73