1<?php
2
3namespace dokuwiki\plugin\structodt\meta;
4
5use dokuwiki\plugin\struct\meta\SearchConfig;
6use dokuwiki\plugin\struct\meta\AggregationEditorTable;
7
8class AggregationEditorTableOdt extends AggregationEditorTable {
9
10    /** @var  string odt file used as export template */
11    protected $template;
12
13    /** @var bool download rendered files as PDFs */
14    protected $pdf;
15
16    /**
17     * @var \helper_plugin_structodt
18     */
19    protected $helper_structodt;
20
21    /**
22     * Initialize the Aggregation renderer and executes the search
23     *
24     * You need to call @see render() on the resulting object.
25     *
26     * @param string $id
27     * @param string $mode
28     * @param \Doku_Renderer $renderer
29     * @param SearchConfig $searchConfig
30     */
31    public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) {
32        parent::__construct($id, $mode, $renderer, $searchConfig);
33        $conf = $searchConfig->getConf();
34        $this->template = $conf['template'];
35        $this->pdf = $conf['pdf'];
36        $this->helper_structodt = plugin_load('helper', 'structodt');
37    }
38
39    /**
40     * Adds additional info to document and renderer in XHTML mode
41     *
42     * We add the schema name as data attribute
43     *
44     * @see finishScope()
45     */
46    protected function startScope()
47    {
48        // unique identifier for this aggregation
49        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
50
51        if ($this->mode != 'xhtml') return;
52
53        $table = $this->columns[0]->getTable();
54
55        $config = $this->searchConfig->getConf();
56        if (isset($config['filter'])) unset($config['filter']);
57        $config = hsc(json_encode($config));
58
59        $filetype = $this->pdf ? 'pdf' : 'odt';
60        $template = $this->template;
61
62        // wrapping div
63        $this->renderer->doc .= "<div class=\"structaggregation structaggregationeditor structodt\" data-schema=\"$table\" data-searchconf=\"$config\"
64                                    data-template=\"$template\" data-filetype=\"$filetype\">";
65
66        // unique identifier for this aggregation
67        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
68    }
69}