xref: /plugin/struct/meta/AggregationTable.php (revision 6fd73b4b83ccd266ba6ba303d7f35b3febcdb6d1)
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;
480ceefd5cSAnna Dabrowska    protected $resultRids;
49*6fd73b4bSAnna Dabrowska    protected $resultRevs;
50d4b5a17cSAndreas Gohr
51d4b5a17cSAndreas Gohr    /**
5207993756SAndreas Gohr     * @var array for summing up columns
5307993756SAndreas Gohr     */
5407993756SAndreas Gohr    protected $sums;
5507993756SAndreas Gohr
5607993756SAndreas Gohr    /**
576b5e52fdSAndreas Gohr     * @var bool skip full table when no results found
586b5e52fdSAndreas Gohr     */
596b5e52fdSAndreas Gohr    protected $simplenone = true;
606b5e52fdSAndreas Gohr
616b5e52fdSAndreas Gohr    /**
6207993756SAndreas Gohr     * @todo we might be able to get rid of this helper and move this to SearchConfig
6307993756SAndreas Gohr     * @var \helper_plugin_struct_config
6407993756SAndreas Gohr     */
6507993756SAndreas Gohr    protected $helper;
6607993756SAndreas Gohr
6707993756SAndreas Gohr    /**
6807993756SAndreas Gohr     * Initialize the Aggregation renderer and executes the search
6907993756SAndreas Gohr     *
7007993756SAndreas Gohr     * You need to call @see render() on the resulting object.
7107993756SAndreas Gohr     *
7207993756SAndreas Gohr     * @param string $id
7307993756SAndreas Gohr     * @param string $mode
7407993756SAndreas Gohr     * @param \Doku_Renderer $renderer
7507993756SAndreas Gohr     * @param SearchConfig $searchConfig
7607993756SAndreas Gohr     */
7707993756SAndreas Gohr    public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) {
7807993756SAndreas Gohr        $this->id = $id;
7907993756SAndreas Gohr        $this->mode = $mode;
8007993756SAndreas Gohr        $this->renderer = $renderer;
8107993756SAndreas Gohr        $this->searchConfig = $searchConfig;
8207993756SAndreas Gohr        $this->data = $searchConfig->getConf();
8307993756SAndreas Gohr        $this->columns = $searchConfig->getColumns();
8407993756SAndreas Gohr
8507993756SAndreas Gohr        $this->result = $this->searchConfig->execute();
8607993756SAndreas Gohr        $this->resultCount = $this->searchConfig->getCount();
87d4b5a17cSAndreas Gohr        $this->resultPIDs = $this->searchConfig->getPids();
880ceefd5cSAnna Dabrowska        $this->resultRids = $this->searchConfig->getRids();
89*6fd73b4bSAnna Dabrowska        $this->resultRevs = $this->searchConfig->getRevs();
9007993756SAndreas Gohr        $this->helper = plugin_load('helper', 'struct_config');
9107993756SAndreas Gohr    }
9207993756SAndreas Gohr
9307993756SAndreas Gohr    /**
9407993756SAndreas Gohr     * Create the table on the renderer
9507993756SAndreas Gohr     */
9607993756SAndreas Gohr    public function render() {
97b7e1d73bSAndreas Gohr
98b7e1d73bSAndreas Gohr        // abort early if there are no results at all (not filtered)
996b5e52fdSAndreas Gohr        if(!$this->resultCount && !$this->isDynamicallyFiltered() && $this->simplenone) {
100b7e1d73bSAndreas Gohr            $this->startScope();
101b7e1d73bSAndreas Gohr            $this->renderer->cdata($this->helper->getLang('none'));
102b7e1d73bSAndreas Gohr            $this->finishScope();
103b7e1d73bSAndreas Gohr            return;
104b7e1d73bSAndreas Gohr        }
105b7e1d73bSAndreas Gohr
10607993756SAndreas Gohr        // table open
10707993756SAndreas Gohr        $this->startScope();
108986ab7e6SAndreas Gohr        $this->renderActiveFilters();
10907993756SAndreas Gohr        $this->renderer->table_open();
11007993756SAndreas Gohr
11107993756SAndreas Gohr        // header
11207993756SAndreas Gohr        $this->renderer->tablethead_open();
113986ab7e6SAndreas Gohr        $this->renderColumnHeaders();
114986ab7e6SAndreas Gohr        $this->renderDynamicFilters();
11507993756SAndreas Gohr        $this->renderer->tablethead_close();
11607993756SAndreas Gohr
11707993756SAndreas Gohr        if($this->resultCount) {
11807993756SAndreas Gohr            // actual data
119a9fd81f9SAndreas Gohr            $this->renderer->tabletbody_open();
120986ab7e6SAndreas Gohr            $this->renderResult();
121a9fd81f9SAndreas Gohr            $this->renderer->tabletbody_close();
12207993756SAndreas Gohr
123a9fd81f9SAndreas Gohr            // footer (tfoot is develonly currently)
124a9fd81f9SAndreas Gohr            if(method_exists($this->renderer, 'tabletfoot_open')) $this->renderer->tabletfoot_open();
125986ab7e6SAndreas Gohr            $this->renderSums();
126986ab7e6SAndreas Gohr            $this->renderPagingControls();
127a9fd81f9SAndreas Gohr            if(method_exists($this->renderer, 'tabletfoot_close')) $this->renderer->tabletfoot_close();
12807993756SAndreas Gohr        } else {
12907993756SAndreas Gohr            // nothing found
130986ab7e6SAndreas Gohr            $this->renderEmptyResult();
13107993756SAndreas Gohr        }
13207993756SAndreas Gohr
13307993756SAndreas Gohr        // table close
13407993756SAndreas Gohr        $this->renderer->table_close();
13509dd691aSAndreas Gohr
13609dd691aSAndreas Gohr        // export handle
13709dd691aSAndreas Gohr        $this->renderExportControls();
13807993756SAndreas Gohr        $this->finishScope();
13907993756SAndreas Gohr    }
14007993756SAndreas Gohr
14107993756SAndreas Gohr    /**
14207993756SAndreas Gohr     * Adds additional info to document and renderer in XHTML mode
14307993756SAndreas Gohr     *
14407993756SAndreas Gohr     * @see finishScope()
14507993756SAndreas Gohr     */
14607993756SAndreas Gohr    protected function startScope() {
14707993756SAndreas Gohr        // unique identifier for this aggregation
14807993756SAndreas Gohr        $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true));
14909dd691aSAndreas Gohr
15009dd691aSAndreas Gohr        // wrapping div
15109dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
15209dd691aSAndreas Gohr        $this->renderer->doc .= "<div class=\"structaggregation\">";
15307993756SAndreas Gohr    }
15407993756SAndreas Gohr
15507993756SAndreas Gohr    /**
15607993756SAndreas Gohr     * Closes the table and anything opened in startScope()
15707993756SAndreas Gohr     *
15807993756SAndreas Gohr     * @see startScope()
15907993756SAndreas Gohr     */
16007993756SAndreas Gohr    protected function finishScope() {
16107993756SAndreas Gohr        // remove identifier from renderer again
16207993756SAndreas Gohr        if(isset($this->renderer->info['struct_table_hash'])) {
16307993756SAndreas Gohr            unset($this->renderer->info['struct_table_hash']);
16407993756SAndreas Gohr        }
16509dd691aSAndreas Gohr
16609dd691aSAndreas Gohr        // wrapping div
16709dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
16809dd691aSAndreas Gohr        $this->renderer->doc .= '</div>';
16907993756SAndreas Gohr    }
17007993756SAndreas Gohr
17107993756SAndreas Gohr    /**
17207993756SAndreas Gohr     * Displays info about the currently applied filters
17307993756SAndreas Gohr     */
174986ab7e6SAndreas Gohr    protected function renderActiveFilters() {
17507993756SAndreas Gohr        if($this->mode != 'xhtml') return;
17607993756SAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
17707993756SAndreas Gohr        $filters = $dynamic->getFilters();
17807993756SAndreas Gohr        if(!$filters) return;
17907993756SAndreas Gohr
18007993756SAndreas Gohr        $fltrs = array();
18107993756SAndreas Gohr        foreach($filters as $column => $filter) {
18207993756SAndreas Gohr            list($comp, $value) = $filter;
18304ec4785SAnna Dabrowska
18404ec4785SAnna Dabrowska            // display the filters in a human readable format
18504ec4785SAnna Dabrowska            foreach ($this->columns as $col) {
18604ec4785SAnna Dabrowska                if ($column === $col->getFullQualifiedLabel()) {
18704ec4785SAnna Dabrowska                    $column = $col->getTranslatedLabel();
18804ec4785SAnna Dabrowska                }
18904ec4785SAnna Dabrowska            }
1901f075418SAnna Dabrowska            $fltrs[] = sprintf('"%s" %s "%s"', $column, $this->helper->getLang("comparator $comp"), $value);
19107993756SAndreas Gohr        }
19207993756SAndreas Gohr
19307993756SAndreas Gohr        $this->renderer->doc .= '<div class="filter">';
19407993756SAndreas Gohr        $this->renderer->doc .= '<h4>' . sprintf($this->helper->getLang('tablefilteredby'), hsc(implode(' & ', $fltrs))) . '</h4>';
19507993756SAndreas Gohr        $this->renderer->doc .= '<div class="resetfilter">';
19607993756SAndreas Gohr        $this->renderer->internallink($this->id, $this->helper->getLang('tableresetfilter'));
19707993756SAndreas Gohr        $this->renderer->doc .= '</div>';
19807993756SAndreas Gohr        $this->renderer->doc .= '</div>';
19907993756SAndreas Gohr    }
20007993756SAndreas Gohr
20107993756SAndreas Gohr    /**
20207993756SAndreas Gohr     * Shows the column headers with links to sort by column
20307993756SAndreas Gohr     */
204986ab7e6SAndreas Gohr    protected function renderColumnHeaders() {
20507993756SAndreas Gohr        $this->renderer->tablerow_open();
20607993756SAndreas Gohr
20707993756SAndreas Gohr        // additional column for row numbers
20807993756SAndreas Gohr        if($this->data['rownumbers']) {
20907993756SAndreas Gohr            $this->renderer->tableheader_open();
21007993756SAndreas Gohr            $this->renderer->cdata('#');
21107993756SAndreas Gohr            $this->renderer->tableheader_close();
21207993756SAndreas Gohr        }
21307993756SAndreas Gohr
21407993756SAndreas Gohr        // show all headers
2158c4ee9beSAndreas Gohr        foreach($this->columns as $num => $column) {
2168c4ee9beSAndreas Gohr            $header = '';
2178c4ee9beSAndreas Gohr            if(isset($this->data['headers'][$num])) {
2188c4ee9beSAndreas Gohr                $header = $this->data['headers'][$num];
2198c4ee9beSAndreas Gohr            }
22007993756SAndreas Gohr
22107993756SAndreas Gohr            // use field label if no header was set
22207993756SAndreas Gohr            if(blank($header)) {
22301f8b845SAndreas Gohr                if(is_a($column, 'dokuwiki\plugin\struct\meta\Column')) {
22407993756SAndreas Gohr                    $header = $column->getTranslatedLabel();
22507993756SAndreas Gohr                } else {
22607993756SAndreas Gohr                    $header = 'column ' . $num; // this should never happen
22707993756SAndreas Gohr                }
22807993756SAndreas Gohr            }
22907993756SAndreas Gohr
23007993756SAndreas Gohr            // simple mode first
23107993756SAndreas Gohr            if($this->mode != 'xhtml') {
23207993756SAndreas Gohr                $this->renderer->tableheader_open();
23307993756SAndreas Gohr                $this->renderer->cdata($header);
23407993756SAndreas Gohr                $this->renderer->tableheader_close();
23507993756SAndreas Gohr                continue;
23607993756SAndreas Gohr            }
23707993756SAndreas Gohr
23807993756SAndreas Gohr            // still here? create custom header for more flexibility
23907993756SAndreas Gohr
2409113d04aSAndreas Gohr            // width setting, widths are prevalidated, no escape needed
24107993756SAndreas Gohr            $width = '';
2429113d04aSAndreas Gohr            if(isset($this->data['widths'][$num]) && $this->data['widths'][$num] != '-') {
2439113d04aSAndreas Gohr                $width = ' style="min-width: ' . $this->data['widths'][$num] . ';'.
2449113d04aSAndreas Gohr                         'max-width: ' . $this->data['widths'][$num] . ';"';
24507993756SAndreas Gohr            }
24607993756SAndreas Gohr
247d4b5a17cSAndreas Gohr            // prepare data attribute for inline edits
248d4b5a17cSAndreas Gohr            if(!is_a($column, '\dokuwiki\plugin\struct\meta\PageColumn') &&
249d4b5a17cSAndreas Gohr                !is_a($column, '\dokuwiki\plugin\struct\meta\RevisionColumn')
250d4b5a17cSAndreas Gohr            ) {
251d4b5a17cSAndreas Gohr                $data = 'data-field="' . hsc($column->getFullQualifiedLabel()) . '"';
252d4b5a17cSAndreas Gohr            } else {
253d4b5a17cSAndreas Gohr                $data = '';
254d4b5a17cSAndreas Gohr            }
255d4b5a17cSAndreas Gohr
25607993756SAndreas Gohr            // sort indicator and link
25707993756SAndreas Gohr            $sortclass = '';
25807993756SAndreas Gohr            $sorts = $this->searchConfig->getSorts();
25907993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
260aa124708SAndreas Gohr            $dynamic->setSort($column, true);
26107993756SAndreas Gohr            if(isset($sorts[$column->getFullQualifiedLabel()])) {
262aa124708SAndreas Gohr                list(/*colname*/, $currentSort) = $sorts[$column->getFullQualifiedLabel()];
263aa124708SAndreas Gohr                if($currentSort) {
26407993756SAndreas Gohr                    $sortclass = 'sort-down';
26507993756SAndreas Gohr                    $dynamic->setSort($column, false);
26607993756SAndreas Gohr                } else {
26707993756SAndreas Gohr                    $sortclass = 'sort-up';
26807993756SAndreas Gohr                }
26907993756SAndreas Gohr            }
27007993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
27107993756SAndreas Gohr
27207993756SAndreas Gohr            // output XHTML header
273d4b5a17cSAndreas Gohr            $this->renderer->doc .= "<th $width $data>";
27407993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="' . $sortclass . '" title="' . $this->helper->getLang('sort') . '">' . hsc($header) . '</a>';
27507993756SAndreas Gohr            $this->renderer->doc .= '</th>';
27607993756SAndreas Gohr        }
27707993756SAndreas Gohr
27807993756SAndreas Gohr        $this->renderer->tablerow_close();
27907993756SAndreas Gohr    }
28007993756SAndreas Gohr
28107993756SAndreas Gohr    /**
282b7e1d73bSAndreas Gohr     * Is the result set currently dynamically filtered?
283b7e1d73bSAndreas Gohr     * @return bool
284b7e1d73bSAndreas Gohr     */
285b7e1d73bSAndreas Gohr    protected function isDynamicallyFiltered() {
286b7e1d73bSAndreas Gohr        if($this->mode != 'xhtml') return false;
287b7e1d73bSAndreas Gohr        if(!$this->data['dynfilters']) return false;
288b7e1d73bSAndreas Gohr
289b7e1d73bSAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
290b7e1d73bSAndreas Gohr        return (bool) $dynamic->getFilters();
291b7e1d73bSAndreas Gohr    }
292b7e1d73bSAndreas Gohr
293b7e1d73bSAndreas Gohr    /**
29407993756SAndreas Gohr     * Add input fields for dynamic filtering
29507993756SAndreas Gohr     */
296986ab7e6SAndreas Gohr    protected function renderDynamicFilters() {
29707993756SAndreas Gohr        if($this->mode != 'xhtml') return;
29807993756SAndreas Gohr        if(!$this->data['dynfilters']) return;
2991bc467a4SMichael Grosse        if (is_a($this->renderer, 'renderer_plugin_dw2pdf')) {
300e6ae02ecSMichael Grosse            return;
301e6ae02ecSMichael Grosse        }
3021bc467a4SMichael Grosse        global $conf;
30307993756SAndreas Gohr
30407993756SAndreas Gohr        $this->renderer->doc .= '<tr class="dataflt">';
30507993756SAndreas Gohr
30607993756SAndreas Gohr        // add extra column for row numbers
30707993756SAndreas Gohr        if($this->data['rownumbers']) {
30807993756SAndreas Gohr            $this->renderer->doc .= '<th></th>';
30907993756SAndreas Gohr        }
31007993756SAndreas Gohr
31107993756SAndreas Gohr        // each column gets a form
31207993756SAndreas Gohr        foreach($this->columns as $column) {
31307993756SAndreas Gohr            $this->renderer->doc .= '<th>';
31407993756SAndreas Gohr            {
31507993756SAndreas Gohr                $form = new \Doku_Form(array('method' => 'GET', 'action' => wl($this->id)));
31676195677SAndreas Gohr                unset($form->_hidden['sectok']); // we don't need it here
31776195677SAndreas Gohr                if(!$conf['userewrite']) $form->addHidden('id', $this->id);
31807993756SAndreas Gohr
31907993756SAndreas Gohr                // current value
32007993756SAndreas Gohr                $dynamic = $this->searchConfig->getDynamicParameters();
32107993756SAndreas Gohr                $filters = $dynamic->getFilters();
32207993756SAndreas Gohr                if(isset($filters[$column->getFullQualifiedLabel()])) {
32307993756SAndreas Gohr                    list(, $current) = $filters[$column->getFullQualifiedLabel()];
32407993756SAndreas Gohr                    $dynamic->removeFilter($column);
32507993756SAndreas Gohr                } else {
32607993756SAndreas Gohr                    $current = '';
32707993756SAndreas Gohr                }
32807993756SAndreas Gohr
32907993756SAndreas Gohr                // Add current request params
33007993756SAndreas Gohr                $params = $dynamic->getURLParameters();
33107993756SAndreas Gohr                foreach($params as $key => $val) {
33207993756SAndreas Gohr                    $form->addHidden($key, $val);
33307993756SAndreas Gohr                }
33407993756SAndreas Gohr
33507993756SAndreas Gohr                // add input field
336db9b8745SAndreas Gohr                $key = $column->getFullQualifiedLabel() . $column->getType()->getDefaultComparator();
337d60f71efSAndreas Gohr                $form->addElement(form_makeField('text', SearchConfigParameters::$PARAM_FILTER . '[' . $key . ']', $current, ''));
33807993756SAndreas Gohr                $this->renderer->doc .= $form->getForm();
33907993756SAndreas Gohr            }
34007993756SAndreas Gohr            $this->renderer->doc .= '</th>';
34107993756SAndreas Gohr        }
34207993756SAndreas Gohr        $this->renderer->doc .= '</tr>';
34307993756SAndreas Gohr
34407993756SAndreas Gohr    }
34507993756SAndreas Gohr
34607993756SAndreas Gohr    /**
34707993756SAndreas Gohr     * Display the actual table data
34807993756SAndreas Gohr     */
349986ab7e6SAndreas Gohr    protected function renderResult() {
35007993756SAndreas Gohr        foreach($this->result as $rownum => $row) {
351f107f479SAndreas Gohr            $this->renderResultRow($rownum, $row);
352f107f479SAndreas Gohr        }
353f107f479SAndreas Gohr    }
354f107f479SAndreas Gohr
355f107f479SAndreas Gohr    /**
356f107f479SAndreas Gohr     * Render a single result row
357f107f479SAndreas Gohr     *
358f107f479SAndreas Gohr     * @param int $rownum
359f107f479SAndreas Gohr     * @param array $row
360f107f479SAndreas Gohr     */
361f107f479SAndreas Gohr    protected function renderResultRow($rownum, $row) {
36207993756SAndreas Gohr        $this->renderer->tablerow_open();
36307993756SAndreas Gohr
364d4b5a17cSAndreas Gohr        // add data attribute for inline edit
365d4b5a17cSAndreas Gohr        if($this->mode == 'xhtml') {
366d4b5a17cSAndreas Gohr            $pid = $this->resultPIDs[$rownum];
3670ceefd5cSAnna Dabrowska            $rid = $this->resultRids[$rownum];
368*6fd73b4bSAnna Dabrowska            $rev = $this->resultRevs[$rownum];
369d4b5a17cSAndreas Gohr            $this->renderer->doc = substr(rtrim($this->renderer->doc), 0, -1); // remove closing '>'
370*6fd73b4bSAnna Dabrowska            $this->renderer->doc .= ' data-pid="' . hsc($pid) . '" data-rev="' . $rev . '" data-rid="' . $rid . '">';
371d4b5a17cSAndreas Gohr        }
372d4b5a17cSAndreas Gohr
37307993756SAndreas Gohr        // row number column
37407993756SAndreas Gohr        if($this->data['rownumbers']) {
37507993756SAndreas Gohr            $this->renderer->tablecell_open();
3763215aebfSSzymon Olewniczak            $searchConfigConf = $this->searchConfig->getConf();
3773215aebfSSzymon Olewniczak            $this->renderer->cdata($rownum + $searchConfigConf['offset'] + 1);
37807993756SAndreas Gohr            $this->renderer->tablecell_close();
37907993756SAndreas Gohr        }
38007993756SAndreas Gohr
38107993756SAndreas Gohr        /** @var Value $value */
38207993756SAndreas Gohr        foreach($row as $colnum => $value) {
38395eef580SAndreas Gohr            $this->renderer->tablecell_open(1, $this->data['align'][$colnum]);
38407993756SAndreas Gohr            $value->render($this->renderer, $this->mode);
38507993756SAndreas Gohr            $this->renderer->tablecell_close();
38607993756SAndreas Gohr
38707993756SAndreas Gohr            // summarize
38807993756SAndreas Gohr            if($this->data['summarize'] && is_numeric($value->getValue())) {
38907993756SAndreas Gohr                if(!isset($this->sums[$colnum])) {
39007993756SAndreas Gohr                    $this->sums[$colnum] = 0;
39107993756SAndreas Gohr                }
39207993756SAndreas Gohr                $this->sums[$colnum] += $value->getValue();
39307993756SAndreas Gohr            }
39407993756SAndreas Gohr        }
39507993756SAndreas Gohr        $this->renderer->tablerow_close();
39607993756SAndreas Gohr    }
39707993756SAndreas Gohr
39807993756SAndreas Gohr    /**
39907993756SAndreas Gohr     * Renders an information row for when no results were found
40007993756SAndreas Gohr     */
401986ab7e6SAndreas Gohr    protected function renderEmptyResult() {
40207993756SAndreas Gohr        $this->renderer->tablerow_open();
40370cf6339SAndreas Gohr        $this->renderer->tablecell_open(count($this->columns) + $this->data['rownumbers'], 'center');
40407993756SAndreas Gohr        $this->renderer->cdata($this->helper->getLang('none'));
40507993756SAndreas Gohr        $this->renderer->tablecell_close();
40607993756SAndreas Gohr        $this->renderer->tablerow_close();
40707993756SAndreas Gohr    }
40807993756SAndreas Gohr
40907993756SAndreas Gohr    /**
41007993756SAndreas Gohr     * Add sums if wanted
41107993756SAndreas Gohr     */
412986ab7e6SAndreas Gohr    protected function renderSums() {
413d18090e8SAndreas Gohr        if(empty($this->data['summarize'])) return;
41407993756SAndreas Gohr
415a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
4168925ba29SAndreas Gohr        if($this->mode == 'xhtml') {
4178925ba29SAndreas Gohr            /** @noinspection PhpMethodParametersCountMismatchInspection */
4188925ba29SAndreas Gohr            $this->renderer->tablerow_open('summarize');
4198925ba29SAndreas Gohr        } else {
42007993756SAndreas Gohr            $this->renderer->tablerow_open();
4218925ba29SAndreas Gohr        }
42207993756SAndreas Gohr
42307993756SAndreas Gohr        if($this->data['rownumbers']) {
4248925ba29SAndreas Gohr            $this->renderer->tableheader_open();
4258925ba29SAndreas Gohr            $this->renderer->tableheader_close();
42607993756SAndreas Gohr        }
42707993756SAndreas Gohr
428aee4116bSAndreas Gohr        $len = count($this->columns);
42907993756SAndreas Gohr        for($i = 0; $i < $len; $i++) {
4308925ba29SAndreas Gohr            $this->renderer->tableheader_open(1, $this->data['align'][$i]);
431aee4116bSAndreas Gohr            if(!empty($this->sums[$i])) {
4329b97e610SAndreas Gohr                $this->renderer->cdata('∑ ');
4339b97e610SAndreas Gohr                $this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode);
43407993756SAndreas Gohr            } else {
43507993756SAndreas Gohr                if($this->mode == 'xhtml') {
43607993756SAndreas Gohr                    $this->renderer->doc .= '&nbsp;';
43707993756SAndreas Gohr                }
43807993756SAndreas Gohr            }
4398925ba29SAndreas Gohr            $this->renderer->tableheader_close();
44007993756SAndreas Gohr        }
44107993756SAndreas Gohr        $this->renderer->tablerow_close();
442a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = false;
44307993756SAndreas Gohr    }
44407993756SAndreas Gohr
44507993756SAndreas Gohr    /**
446986ab7e6SAndreas Gohr     * Adds paging controls to the table
44707993756SAndreas Gohr     */
448986ab7e6SAndreas Gohr    protected function renderPagingControls() {
44907993756SAndreas Gohr        if(empty($this->data['limit'])) return;
450a0bf8bb2SAndreas Gohr        if($this->mode != 'xhtml') return;
45107993756SAndreas Gohr
452a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
45307993756SAndreas Gohr        $this->renderer->tablerow_open();
4544bc1074dSMichael Grosse        $this->renderer->tableheader_open((count($this->columns) + ($this->data['rownumbers'] ? 1 : 0)));
45507993756SAndreas Gohr        $offset = $this->data['offset'];
45607993756SAndreas Gohr
45707993756SAndreas Gohr        // prev link
45807993756SAndreas Gohr        if($offset) {
45907993756SAndreas Gohr            $prev = $offset - $this->data['limit'];
46007993756SAndreas Gohr            if($prev < 0) {
46107993756SAndreas Gohr                $prev = 0;
46207993756SAndreas Gohr            }
46307993756SAndreas Gohr
46407993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
46507993756SAndreas Gohr            $dynamic->setOffset($prev);
46607993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
46707993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="prev">' . $this->helper->getLang('prev') . '</a>';
46807993756SAndreas Gohr        }
46907993756SAndreas Gohr
47007993756SAndreas Gohr        // next link
47107993756SAndreas Gohr        if($this->resultCount > $offset + $this->data['limit']) {
47207993756SAndreas Gohr            $next = $offset + $this->data['limit'];
47307993756SAndreas Gohr            $dynamic = $this->searchConfig->getDynamicParameters();
47407993756SAndreas Gohr            $dynamic->setOffset($next);
47507993756SAndreas Gohr            $link = wl($this->id, $dynamic->getURLParameters());
47607993756SAndreas Gohr            $this->renderer->doc .= '<a href="' . $link . '" class="next">' . $this->helper->getLang('next') . '</a>';
47707993756SAndreas Gohr        }
47807993756SAndreas Gohr
47907993756SAndreas Gohr        $this->renderer->tableheader_close();
48007993756SAndreas Gohr        $this->renderer->tablerow_close();
481a0bf8bb2SAndreas Gohr        $this->renderer->info['struct_table_meta'] = true;
48207993756SAndreas Gohr    }
48309dd691aSAndreas Gohr
48409dd691aSAndreas Gohr    /**
48509dd691aSAndreas Gohr     * Adds CSV export controls
48609dd691aSAndreas Gohr     */
48709dd691aSAndreas Gohr    protected function renderExportControls() {
48809dd691aSAndreas Gohr        if($this->mode != 'xhtml') return;
4897b240ca8SAndreas Gohr        if(empty($this->data['csv'])) return;
49009dd691aSAndreas Gohr        if(!$this->resultCount) return;
49109dd691aSAndreas Gohr
492c8ccdaf8SAndreas Gohr        $dynamic = $this->searchConfig->getDynamicParameters();
493c8ccdaf8SAndreas Gohr        $params = $dynamic->getURLParameters();
494c8ccdaf8SAndreas Gohr        $params['hash'] = $this->renderer->info['struct_table_hash'];
495c8ccdaf8SAndreas Gohr
49609dd691aSAndreas Gohr        // FIXME apply dynamic filters
497eafc109fSAndreas Gohr        $link = exportlink($this->id, 'struct_csv', $params);
49809dd691aSAndreas Gohr
49909dd691aSAndreas Gohr        $this->renderer->doc .= '<a href="' . $link . '" class="export mediafile mf_csv">'.$this->helper->getLang('csvexport').'</a>';
50009dd691aSAndreas Gohr    }
50107993756SAndreas Gohr}
502