107993756SAndreas Gohr<?php 207993756SAndreas Gohr 3ba766201SAndreas Gohrnamespace dokuwiki\plugin\struct\meta; 407993756SAndreas Gohr 57234bfb1Ssplitbrainuse dokuwiki\Extension\Event; 67234bfb1Ssplitbrain 7d60f71efSAndreas Gohr/** 8d60f71efSAndreas Gohr * Creates the table aggregation output 9d60f71efSAndreas Gohr * 10ba766201SAndreas Gohr * @package dokuwiki\plugin\struct\meta 11d60f71efSAndreas Gohr */ 12d90aa848SAndreas Gohrclass AggregationTable extends Aggregation 13d6d97f60SAnna Dabrowska{ 14d90aa848SAndreas Gohr /** @var array for summing up columns */ 15d90aa848SAndreas Gohr protected $sums; 1607993756SAndreas Gohr 17d90aa848SAndreas Gohr /** @var string[] the result PIDs for each row */ 18d4b5a17cSAndreas Gohr protected $resultPIDs; 190ceefd5cSAnna Dabrowska protected $resultRids; 206fd73b4bSAnna Dabrowska protected $resultRevs; 21d4b5a17cSAndreas Gohr 228ce43f5aSAnna Dabrowska public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 23d6d97f60SAnna Dabrowska { 24d90aa848SAndreas Gohr parent::__construct($id, $mode, $renderer, $searchConfig); 25d4b5a17cSAndreas Gohr $this->resultPIDs = $this->searchConfig->getPids(); 260ceefd5cSAnna Dabrowska $this->resultRids = $this->searchConfig->getRids(); 276fd73b4bSAnna Dabrowska $this->resultRevs = $this->searchConfig->getRevs(); 2807993756SAndreas Gohr } 2907993756SAndreas Gohr 30d90aa848SAndreas Gohr /** @inheritdoc */ 31d90aa848SAndreas Gohr public function render($showNotFound = false) 32d6d97f60SAnna Dabrowska { 33b7e1d73bSAndreas Gohr 34b7e1d73bSAndreas Gohr // abort early if there are no results at all (not filtered) 35d90aa848SAndreas Gohr if (!$this->resultCount && !$this->isDynamicallyFiltered() && $showNotFound) { 36b7e1d73bSAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 37b7e1d73bSAndreas Gohr return; 38b7e1d73bSAndreas Gohr } 39b7e1d73bSAndreas Gohr 40986ab7e6SAndreas Gohr $this->renderActiveFilters(); 41844a4f01SFrieder Schrempf 42*7fe2cdf2SAndreas Gohr $rendercontext = [ 43*7fe2cdf2SAndreas Gohr 'table' => $this, 44*7fe2cdf2SAndreas Gohr 'renderer' => $this->renderer, 45*7fe2cdf2SAndreas Gohr 'format' => $this->mode, 46*7fe2cdf2SAndreas Gohr 'search' => $this->searchConfig, 47*7fe2cdf2SAndreas Gohr 'columns' => $this->columns, 48*7fe2cdf2SAndreas Gohr 'data' => $this->result 49*7fe2cdf2SAndreas Gohr ]; 50844a4f01SFrieder Schrempf 517234bfb1Ssplitbrain $event = new Event( 52844a4f01SFrieder Schrempf 'PLUGIN_STRUCT_RENDER_AGGREGATION_TABLE', 532dbe71f8SAnna Dabrowska $rendercontext 54844a4f01SFrieder Schrempf ); 552dbe71f8SAnna Dabrowska $event->trigger([$this, 'renderTable']); 56844a4f01SFrieder Schrempf 57844a4f01SFrieder Schrempf // export handle 58844a4f01SFrieder Schrempf $this->renderExportControls(); 59844a4f01SFrieder Schrempf } 60844a4f01SFrieder Schrempf 61844a4f01SFrieder Schrempf /** 62844a4f01SFrieder Schrempf * Render the default aggregation table 63844a4f01SFrieder Schrempf */ 64844a4f01SFrieder Schrempf public function renderTable($rendercontext) 65844a4f01SFrieder Schrempf { 6607993756SAndreas Gohr $this->renderer->table_open(); 6707993756SAndreas Gohr 6807993756SAndreas Gohr // header 6907993756SAndreas Gohr $this->renderer->tablethead_open(); 70986ab7e6SAndreas Gohr $this->renderColumnHeaders(); 71986ab7e6SAndreas Gohr $this->renderDynamicFilters(); 7207993756SAndreas Gohr $this->renderer->tablethead_close(); 7307993756SAndreas Gohr 7407993756SAndreas Gohr if ($this->resultCount) { 7507993756SAndreas Gohr // actual data 76a9fd81f9SAndreas Gohr $this->renderer->tabletbody_open(); 77986ab7e6SAndreas Gohr $this->renderResult(); 78a9fd81f9SAndreas Gohr $this->renderer->tabletbody_close(); 7907993756SAndreas Gohr 80a9fd81f9SAndreas Gohr // footer (tfoot is develonly currently) 81a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_open')) $this->renderer->tabletfoot_open(); 82986ab7e6SAndreas Gohr $this->renderSums(); 83986ab7e6SAndreas Gohr $this->renderPagingControls(); 84a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_close')) $this->renderer->tabletfoot_close(); 8507993756SAndreas Gohr } else { 8607993756SAndreas Gohr // nothing found 87986ab7e6SAndreas Gohr $this->renderEmptyResult(); 8807993756SAndreas Gohr } 8907993756SAndreas Gohr 9007993756SAndreas Gohr // table close 9107993756SAndreas Gohr $this->renderer->table_close(); 9207993756SAndreas Gohr } 9307993756SAndreas Gohr 9407993756SAndreas Gohr /** 9507993756SAndreas Gohr * Adds additional info to document and renderer in XHTML mode 9607993756SAndreas Gohr * 9707993756SAndreas Gohr * @see finishScope() 9807993756SAndreas Gohr */ 99af0ce8d2SAndreas Gohr public function startScope() 100d6d97f60SAnna Dabrowska { 10107993756SAndreas Gohr // unique identifier for this aggregation 10207993756SAndreas Gohr $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true)); 10309dd691aSAndreas Gohr 104af0ce8d2SAndreas Gohr parent::startScope(); 10507993756SAndreas Gohr } 10607993756SAndreas Gohr 10707993756SAndreas Gohr /** 10807993756SAndreas Gohr * Closes the table and anything opened in startScope() 10907993756SAndreas Gohr * 11007993756SAndreas Gohr * @see startScope() 11107993756SAndreas Gohr */ 112af0ce8d2SAndreas Gohr public function finishScope() 113d6d97f60SAnna Dabrowska { 11407993756SAndreas Gohr // remove identifier from renderer again 11507993756SAndreas Gohr if (isset($this->renderer->info['struct_table_hash'])) { 11607993756SAndreas Gohr unset($this->renderer->info['struct_table_hash']); 11707993756SAndreas Gohr } 11809dd691aSAndreas Gohr 119af0ce8d2SAndreas Gohr parent::finishScope(); 12007993756SAndreas Gohr } 12107993756SAndreas Gohr 12207993756SAndreas Gohr /** 12307993756SAndreas Gohr * Displays info about the currently applied filters 12407993756SAndreas Gohr */ 125d6d97f60SAnna Dabrowska protected function renderActiveFilters() 126d6d97f60SAnna Dabrowska { 12707993756SAndreas Gohr if ($this->mode != 'xhtml') return; 12807993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 12907993756SAndreas Gohr $filters = $dynamic->getFilters(); 13007993756SAndreas Gohr if (!$filters) return; 13107993756SAndreas Gohr 1327234bfb1Ssplitbrain $fltrs = []; 13307993756SAndreas Gohr foreach ($filters as $column => $filter) { 1347234bfb1Ssplitbrain [$comp, $value] = $filter; 13504ec4785SAnna Dabrowska 13604ec4785SAnna Dabrowska // display the filters in a human readable format 13704ec4785SAnna Dabrowska foreach ($this->columns as $col) { 13804ec4785SAnna Dabrowska if ($column === $col->getFullQualifiedLabel()) { 13904ec4785SAnna Dabrowska $column = $col->getTranslatedLabel(); 14004ec4785SAnna Dabrowska } 14104ec4785SAnna Dabrowska } 1421f075418SAnna Dabrowska $fltrs[] = sprintf('"%s" %s "%s"', $column, $this->helper->getLang("comparator $comp"), $value); 14307993756SAndreas Gohr } 14407993756SAndreas Gohr 14507993756SAndreas Gohr $this->renderer->doc .= '<div class="filter">'; 14617a3a578SAndreas Gohr $this->renderer->doc .= '<h4>' . 14717a3a578SAndreas Gohr sprintf( 14817a3a578SAndreas Gohr $this->helper->getLang('tablefilteredby'), 14917a3a578SAndreas Gohr hsc(implode(' & ', $fltrs)) 15017a3a578SAndreas Gohr ) . 15117a3a578SAndreas Gohr '</h4>'; 15207993756SAndreas Gohr $this->renderer->doc .= '<div class="resetfilter">'; 15307993756SAndreas Gohr $this->renderer->internallink($this->id, $this->helper->getLang('tableresetfilter')); 15407993756SAndreas Gohr $this->renderer->doc .= '</div>'; 15507993756SAndreas Gohr $this->renderer->doc .= '</div>'; 15607993756SAndreas Gohr } 15707993756SAndreas Gohr 15807993756SAndreas Gohr /** 15907993756SAndreas Gohr * Shows the column headers with links to sort by column 16007993756SAndreas Gohr */ 161d6d97f60SAnna Dabrowska protected function renderColumnHeaders() 162d6d97f60SAnna Dabrowska { 16307993756SAndreas Gohr $this->renderer->tablerow_open(); 16407993756SAndreas Gohr 16507993756SAndreas Gohr // additional column for row numbers 16634ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 16707993756SAndreas Gohr $this->renderer->tableheader_open(); 16807993756SAndreas Gohr $this->renderer->cdata('#'); 16907993756SAndreas Gohr $this->renderer->tableheader_close(); 17007993756SAndreas Gohr } 17107993756SAndreas Gohr 17207993756SAndreas Gohr // show all headers 1738c4ee9beSAndreas Gohr foreach ($this->columns as $num => $column) { 1748c4ee9beSAndreas Gohr $header = ''; 1758c4ee9beSAndreas Gohr if (isset($this->data['headers'][$num])) { 1768c4ee9beSAndreas Gohr $header = $this->data['headers'][$num]; 1778c4ee9beSAndreas Gohr } 17807993756SAndreas Gohr 17907993756SAndreas Gohr // use field label if no header was set 18007993756SAndreas Gohr if (blank($header)) { 18101f8b845SAndreas Gohr if (is_a($column, 'dokuwiki\plugin\struct\meta\Column')) { 18207993756SAndreas Gohr $header = $column->getTranslatedLabel(); 18307993756SAndreas Gohr } else { 18407993756SAndreas Gohr $header = 'column ' . $num; // this should never happen 18507993756SAndreas Gohr } 18607993756SAndreas Gohr } 18707993756SAndreas Gohr 18807993756SAndreas Gohr // simple mode first 18907993756SAndreas Gohr if ($this->mode != 'xhtml') { 19007993756SAndreas Gohr $this->renderer->tableheader_open(); 19107993756SAndreas Gohr $this->renderer->cdata($header); 19207993756SAndreas Gohr $this->renderer->tableheader_close(); 19307993756SAndreas Gohr continue; 19407993756SAndreas Gohr } 19507993756SAndreas Gohr 19607993756SAndreas Gohr // still here? create custom header for more flexibility 19707993756SAndreas Gohr 1989113d04aSAndreas Gohr // width setting, widths are prevalidated, no escape needed 19907993756SAndreas Gohr $width = ''; 2009113d04aSAndreas Gohr if (isset($this->data['widths'][$num]) && $this->data['widths'][$num] != '-') { 2019113d04aSAndreas Gohr $width = ' style="min-width: ' . $this->data['widths'][$num] . ';' . 2029113d04aSAndreas Gohr 'max-width: ' . $this->data['widths'][$num] . ';"'; 20307993756SAndreas Gohr } 20407993756SAndreas Gohr 205d4b5a17cSAndreas Gohr // prepare data attribute for inline edits 206d6d97f60SAnna Dabrowska if ( 207d6d97f60SAnna Dabrowska !is_a($column, '\dokuwiki\plugin\struct\meta\PageColumn') && 208d4b5a17cSAndreas Gohr !is_a($column, '\dokuwiki\plugin\struct\meta\RevisionColumn') 209d4b5a17cSAndreas Gohr ) { 210d4b5a17cSAndreas Gohr $data = 'data-field="' . hsc($column->getFullQualifiedLabel()) . '"'; 211d4b5a17cSAndreas Gohr } else { 212d4b5a17cSAndreas Gohr $data = ''; 213d4b5a17cSAndreas Gohr } 214d4b5a17cSAndreas Gohr 21507993756SAndreas Gohr // sort indicator and link 21607993756SAndreas Gohr $sortclass = ''; 21707993756SAndreas Gohr $sorts = $this->searchConfig->getSorts(); 21807993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 219aa124708SAndreas Gohr $dynamic->setSort($column, true); 22007993756SAndreas Gohr if (isset($sorts[$column->getFullQualifiedLabel()])) { 221*7fe2cdf2SAndreas Gohr [/*colname*/, $currentSort] = $sorts[$column->getFullQualifiedLabel()]; 222aa124708SAndreas Gohr if ($currentSort) { 22307993756SAndreas Gohr $sortclass = 'sort-down'; 22407993756SAndreas Gohr $dynamic->setSort($column, false); 22507993756SAndreas Gohr } else { 22607993756SAndreas Gohr $sortclass = 'sort-up'; 22707993756SAndreas Gohr } 22807993756SAndreas Gohr } 22907993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 23007993756SAndreas Gohr 23107993756SAndreas Gohr // output XHTML header 232d4b5a17cSAndreas Gohr $this->renderer->doc .= "<th $width $data>"; 23317a3a578SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="' . $sortclass . '" ' . 23417a3a578SAndreas Gohr 'title="' . $this->helper->getLang('sort') . '">' . hsc($header) . '</a>'; 23507993756SAndreas Gohr $this->renderer->doc .= '</th>'; 23607993756SAndreas Gohr } 23707993756SAndreas Gohr 23807993756SAndreas Gohr $this->renderer->tablerow_close(); 23907993756SAndreas Gohr } 24007993756SAndreas Gohr 24107993756SAndreas Gohr /** 242b7e1d73bSAndreas Gohr * Is the result set currently dynamically filtered? 243b7e1d73bSAndreas Gohr * @return bool 244b7e1d73bSAndreas Gohr */ 245d6d97f60SAnna Dabrowska protected function isDynamicallyFiltered() 246d6d97f60SAnna Dabrowska { 247b7e1d73bSAndreas Gohr if ($this->mode != 'xhtml') return false; 248b7e1d73bSAndreas Gohr if (!$this->data['dynfilters']) return false; 249b7e1d73bSAndreas Gohr 250b7e1d73bSAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 251b7e1d73bSAndreas Gohr return (bool)$dynamic->getFilters(); 252b7e1d73bSAndreas Gohr } 253b7e1d73bSAndreas Gohr 254b7e1d73bSAndreas Gohr /** 25507993756SAndreas Gohr * Add input fields for dynamic filtering 25607993756SAndreas Gohr */ 257d6d97f60SAnna Dabrowska protected function renderDynamicFilters() 258d6d97f60SAnna Dabrowska { 25907993756SAndreas Gohr if ($this->mode != 'xhtml') return; 2601ca21e17SAnna Dabrowska if (empty($this->data['dynfilters'])) return; 2611bc467a4SMichael Grosse if (is_a($this->renderer, 'renderer_plugin_dw2pdf')) { 262e6ae02ecSMichael Grosse return; 263e6ae02ecSMichael Grosse } 2641bc467a4SMichael Grosse global $conf; 26507993756SAndreas Gohr 26607993756SAndreas Gohr $this->renderer->doc .= '<tr class="dataflt">'; 26707993756SAndreas Gohr 26807993756SAndreas Gohr // add extra column for row numbers 26907993756SAndreas Gohr if ($this->data['rownumbers']) { 27007993756SAndreas Gohr $this->renderer->doc .= '<th></th>'; 27107993756SAndreas Gohr } 27207993756SAndreas Gohr 27307993756SAndreas Gohr // each column gets a form 27407993756SAndreas Gohr foreach ($this->columns as $column) { 27507993756SAndreas Gohr $this->renderer->doc .= '<th>'; 27617a3a578SAndreas Gohr 27717a3a578SAndreas Gohr // BEGIN FORM 2787234bfb1Ssplitbrain $form = new \Doku_Form(['method' => 'GET', 'action' => wl($this->id)]); 27976195677SAndreas Gohr unset($form->_hidden['sectok']); // we don't need it here 28076195677SAndreas Gohr if (!$conf['userewrite']) $form->addHidden('id', $this->id); 28107993756SAndreas Gohr 28207993756SAndreas Gohr // current value 28307993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 28407993756SAndreas Gohr $filters = $dynamic->getFilters(); 28507993756SAndreas Gohr if (isset($filters[$column->getFullQualifiedLabel()])) { 2867234bfb1Ssplitbrain [, $current] = $filters[$column->getFullQualifiedLabel()]; 28707993756SAndreas Gohr $dynamic->removeFilter($column); 28807993756SAndreas Gohr } else { 28907993756SAndreas Gohr $current = ''; 29007993756SAndreas Gohr } 29107993756SAndreas Gohr 29207993756SAndreas Gohr // Add current request params 29307993756SAndreas Gohr $params = $dynamic->getURLParameters(); 29407993756SAndreas Gohr foreach ($params as $key => $val) { 29507993756SAndreas Gohr $form->addHidden($key, $val); 29607993756SAndreas Gohr } 29707993756SAndreas Gohr 29807993756SAndreas Gohr // add input field 299db9b8745SAndreas Gohr $key = $column->getFullQualifiedLabel() . $column->getType()->getDefaultComparator(); 30017a3a578SAndreas Gohr $form->addElement( 30117a3a578SAndreas Gohr form_makeField('text', SearchConfigParameters::$PARAM_FILTER . '[' . $key . ']', $current, '') 30217a3a578SAndreas Gohr ); 30307993756SAndreas Gohr $this->renderer->doc .= $form->getForm(); 30417a3a578SAndreas Gohr // END FORM 30517a3a578SAndreas Gohr 30607993756SAndreas Gohr $this->renderer->doc .= '</th>'; 30707993756SAndreas Gohr } 30807993756SAndreas Gohr $this->renderer->doc .= '</tr>'; 30907993756SAndreas Gohr } 31007993756SAndreas Gohr 31107993756SAndreas Gohr /** 31207993756SAndreas Gohr * Display the actual table data 31307993756SAndreas Gohr */ 314d6d97f60SAnna Dabrowska protected function renderResult() 315d6d97f60SAnna Dabrowska { 31607993756SAndreas Gohr foreach ($this->result as $rownum => $row) { 317*7fe2cdf2SAndreas Gohr $data = [ 318*7fe2cdf2SAndreas Gohr 'id' => $this->id, 319*7fe2cdf2SAndreas Gohr 'mode' => $this->mode, 320*7fe2cdf2SAndreas Gohr 'renderer' => $this->renderer, 321*7fe2cdf2SAndreas Gohr 'searchConfig' => $this->searchConfig, 322*7fe2cdf2SAndreas Gohr 'data' => $this->data, 323*7fe2cdf2SAndreas Gohr 'rownum' => &$rownum, 324*7fe2cdf2SAndreas Gohr 'row' => &$row 325*7fe2cdf2SAndreas Gohr ]; 3267234bfb1Ssplitbrain $evt = new Event('PLUGIN_STRUCT_AGGREGATIONTABLE_RENDERRESULTROW', $data); 32747eb8cceSSzymon Olewniczak if ($evt->advise_before()) { 328f107f479SAndreas Gohr $this->renderResultRow($rownum, $row); 329f107f479SAndreas Gohr } 33047eb8cceSSzymon Olewniczak $evt->advise_after(); 33147eb8cceSSzymon Olewniczak } 332f107f479SAndreas Gohr } 333f107f479SAndreas Gohr 334f107f479SAndreas Gohr /** 335f107f479SAndreas Gohr * Render a single result row 336f107f479SAndreas Gohr * 337f107f479SAndreas Gohr * @param int $rownum 338f107f479SAndreas Gohr * @param array $row 339f107f479SAndreas Gohr */ 340d6d97f60SAnna Dabrowska protected function renderResultRow($rownum, $row) 341d6d97f60SAnna Dabrowska { 34207993756SAndreas Gohr $this->renderer->tablerow_open(); 34307993756SAndreas Gohr 344d4b5a17cSAndreas Gohr // add data attribute for inline edit 345d4b5a17cSAndreas Gohr if ($this->mode == 'xhtml') { 346d4b5a17cSAndreas Gohr $pid = $this->resultPIDs[$rownum]; 3470ceefd5cSAnna Dabrowska $rid = $this->resultRids[$rownum]; 3486fd73b4bSAnna Dabrowska $rev = $this->resultRevs[$rownum]; 349d4b5a17cSAndreas Gohr $this->renderer->doc = substr(rtrim($this->renderer->doc), 0, -1); // remove closing '>' 3506fd73b4bSAnna Dabrowska $this->renderer->doc .= ' data-pid="' . hsc($pid) . '" data-rev="' . $rev . '" data-rid="' . $rid . '">'; 351d4b5a17cSAndreas Gohr } 352d4b5a17cSAndreas Gohr 35307993756SAndreas Gohr // row number column 35434ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 35507993756SAndreas Gohr $this->renderer->tablecell_open(); 356fdf37115SAndreas Gohr $this->renderer->cdata($rownum + $this->searchConfig->getOffset() + 1); 35707993756SAndreas Gohr $this->renderer->tablecell_close(); 35807993756SAndreas Gohr } 35907993756SAndreas Gohr 36007993756SAndreas Gohr /** @var Value $value */ 36107993756SAndreas Gohr foreach ($row as $colnum => $value) { 3627234bfb1Ssplitbrain $align = $this->data['align'][$colnum] ?? null; 36334ea6e10SAnna Dabrowska $this->renderer->tablecell_open(1, $align); 36407993756SAndreas Gohr $value->render($this->renderer, $this->mode); 36507993756SAndreas Gohr $this->renderer->tablecell_close(); 36607993756SAndreas Gohr 36707993756SAndreas Gohr // summarize 3681ca21e17SAnna Dabrowska if (!empty($this->data['summarize']) && is_numeric($value->getValue())) { 36907993756SAndreas Gohr if (!isset($this->sums[$colnum])) { 37007993756SAndreas Gohr $this->sums[$colnum] = 0; 37107993756SAndreas Gohr } 37207993756SAndreas Gohr $this->sums[$colnum] += $value->getValue(); 37307993756SAndreas Gohr } 37407993756SAndreas Gohr } 37507993756SAndreas Gohr $this->renderer->tablerow_close(); 37607993756SAndreas Gohr } 37707993756SAndreas Gohr 37807993756SAndreas Gohr /** 37907993756SAndreas Gohr * Renders an information row for when no results were found 38007993756SAndreas Gohr */ 381d6d97f60SAnna Dabrowska protected function renderEmptyResult() 382d6d97f60SAnna Dabrowska { 38307993756SAndreas Gohr $this->renderer->tablerow_open(); 38470cf6339SAndreas Gohr $this->renderer->tablecell_open(count($this->columns) + $this->data['rownumbers'], 'center'); 38507993756SAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 38607993756SAndreas Gohr $this->renderer->tablecell_close(); 38707993756SAndreas Gohr $this->renderer->tablerow_close(); 38807993756SAndreas Gohr } 38907993756SAndreas Gohr 39007993756SAndreas Gohr /** 39107993756SAndreas Gohr * Add sums if wanted 39207993756SAndreas Gohr */ 393d6d97f60SAnna Dabrowska protected function renderSums() 394d6d97f60SAnna Dabrowska { 395d18090e8SAndreas Gohr if (empty($this->data['summarize'])) return; 39607993756SAndreas Gohr 397a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 3988925ba29SAndreas Gohr if ($this->mode == 'xhtml') { 3998925ba29SAndreas Gohr /** @noinspection PhpMethodParametersCountMismatchInspection */ 4008925ba29SAndreas Gohr $this->renderer->tablerow_open('summarize'); 4018925ba29SAndreas Gohr } else { 40207993756SAndreas Gohr $this->renderer->tablerow_open(); 4038925ba29SAndreas Gohr } 40407993756SAndreas Gohr 40507993756SAndreas Gohr if ($this->data['rownumbers']) { 4068925ba29SAndreas Gohr $this->renderer->tableheader_open(); 4078925ba29SAndreas Gohr $this->renderer->tableheader_close(); 40807993756SAndreas Gohr } 40907993756SAndreas Gohr 410aee4116bSAndreas Gohr $len = count($this->columns); 41107993756SAndreas Gohr for ($i = 0; $i < $len; $i++) { 4128925ba29SAndreas Gohr $this->renderer->tableheader_open(1, $this->data['align'][$i]); 413aee4116bSAndreas Gohr if (!empty($this->sums[$i])) { 4149b97e610SAndreas Gohr $this->renderer->cdata('∑ '); 4159b97e610SAndreas Gohr $this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode); 4167234bfb1Ssplitbrain } elseif ($this->mode == 'xhtml') { 41707993756SAndreas Gohr $this->renderer->doc .= ' '; 41807993756SAndreas Gohr } 4198925ba29SAndreas Gohr $this->renderer->tableheader_close(); 42007993756SAndreas Gohr } 42107993756SAndreas Gohr $this->renderer->tablerow_close(); 422a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = false; 42307993756SAndreas Gohr } 42407993756SAndreas Gohr 42507993756SAndreas Gohr /** 426986ab7e6SAndreas Gohr * Adds paging controls to the table 42707993756SAndreas Gohr */ 428d6d97f60SAnna Dabrowska protected function renderPagingControls() 429d6d97f60SAnna Dabrowska { 430a0bf8bb2SAndreas Gohr if ($this->mode != 'xhtml') return; 43107993756SAndreas Gohr 432fdf37115SAndreas Gohr $limit = $this->searchConfig->getLimit(); 433fdf37115SAndreas Gohr if (!$limit) return; 434fdf37115SAndreas Gohr $offset = $this->searchConfig->getOffset(); 435fdf37115SAndreas Gohr 436a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 43707993756SAndreas Gohr $this->renderer->tablerow_open(); 4384bc1074dSMichael Grosse $this->renderer->tableheader_open((count($this->columns) + ($this->data['rownumbers'] ? 1 : 0))); 439fdf37115SAndreas Gohr 44007993756SAndreas Gohr 44107993756SAndreas Gohr // prev link 44207993756SAndreas Gohr if ($offset) { 443fdf37115SAndreas Gohr $prev = $offset - $limit; 44407993756SAndreas Gohr if ($prev < 0) { 44507993756SAndreas Gohr $prev = 0; 44607993756SAndreas Gohr } 44707993756SAndreas Gohr 44807993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 44907993756SAndreas Gohr $dynamic->setOffset($prev); 45007993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 45107993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="prev">' . $this->helper->getLang('prev') . '</a>'; 45207993756SAndreas Gohr } 45307993756SAndreas Gohr 45407993756SAndreas Gohr // next link 455fdf37115SAndreas Gohr if ($this->resultCount > $offset + $limit) { 456fdf37115SAndreas Gohr $next = $offset + $limit; 45707993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 45807993756SAndreas Gohr $dynamic->setOffset($next); 45907993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 46007993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="next">' . $this->helper->getLang('next') . '</a>'; 46107993756SAndreas Gohr } 46207993756SAndreas Gohr 46307993756SAndreas Gohr $this->renderer->tableheader_close(); 46407993756SAndreas Gohr $this->renderer->tablerow_close(); 465a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 46607993756SAndreas Gohr } 46709dd691aSAndreas Gohr 46809dd691aSAndreas Gohr /** 46909dd691aSAndreas Gohr * Adds CSV export controls 47009dd691aSAndreas Gohr */ 471d6d97f60SAnna Dabrowska protected function renderExportControls() 472d6d97f60SAnna Dabrowska { 47309dd691aSAndreas Gohr if ($this->mode != 'xhtml') return; 4747b240ca8SAndreas Gohr if (empty($this->data['csv'])) return; 47509dd691aSAndreas Gohr if (!$this->resultCount) return; 47609dd691aSAndreas Gohr 477c8ccdaf8SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 478c8ccdaf8SAndreas Gohr $params = $dynamic->getURLParameters(); 479c8ccdaf8SAndreas Gohr $params['hash'] = $this->renderer->info['struct_table_hash']; 480c8ccdaf8SAndreas Gohr 48109dd691aSAndreas Gohr // FIXME apply dynamic filters 482eafc109fSAndreas Gohr $link = exportlink($this->id, 'struct_csv', $params); 48309dd691aSAndreas Gohr 48417a3a578SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="export mediafile mf_csv">' . 48517a3a578SAndreas Gohr $this->helper->getLang('csvexport') . '</a>'; 48609dd691aSAndreas Gohr } 48707993756SAndreas Gohr} 488