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