xref: /plugin/struct/meta/AggregationTable.php (revision a9fd81f9611d686f1563626cfcc1fd7c94486aa5)
107993756SAndreas Gohr<?php
207993756SAndreas Gohr
3ba766201SAndreas Gohrnamespace dokuwiki\plugin\struct\meta;
407993756SAndreas Gohr
5d60f71efSAndreas Gohr/**
6d60f71efSAndreas Gohr * Creates the table aggregation output
7d60f71efSAndreas Gohr *
8ba766201SAndreas Gohr * @package dokuwiki\plugin\struct\meta
9d60f71efSAndreas Gohr */
1007993756SAndreas Gohrclass AggregationTable {
1107993756SAndreas Gohr
1207993756SAndreas Gohr    /**
1307993756SAndreas Gohr     * @var string the page id of the page this is rendered to
1407993756SAndreas Gohr     */
1507993756SAndreas Gohr    protected $id;
1607993756SAndreas Gohr    /**
1707993756SAndreas Gohr     * @var string the Type of renderer used
1807993756SAndreas Gohr     */
1907993756SAndreas Gohr    protected $mode;
2007993756SAndreas Gohr    /**
2107993756SAndreas Gohr     * @var \Doku_Renderer the DokuWiki renderer used to create the output
2207993756SAndreas Gohr     */
2307993756SAndreas Gohr    protected $renderer;
2407993756SAndreas Gohr    /**
2507993756SAndreas Gohr     * @var SearchConfig the configured search - gives access to columns etc.
2607993756SAndreas Gohr     */
2707993756SAndreas Gohr    protected $searchConfig;
2807993756SAndreas Gohr
2907993756SAndreas Gohr    /**
3007993756SAndreas Gohr     * @var Column[] the list of columns to be displayed
3107993756SAndreas Gohr     */
3207993756SAndreas Gohr    protected $columns;
3307993756SAndreas Gohr
3407993756SAndreas Gohr    /**
3507993756SAndreas Gohr     * @var  Value[][] the search result
3607993756SAndreas Gohr     */
3707993756SAndreas Gohr    protected $result;
3807993756SAndreas Gohr
3907993756SAndreas Gohr    /**
4007993756SAndreas Gohr     * @var int number of all results
4107993756SAndreas Gohr     */
4207993756SAndreas Gohr    protected $resultCount;
4307993756SAndreas Gohr
4407993756SAndreas Gohr    /**
45d4b5a17cSAndreas Gohr     * @var string[] the result PIDs for each row
46d4b5a17cSAndreas Gohr     */
47d4b5a17cSAndreas Gohr    protected $resultPIDs;
48d4b5a17cSAndreas Gohr
49d4b5a17cSAndreas Gohr    /**
5007993756SAndreas Gohr     * @var array for summing up columns
5107993756SAndreas Gohr     */
5207993756SAndreas Gohr    protected $sums;
5307993756SAndreas Gohr
5407993756SAndreas Gohr    /**
556b5e52fdSAndreas Gohr     * @var bool skip full table when no results found
566b5e52fdSAndreas Gohr     */
576b5e52fdSAndreas Gohr    protected $simplenone = true;
586b5e52fdSAndreas Gohr
596b5e52fdSAndreas Gohr    /**
6007993756SAndreas Gohr     * @todo we might be able to get rid of this helper and move this to SearchConfig
6107993756SAndreas Gohr     * @var \helper_plugin_struct_config
6207993756SAndreas Gohr     */
6307993756SAndreas Gohr    protected $helper;
6407993756SAndreas Gohr
6507993756SAndreas Gohr    /**
6607993756SAndreas Gohr     * Initialize the Aggregation renderer and executes the search
6707993756SAndreas Gohr     *
6807993756SAndreas Gohr     * You need to call @see render() on the resulting object.
6907993756SAndreas Gohr     *
7007993756SAndreas Gohr     * @param string $id
7107993756SAndreas Gohr     * @param string $mode
7207993756SAndreas Gohr     * @param \Doku_Renderer $renderer
7307993756SAndreas Gohr     * @param SearchConfig $searchConfig
7407993756SAndreas Gohr     */
7507993756SAndreas Gohr    public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) {
7607993756SAndreas Gohr        $this->id = $id;
7707993756SAndreas Gohr        $this->mode = $mode;
7807993756SAndreas Gohr        $this->renderer = $renderer;
7907993756SAndreas Gohr        $this->searchConfig = $searchConfig;
8007993756SAndreas Gohr        $this->data = $searchConfig->getConf();
8107993756SAndreas Gohr        $this->columns = $searchConfig->getColumns();
8207993756SAndreas Gohr
8307993756SAndreas Gohr        $this->result = $this->searchConfig->execute();
8407993756SAndreas Gohr        $this->resultCount = $this->searchConfig->getCount();
85d4b5a17cSAndreas Gohr        $this->resultPIDs = $this->searchConfig->getPids();
8607993756SAndreas Gohr        $this->helper = plugin_load('helper', 'struct_config');
8707993756SAndreas Gohr    }
8807993756SAndreas Gohr
8907993756SAndreas Gohr    /**
9007993756SAndreas Gohr     * Create the table on the renderer
9107993756SAndreas Gohr     */
9207993756SAndreas Gohr    public function render() {
93b7e1d73bSAndreas Gohr
94b7e1d73bSAndreas Gohr        // abort early if there are no results at all (not filtered)
956b5e52fdSAndreas Gohr        if(!$this->resultCount && !$this->isDynamicallyFiltered() && $this->simplenone) {
96b7e1d73bSAndreas Gohr            $this->startScope();
97b7e1d73bSAndreas Gohr            $this->renderer->cdata($this->helper->getLang('none'));
98b7e1d73bSAndreas Gohr            $this->finishScope();
99b7e1d73bSAndreas Gohr            return;
100b7e1d73bSAndreas Gohr        }
101b7e1d73bSAndreas Gohr
10207993756SAndreas Gohr        // table open
10307993756SAndreas Gohr        $this->startScope();
104986ab7e6SAndreas Gohr        $this->renderActiveFilters();
10507993756SAndreas Gohr        $this->renderer->table_open();
10607993756SAndreas Gohr
10707993756SAndreas Gohr        // header
10807993756SAndreas Gohr        $this->renderer->tablethead_open();
109986ab7e6SAndreas Gohr        $this->renderColumnHeaders();
110986ab7e6SAndreas Gohr        $this->renderDynamicFilters();
11107993756SAndreas Gohr        $this->renderer->tablethead_close();
11207993756SAndreas Gohr
11307993756SAndreas Gohr        if($this->resultCount) {
11407993756SAndreas Gohr            // actual data
115*a9fd81f9SAndreas Gohr            $this->renderer->tabletbody_open();
116986ab7e6SAndreas Gohr            $this->renderResult();
117*a9fd81f9SAndreas Gohr            $this->renderer->tabletbody_close();
11807993756SAndreas Gohr
119*a9fd81f9SAndreas Gohr            // footer (tfoot is develonly currently)
120*a9fd81f9SAndreas Gohr            if(method_exists($this->renderer, 'tabletfoot_open')) $this->renderer->tabletfoot_open();
121986ab7e6SAndreas Gohr            $this->renderSums();
122986ab7e6SAndreas Gohr            $this->renderPagingControls();
123*a9fd81f9SAndreas Gohr            if(method_exists($this->renderer, 'tabletfoot_close')) $this->renderer->tabletfoot_close();
12407993756SAndreas Gohr        } else {
12507993756SAndreas Gohr            // nothing found
126986ab7e6SAndreas Gohr            $this->renderEmptyResult();
12707993756SAndreas Gohr        }
12807993756SAndreas Gohr
12907993756SAndreas Gohr        // table close
13007993756SAndreas Gohr        $this->renderer->table_close();
13109dd691aSAndreas Gohr
13209dd691aSAndreas Gohr        // export handle
13309dd691aSAndreas Gohr        $this->renderExportControls();
13407993756SAndreas Gohr        $this->finishScope();
13507993756SAndreas Gohr    }
13607993756SAndreas Gohr
13707993756SAndreas Gohr    /**
13807993756SAndreas Gohr     * Adds additional info to document and renderer in XHTML mode
13907993756SAndreas Gohr     *
14007993756SAndreas Gohr     * @see finishScope()
14107993756SAndreas Gohr     */
14207993756SAndreas Gohr    protected function startScope() {
14307993756SAndreas Gohr        // unique identifier for this aggregation
14407993756SAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
14509dd691aSAndreas Gohr
14609dd691aSAndreas Gohr        // wrapping div
14709dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
14809dd691aSAndreas Gohr        $this->renderer->doc .= "<div class=\"structaggregation\">";
14907993756SAndreas Gohr    }
15007993756SAndreas Gohr
15107993756SAndreas Gohr    /**
15207993756SAndreas Gohr     * Closes the table and anything opened in startScope()
15307993756SAndreas Gohr     *
15407993756SAndreas Gohr     * @see startScope()
15507993756SAndreas Gohr     */
15607993756SAndreas Gohr    protected function finishScope() {
15707993756SAndreas Gohr        // remove identifier from renderer again
15807993756SAndreas Gohr        if(isset($this->renderer->info['struct_table_hash'])) {
15907993756SAndreas Gohr            unset($this->renderer->info['struct_table_hash']);
16007993756SAndreas Gohr        }
16109dd691aSAndreas Gohr
16209dd691aSAndreas Gohr        // wrapping div
16309dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
16409dd691aSAndreas Gohr        $this->renderer->doc .= '</div>';
16507993756SAndreas Gohr    }
16607993756SAndreas Gohr
16707993756SAndreas Gohr    /**
16807993756SAndreas Gohr     * Displays info about the currently applied filters
16907993756SAndreas Gohr     */
170986ab7e6SAndreas Gohr    protected function renderActiveFilters() {
17107993756SAndreas Gohr        if($this->mode != 'xhtml') return;
17207993756SAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
17307993756SAndreas Gohr        $filters = $dynamic->getFilters();
17407993756SAndreas Gohr        if(!$filters) return;
17507993756SAndreas Gohr
17607993756SAndreas Gohr        $fltrs = array();
17707993756SAndreas Gohr        foreach($filters as $column => $filter) {
17807993756SAndreas Gohr            list($comp, $value) = $filter;
179083109a1SAndreas Gohr            $fltrs[] = $column . ' ' . $comp . ' ' . $value;
18007993756SAndreas Gohr        }
18107993756SAndreas Gohr
18207993756SAndreas Gohr        $this->renderer->doc .= '<div class="filter">';
18307993756SAndreas Gohr        $this->renderer->doc .= '<h4>' . sprintf($this->helper->getLang('tablefilteredby'), hsc(implode(' & ', $fltrs))) . '</h4>';
18407993756SAndreas Gohr        $this->renderer->doc .= '<div class="resetfilter">';
18507993756SAndreas Gohr        $this->renderer->internallink($this->id, $this->helper->getLang('tableresetfilter'));
18607993756SAndreas Gohr        $this->renderer->doc .= '</div>';
18707993756SAndreas Gohr        $this->renderer->doc .= '</div>';
18807993756SAndreas Gohr    }
18907993756SAndreas Gohr
19007993756SAndreas Gohr    /**
19107993756SAndreas Gohr     * Shows the column headers with links to sort by column
19207993756SAndreas Gohr     */
193986ab7e6SAndreas Gohr    protected function renderColumnHeaders() {
19407993756SAndreas Gohr        $this->renderer->tablerow_open();
19507993756SAndreas Gohr
19607993756SAndreas Gohr        // additional column for row numbers
19707993756SAndreas Gohr        if($this->data['rownumbers']) {
19807993756SAndreas Gohr            $this->renderer->tableheader_open();
19907993756SAndreas Gohr            $this->renderer->cdata('#');
20007993756SAndreas Gohr            $this->renderer->tableheader_close();
20107993756SAndreas Gohr        }
20207993756SAndreas Gohr
20307993756SAndreas Gohr        // show all headers
2048c4ee9beSAndreas Gohr        foreach($this->columns as $num => $column) {
2058c4ee9beSAndreas Gohr            $header = '';
2068c4ee9beSAndreas Gohr            if(isset($this->data['headers'][$num])) {
2078c4ee9beSAndreas Gohr                $header = $this->data['headers'][$num];
2088c4ee9beSAndreas Gohr            }
20907993756SAndreas Gohr
21007993756SAndreas Gohr            // use field label if no header was set
21107993756SAndreas Gohr            if(blank($header)) {
21201f8b845SAndreas Gohr                if(is_a($column, 'dokuwiki\plugin\struct\meta\Column')) {
21307993756SAndreas Gohr                    $header = $column->getTranslatedLabel();
21407993756SAndreas Gohr                } else {
21507993756SAndreas Gohr                    $header = 'column ' . $num; // this should never happen
21607993756SAndreas Gohr                }
21707993756SAndreas Gohr            }
21807993756SAndreas Gohr
21907993756SAndreas Gohr            // simple mode first
22007993756SAndreas Gohr            if($this->mode != 'xhtml') {
22107993756SAndreas Gohr                $this->renderer->tableheader_open();
22207993756SAndreas Gohr                $this->renderer->cdata($header);
22307993756SAndreas Gohr                $this->renderer->tableheader_close();
22407993756SAndreas Gohr                continue;
22507993756SAndreas Gohr            }
22607993756SAndreas Gohr
22707993756SAndreas Gohr            // still here? create custom header for more flexibility
22807993756SAndreas Gohr
22907993756SAndreas Gohr            // width setting
23007993756SAndreas Gohr            $width = '';
23107993756SAndreas Gohr            if(isset($data['widths'][$num]) && $data['widths'][$num] != '-') {
232e0216289SAndreas Gohr                $width = ' style="width: ' . $data['widths'][$num] . ';"'; // widths are prevalidated, no escape needed
23307993756SAndreas Gohr            }
23407993756SAndreas Gohr
235d4b5a17cSAndreas Gohr            // prepare data attribute for inline edits
236d4b5a17cSAndreas Gohr            if(!is_a($column, '\dokuwiki\plugin\struct\meta\PageColumn') &&
237d4b5a17cSAndreas Gohr                !is_a($column, '\dokuwiki\plugin\struct\meta\RevisionColumn')
238d4b5a17cSAndreas Gohr            ) {
239d4b5a17cSAndreas Gohr                $data = 'data-field="' . hsc($column->getFullQualifiedLabel()) . '"';
240d4b5a17cSAndreas Gohr            } else {
241d4b5a17cSAndreas Gohr                $data = '';
242d4b5a17cSAndreas Gohr            }
243d4b5a17cSAndreas Gohr
24407993756SAndreas Gohr            // sort indicator and link
24507993756SAndreas Gohr            $sortclass = '';
24607993756SAndreas Gohr            $sorts = $this->searchConfig->getSorts();
24707993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
248aa124708SAndreas Gohr            $dynamic->setSort($column, true);
24907993756SAndreas Gohr            if(isset($sorts[$column->getFullQualifiedLabel()])) {
250aa124708SAndreas Gohr                list(/*colname*/, $currentSort) = $sorts[$column->getFullQualifiedLabel()];
251aa124708SAndreas Gohr                if($currentSort) {
25207993756SAndreas Gohr                    $sortclass = 'sort-down';
25307993756SAndreas Gohr                    $dynamic->setSort($column, false);
25407993756SAndreas Gohr                } else {
25507993756SAndreas Gohr                    $sortclass = 'sort-up';
25607993756SAndreas Gohr                }
25707993756SAndreas Gohr            }
25807993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
25907993756SAndreas Gohr
26007993756SAndreas Gohr            // output XHTML header
261d4b5a17cSAndreas Gohr            $this->renderer->doc .= "<th $width $data>";
26207993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="' . $sortclass . '" title="' . $this->helper->getLang('sort') . '">' . hsc($header) . '</a>';
26307993756SAndreas Gohr            $this->renderer->doc .= '</th>';
26407993756SAndreas Gohr        }
26507993756SAndreas Gohr
26607993756SAndreas Gohr        $this->renderer->tablerow_close();
26707993756SAndreas Gohr    }
26807993756SAndreas Gohr
26907993756SAndreas Gohr    /**
270b7e1d73bSAndreas Gohr     * Is the result set currently dynamically filtered?
271b7e1d73bSAndreas Gohr     * @return bool
272b7e1d73bSAndreas Gohr     */
273b7e1d73bSAndreas Gohr    protected function isDynamicallyFiltered() {
274b7e1d73bSAndreas Gohr        if($this->mode != 'xhtml') return false;
275b7e1d73bSAndreas Gohr        if(!$this->data['dynfilters']) return false;
276b7e1d73bSAndreas Gohr
277b7e1d73bSAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
278b7e1d73bSAndreas Gohr        return (bool) $dynamic->getFilters();
279b7e1d73bSAndreas Gohr    }
280b7e1d73bSAndreas Gohr
281b7e1d73bSAndreas Gohr    /**
28207993756SAndreas Gohr     * Add input fields for dynamic filtering
28307993756SAndreas Gohr     */
284986ab7e6SAndreas Gohr    protected function renderDynamicFilters() {
28507993756SAndreas Gohr        if($this->mode != 'xhtml') return;
28607993756SAndreas Gohr        if(!$this->data['dynfilters']) return;
2871bc467a4SMichael Grosse        if (is_a($this->renderer, 'renderer_plugin_dw2pdf')) {
288e6ae02ecSMichael Grosse            return;
289e6ae02ecSMichael Grosse        }
2901bc467a4SMichael Grosse        global $conf;
29107993756SAndreas Gohr
29207993756SAndreas Gohr        $this->renderer->doc .= '<tr class="dataflt">';
29307993756SAndreas Gohr
29407993756SAndreas Gohr        // add extra column for row numbers
29507993756SAndreas Gohr        if($this->data['rownumbers']) {
29607993756SAndreas Gohr            $this->renderer->doc .= '<th></th>';
29707993756SAndreas Gohr        }
29807993756SAndreas Gohr
29907993756SAndreas Gohr        // each column gets a form
30007993756SAndreas Gohr        foreach($this->columns as $column) {
30107993756SAndreas Gohr            $this->renderer->doc .= '<th>';
30207993756SAndreas Gohr            {
30307993756SAndreas Gohr                $form = new \Doku_Form(array('method' => 'GET', 'action' => wl($this->id)));
30476195677SAndreas Gohr                unset($form->_hidden['sectok']); // we don't need it here
30576195677SAndreas Gohr                if(!$conf['userewrite']) $form->addHidden('id', $this->id);
30607993756SAndreas Gohr
30707993756SAndreas Gohr                // current value
30807993756SAndreas Gohr                $dynamic = $this->searchConfig->getDynamicParameters();
30907993756SAndreas Gohr                $filters = $dynamic->getFilters();
31007993756SAndreas Gohr                if(isset($filters[$column->getFullQualifiedLabel()])) {
31107993756SAndreas Gohr                    list(, $current) = $filters[$column->getFullQualifiedLabel()];
31207993756SAndreas Gohr                    $dynamic->removeFilter($column);
31307993756SAndreas Gohr                } else {
31407993756SAndreas Gohr                    $current = '';
31507993756SAndreas Gohr                }
31607993756SAndreas Gohr
31707993756SAndreas Gohr                // Add current request params
31807993756SAndreas Gohr                $params = $dynamic->getURLParameters();
31907993756SAndreas Gohr                foreach($params as $key => $val) {
32007993756SAndreas Gohr                    $form->addHidden($key, $val);
32107993756SAndreas Gohr                }
32207993756SAndreas Gohr
32307993756SAndreas Gohr                // add input field
32407993756SAndreas Gohr                $key = $column->getFullQualifiedLabel() . '*~';
325d60f71efSAndreas Gohr                $form->addElement(form_makeField('text', SearchConfigParameters::$PARAM_FILTER . '[' . $key . ']', $current, ''));
32607993756SAndreas Gohr                $this->renderer->doc .= $form->getForm();
32707993756SAndreas Gohr            }
32807993756SAndreas Gohr            $this->renderer->doc .= '</th>';
32907993756SAndreas Gohr        }
33007993756SAndreas Gohr        $this->renderer->doc .= '</tr>';
33107993756SAndreas Gohr
33207993756SAndreas Gohr    }
33307993756SAndreas Gohr
33407993756SAndreas Gohr    /**
33507993756SAndreas Gohr     * Display the actual table data
33607993756SAndreas Gohr     */
337986ab7e6SAndreas Gohr    protected function renderResult() {
33807993756SAndreas Gohr        foreach($this->result as $rownum => $row) {
339f107f479SAndreas Gohr            $this->renderResultRow($rownum, $row);
340f107f479SAndreas Gohr        }
341f107f479SAndreas Gohr    }
342f107f479SAndreas Gohr
343f107f479SAndreas Gohr    /**
344f107f479SAndreas Gohr     * Render a single result row
345f107f479SAndreas Gohr     *
346f107f479SAndreas Gohr     * @param int $rownum
347f107f479SAndreas Gohr     * @param array $row
348f107f479SAndreas Gohr     */
349f107f479SAndreas Gohr    protected function renderResultRow($rownum, $row) {
35007993756SAndreas Gohr        $this->renderer->tablerow_open();
35107993756SAndreas Gohr
352d4b5a17cSAndreas Gohr        // add data attribute for inline edit
353d4b5a17cSAndreas Gohr        if($this->mode == 'xhtml') {
354d4b5a17cSAndreas Gohr            $pid = $this->resultPIDs[$rownum];
355d4b5a17cSAndreas Gohr            $this->renderer->doc = substr(rtrim($this->renderer->doc), 0, -1); // remove closing '>'
356d4b5a17cSAndreas Gohr            $this->renderer->doc .= ' data-pid="' . hsc($pid) . '">';
357d4b5a17cSAndreas Gohr        }
358d4b5a17cSAndreas Gohr
35907993756SAndreas Gohr        // row number column
36007993756SAndreas Gohr        if($this->data['rownumbers']) {
36107993756SAndreas Gohr            $this->renderer->tablecell_open();
36209dd691aSAndreas Gohr            $this->renderer->cdata($rownum + 1);
36307993756SAndreas Gohr            $this->renderer->tablecell_close();
36407993756SAndreas Gohr        }
36507993756SAndreas Gohr
36607993756SAndreas Gohr        /** @var Value $value */
3679cda5805SAndreas Gohr        $col = -1;
36807993756SAndreas Gohr        foreach($row as $colnum => $value) {
36995eef580SAndreas Gohr            $this->renderer->tablecell_open(1, $this->data['align'][$colnum]);
37007993756SAndreas Gohr            $value->render($this->renderer, $this->mode);
37107993756SAndreas Gohr            $this->renderer->tablecell_close();
37207993756SAndreas Gohr
37307993756SAndreas Gohr            // summarize
37407993756SAndreas Gohr            if($this->data['summarize'] && is_numeric($value->getValue())) {
37507993756SAndreas Gohr                if(!isset($this->sums[$colnum])) {
37607993756SAndreas Gohr                    $this->sums[$colnum] = 0;
37707993756SAndreas Gohr                }
37807993756SAndreas Gohr                $this->sums[$colnum] += $value->getValue();
37907993756SAndreas Gohr            }
38007993756SAndreas Gohr        }
38107993756SAndreas Gohr        $this->renderer->tablerow_close();
38207993756SAndreas Gohr    }
38307993756SAndreas Gohr
38407993756SAndreas Gohr    /**
38507993756SAndreas Gohr     * Renders an information row for when no results were found
38607993756SAndreas Gohr     */
387986ab7e6SAndreas Gohr    protected function renderEmptyResult() {
38807993756SAndreas Gohr        $this->renderer->tablerow_open();
38970cf6339SAndreas Gohr        $this->renderer->tablecell_open(count($this->columns) + $this->data['rownumbers'], 'center');
39007993756SAndreas Gohr        $this->renderer->cdata($this->helper->getLang('none'));
39107993756SAndreas Gohr        $this->renderer->tablecell_close();
39207993756SAndreas Gohr        $this->renderer->tablerow_close();
39307993756SAndreas Gohr    }
39407993756SAndreas Gohr
39507993756SAndreas Gohr    /**
39607993756SAndreas Gohr     * Add sums if wanted
39707993756SAndreas Gohr     */
398986ab7e6SAndreas Gohr    protected function renderSums() {
399d18090e8SAndreas Gohr        if(empty($this->data['summarize'])) return;
40007993756SAndreas Gohr
401a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
4028925ba29SAndreas Gohr        if($this->mode == 'xhtml') {
4038925ba29SAndreas Gohr            /** @noinspection PhpMethodParametersCountMismatchInspection */
4048925ba29SAndreas Gohr            $this->renderer->tablerow_open('summarize');
4058925ba29SAndreas Gohr        } else {
40607993756SAndreas Gohr            $this->renderer->tablerow_open();
4078925ba29SAndreas Gohr        }
40807993756SAndreas Gohr
40907993756SAndreas Gohr        if($this->data['rownumbers']) {
4108925ba29SAndreas Gohr            $this->renderer->tableheader_open();
4118925ba29SAndreas Gohr            $this->renderer->tableheader_close();
41207993756SAndreas Gohr        }
41307993756SAndreas Gohr
414aee4116bSAndreas Gohr        $len = count($this->columns);
41507993756SAndreas Gohr        for($i = 0; $i < $len; $i++) {
4168925ba29SAndreas Gohr            $this->renderer->tableheader_open(1, $this->data['align'][$i]);
417aee4116bSAndreas Gohr            if(!empty($this->sums[$i])) {
4189b97e610SAndreas Gohr                $this->renderer->cdata('∑ ');
4199b97e610SAndreas Gohr                $this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode);
42007993756SAndreas Gohr            } else {
42107993756SAndreas Gohr                if($this->mode == 'xhtml') {
42207993756SAndreas Gohr                    $this->renderer->doc .= '&nbsp;';
42307993756SAndreas Gohr                }
42407993756SAndreas Gohr            }
4258925ba29SAndreas Gohr            $this->renderer->tableheader_close();
42607993756SAndreas Gohr        }
42707993756SAndreas Gohr        $this->renderer->tablerow_close();
428a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = false;
42907993756SAndreas Gohr    }
43007993756SAndreas Gohr
43107993756SAndreas Gohr    /**
432986ab7e6SAndreas Gohr     * Adds paging controls to the table
43307993756SAndreas Gohr     */
434986ab7e6SAndreas Gohr    protected function renderPagingControls() {
43507993756SAndreas Gohr        if(empty($this->data['limit'])) return;
436a0bf8bb2SAndreas Gohr        if($this->mode != 'xhtml') return;
43707993756SAndreas Gohr
438a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
43907993756SAndreas Gohr        $this->renderer->tablerow_open();
4404bc1074dSMichael Grosse        $this->renderer->tableheader_open((count($this->columns) + ($this->data['rownumbers'] ? 1 : 0)));
44107993756SAndreas Gohr        $offset = $this->data['offset'];
44207993756SAndreas Gohr
44307993756SAndreas Gohr        // prev link
44407993756SAndreas Gohr        if($offset) {
44507993756SAndreas Gohr            $prev = $offset - $this->data['limit'];
44607993756SAndreas Gohr            if($prev < 0) {
44707993756SAndreas Gohr                $prev = 0;
44807993756SAndreas Gohr            }
44907993756SAndreas Gohr
45007993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
45107993756SAndreas Gohr            $dynamic->setOffset($prev);
45207993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
45307993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="prev">' . $this->helper->getLang('prev') . '</a>';
45407993756SAndreas Gohr        }
45507993756SAndreas Gohr
45607993756SAndreas Gohr        // next link
45707993756SAndreas Gohr        if($this->resultCount > $offset + $this->data['limit']) {
45807993756SAndreas Gohr            $next = $offset + $this->data['limit'];
45907993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
46007993756SAndreas Gohr            $dynamic->setOffset($next);
46107993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
46207993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="next">' . $this->helper->getLang('next') . '</a>';
46307993756SAndreas Gohr        }
46407993756SAndreas Gohr
46507993756SAndreas Gohr        $this->renderer->tableheader_close();
46607993756SAndreas Gohr        $this->renderer->tablerow_close();
467a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
46807993756SAndreas Gohr    }
46909dd691aSAndreas Gohr
47009dd691aSAndreas Gohr    /**
47109dd691aSAndreas Gohr     * Adds CSV export controls
47209dd691aSAndreas Gohr     */
47309dd691aSAndreas Gohr    protected function renderExportControls() {
47409dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
4757b240ca8SAndreas Gohr        if(empty($this->data['csv'])) return;
47609dd691aSAndreas Gohr        if(!$this->resultCount) return;
47709dd691aSAndreas Gohr
478c8ccdaf8SAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
479c8ccdaf8SAndreas Gohr        $params = $dynamic->getURLParameters();
480c8ccdaf8SAndreas Gohr        $params['hash'] = $this->renderer->info['struct_table_hash'];
481c8ccdaf8SAndreas Gohr
48209dd691aSAndreas Gohr        // FIXME apply dynamic filters
483eafc109fSAndreas Gohr        $link = exportlink($this->id, 'struct_csv', $params);
48409dd691aSAndreas Gohr
48509dd691aSAndreas Gohr        $this->renderer->doc .= '<a href="' . $link . '" class="export mediafile mf_csv">'.$this->helper->getLang('csvexport').'</a>';
48609dd691aSAndreas Gohr    }
48707993756SAndreas Gohr}
488