xref: /plugin/struct/meta/AggregationEditorTable.php (revision 17a3a5782666ca8742a2c64cc11565d4f9fe1076)
1308cc83fSAndreas Gohr<?php
2308cc83fSAndreas Gohr
3308cc83fSAndreas Gohrnamespace dokuwiki\plugin\struct\meta;
4308cc83fSAndreas Gohr
5308cc83fSAndreas Gohr/**
6308cc83fSAndreas Gohr * Class AggregationEditorTable
7308cc83fSAndreas Gohr *
8308cc83fSAndreas Gohr * An AggregationTable for editing global and serial tables
9308cc83fSAndreas Gohr *
10308cc83fSAndreas Gohr * @package dokuwiki\plugin\struct\meta
11308cc83fSAndreas Gohr */
12308cc83fSAndreas Gohrclass AggregationEditorTable extends AggregationTable
13308cc83fSAndreas Gohr{
14308cc83fSAndreas Gohr    /**
15308cc83fSAndreas Gohr     * @var bool skip full table when no results found
16308cc83fSAndreas Gohr     */
17308cc83fSAndreas Gohr    protected $simplenone = false;
18308cc83fSAndreas Gohr
19308cc83fSAndreas Gohr    /**
20308cc83fSAndreas Gohr     * Adds additional info to document and renderer in XHTML mode
21308cc83fSAndreas Gohr     *
22308cc83fSAndreas Gohr     * We add the schema name as data attribute
23308cc83fSAndreas Gohr     *
24308cc83fSAndreas Gohr     * @see finishScope()
25308cc83fSAndreas Gohr     */
26308cc83fSAndreas Gohr    protected function startScope()
27308cc83fSAndreas Gohr    {
28308cc83fSAndreas Gohr        // unique identifier for this aggregation
29308cc83fSAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
30308cc83fSAndreas Gohr
31308cc83fSAndreas Gohr        if ($this->mode != 'xhtml') return;
32308cc83fSAndreas Gohr
33308cc83fSAndreas Gohr        $table = $this->columns[0]->getTable();
34308cc83fSAndreas Gohr
35308cc83fSAndreas Gohr        $config = $this->searchConfig->getConf();
36308cc83fSAndreas Gohr        if (isset($config['filter'])) unset($config['filter']);
37308cc83fSAndreas Gohr        $config = hsc(json_encode($config));
38308cc83fSAndreas Gohr
39308cc83fSAndreas Gohr        // wrapping div
40*17a3a578SAndreas Gohr        $this->renderer->doc .= "<div class=\"structaggregation structaggregationeditor\"
41*17a3a578SAndreas Gohr                                      data-schema=\"$table\" data-searchconf=\"$config\">";
42308cc83fSAndreas Gohr
43308cc83fSAndreas Gohr        // unique identifier for this aggregation
44308cc83fSAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
45308cc83fSAndreas Gohr    }
46308cc83fSAndreas Gohr
47308cc83fSAndreas Gohr    /**
48308cc83fSAndreas Gohr     * We do not output a row for empty tables
49308cc83fSAndreas Gohr     */
50308cc83fSAndreas Gohr    protected function renderEmptyResult()
51308cc83fSAndreas Gohr    {
52308cc83fSAndreas Gohr    }
53308cc83fSAndreas Gohr
54308cc83fSAndreas Gohr    /**
55308cc83fSAndreas Gohr     * Renders the first result row and returns it
56308cc83fSAndreas Gohr     *
57308cc83fSAndreas Gohr     * Only used for rendering new rows via JS (where the first row is the only one)
58308cc83fSAndreas Gohr     *
59308cc83fSAndreas Gohr     * @return string
60308cc83fSAndreas Gohr     */
61308cc83fSAndreas Gohr    public function getFirstRow()
62308cc83fSAndreas Gohr    {
63308cc83fSAndreas Gohr        // XHTML renderer doesn't like calling ->tablerow_open() without
64308cc83fSAndreas Gohr        // ->table_open() first, since it leaves some internal variables unset.
65308cc83fSAndreas Gohr        // Therefore, call ->table_open() and throw away the generated HTML.
66308cc83fSAndreas Gohr        $this->renderer->table_open();
67308cc83fSAndreas Gohr        $this->renderer->doc = '';
68308cc83fSAndreas Gohr
69308cc83fSAndreas Gohr        $this->renderResultRow(0, $this->result[0]);
70308cc83fSAndreas Gohr        return $this->renderer->doc;
71308cc83fSAndreas Gohr    }
72308cc83fSAndreas Gohr}
73