xref: /plugin/struct/meta/AggregationEditorTable.php (revision 1ee0a2dc290e607b00cb9d6d919f4f60a00fcd2d)
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    protected 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        $this->renderer->doc .= "<div class=\"structaggregation structaggregationeditor\"
43                                      data-schema=\"$table\" data-searchconf=\"$config\">";
44
45        // unique identifier for this aggregation
46        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
47    }
48
49    /**
50     * We do not output a row for empty tables
51     */
52    protected function renderEmptyResult()
53    {
54    }
55
56    /**
57     * Renders the first result row and returns it
58     *
59     * Only used for rendering new rows via JS (where the first row is the only one)
60     *
61     * @return string
62     */
63    public function getFirstRow()
64    {
65        // XHTML renderer doesn't like calling ->tablerow_open() without
66        // ->table_open() first, since it leaves some internal variables unset.
67        // Therefore, call ->table_open() and throw away the generated HTML.
68        $this->renderer->table_open();
69        $this->renderer->doc = '';
70
71        $this->renderResultRow(0, $this->result[0]);
72        return $this->renderer->doc;
73    }
74}
75