xref: /plugin/struct/meta/AggregationEditorTable.php (revision d90aa848684950ae06490f12279278db183f4fa5)
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{
14*d90aa848SAndreas Gohr    /** @inheritdoc */
15*d90aa848SAndreas Gohr    public function render($showNotFound = false)
16*d90aa848SAndreas Gohr    {
17*d90aa848SAndreas Gohr        parent::render(); // never show not found
18*d90aa848SAndreas Gohr    }
19*d90aa848SAndreas Gohr
20308cc83fSAndreas Gohr
21308cc83fSAndreas Gohr    /**
22308cc83fSAndreas Gohr     * Adds additional info to document and renderer in XHTML mode
23308cc83fSAndreas Gohr     *
24308cc83fSAndreas Gohr     * We add the schema name as data attribute
25308cc83fSAndreas Gohr     *
26308cc83fSAndreas Gohr     * @see finishScope()
27308cc83fSAndreas Gohr     */
28308cc83fSAndreas Gohr    protected function startScope()
29308cc83fSAndreas Gohr    {
30308cc83fSAndreas Gohr        // unique identifier for this aggregation
31308cc83fSAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
32308cc83fSAndreas Gohr
33308cc83fSAndreas Gohr        if ($this->mode != 'xhtml') return;
34308cc83fSAndreas Gohr
35308cc83fSAndreas Gohr        $table = $this->columns[0]->getTable();
36308cc83fSAndreas Gohr
37308cc83fSAndreas Gohr        $config = $this->searchConfig->getConf();
38308cc83fSAndreas Gohr        if (isset($config['filter'])) unset($config['filter']);
39308cc83fSAndreas Gohr        $config = hsc(json_encode($config));
40308cc83fSAndreas Gohr
41308cc83fSAndreas Gohr        // wrapping div
4217a3a578SAndreas Gohr        $this->renderer->doc .= "<div class=\"structaggregation structaggregationeditor\"
4317a3a578SAndreas Gohr                                      data-schema=\"$table\" data-searchconf=\"$config\">";
44308cc83fSAndreas Gohr
45308cc83fSAndreas Gohr        // unique identifier for this aggregation
46308cc83fSAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
47308cc83fSAndreas Gohr    }
48308cc83fSAndreas Gohr
49308cc83fSAndreas Gohr    /**
50308cc83fSAndreas Gohr     * We do not output a row for empty tables
51308cc83fSAndreas Gohr     */
52308cc83fSAndreas Gohr    protected function renderEmptyResult()
53308cc83fSAndreas Gohr    {
54308cc83fSAndreas Gohr    }
55308cc83fSAndreas Gohr
56308cc83fSAndreas Gohr    /**
57308cc83fSAndreas Gohr     * Renders the first result row and returns it
58308cc83fSAndreas Gohr     *
59308cc83fSAndreas Gohr     * Only used for rendering new rows via JS (where the first row is the only one)
60308cc83fSAndreas Gohr     *
61308cc83fSAndreas Gohr     * @return string
62308cc83fSAndreas Gohr     */
63308cc83fSAndreas Gohr    public function getFirstRow()
64308cc83fSAndreas Gohr    {
65308cc83fSAndreas Gohr        // XHTML renderer doesn't like calling ->tablerow_open() without
66308cc83fSAndreas Gohr        // ->table_open() first, since it leaves some internal variables unset.
67308cc83fSAndreas Gohr        // Therefore, call ->table_open() and throw away the generated HTML.
68308cc83fSAndreas Gohr        $this->renderer->table_open();
69308cc83fSAndreas Gohr        $this->renderer->doc = '';
70308cc83fSAndreas Gohr
71308cc83fSAndreas Gohr        $this->renderResultRow(0, $this->result[0]);
72308cc83fSAndreas Gohr        return $this->renderer->doc;
73308cc83fSAndreas Gohr    }
74308cc83fSAndreas Gohr}
75