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 */ 10d90aa848SAndreas Gohrclass AggregationTable extends Aggregation 11d6d97f60SAnna Dabrowska{ 12d90aa848SAndreas Gohr /** @var array for summing up columns */ 13d90aa848SAndreas Gohr protected $sums; 1407993756SAndreas Gohr 15d90aa848SAndreas Gohr /** @var string[] the result PIDs for each row */ 16d4b5a17cSAndreas Gohr protected $resultPIDs; 170ceefd5cSAnna Dabrowska protected $resultRids; 186fd73b4bSAnna Dabrowska protected $resultRevs; 19d4b5a17cSAndreas Gohr 208ce43f5aSAnna Dabrowska public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 21d6d97f60SAnna Dabrowska { 22d90aa848SAndreas Gohr parent::__construct($id, $mode, $renderer, $searchConfig); 23d4b5a17cSAndreas Gohr $this->resultPIDs = $this->searchConfig->getPids(); 240ceefd5cSAnna Dabrowska $this->resultRids = $this->searchConfig->getRids(); 256fd73b4bSAnna Dabrowska $this->resultRevs = $this->searchConfig->getRevs(); 2607993756SAndreas Gohr } 2707993756SAndreas Gohr 28d90aa848SAndreas Gohr /** @inheritdoc */ 29d90aa848SAndreas Gohr public function render($showNotFound = false) 30d6d97f60SAnna Dabrowska { 31b7e1d73bSAndreas Gohr 32b7e1d73bSAndreas Gohr // abort early if there are no results at all (not filtered) 33d90aa848SAndreas Gohr if (!$this->resultCount && !$this->isDynamicallyFiltered() && $showNotFound) { 34b7e1d73bSAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 35b7e1d73bSAndreas Gohr return; 36b7e1d73bSAndreas Gohr } 37b7e1d73bSAndreas Gohr 38986ab7e6SAndreas Gohr $this->renderActiveFilters(); 39844a4f01SFrieder Schrempf 40844a4f01SFrieder Schrempf $rendercontext = array( 41844a4f01SFrieder Schrempf 'table' => $this, 42844a4f01SFrieder Schrempf 'renderer' => $this->renderer, 433f640228SFrieder Schrempf 'format' => $this->mode, 44844a4f01SFrieder Schrempf 'search' => $this->searchConfig, 45844a4f01SFrieder Schrempf 'columns' => $this->columns, 46844a4f01SFrieder Schrempf 'data' => $this->result 47844a4f01SFrieder Schrempf ); 48844a4f01SFrieder Schrempf 492dbe71f8SAnna Dabrowska $event = new \Doku_Event( 50844a4f01SFrieder Schrempf 'PLUGIN_STRUCT_RENDER_AGGREGATION_TABLE', 512dbe71f8SAnna Dabrowska $rendercontext 52844a4f01SFrieder Schrempf ); 532dbe71f8SAnna Dabrowska $event->trigger([$this, 'renderTable']); 54844a4f01SFrieder Schrempf 55844a4f01SFrieder Schrempf // export handle 56844a4f01SFrieder Schrempf $this->renderExportControls(); 57844a4f01SFrieder Schrempf } 58844a4f01SFrieder Schrempf 59844a4f01SFrieder Schrempf /** 60844a4f01SFrieder Schrempf * Render the default aggregation table 61844a4f01SFrieder Schrempf */ 62844a4f01SFrieder Schrempf public function renderTable($rendercontext) 63844a4f01SFrieder Schrempf { 6407993756SAndreas Gohr $this->renderer->table_open(); 6507993756SAndreas Gohr 6607993756SAndreas Gohr // header 6707993756SAndreas Gohr $this->renderer->tablethead_open(); 68986ab7e6SAndreas Gohr $this->renderColumnHeaders(); 69986ab7e6SAndreas Gohr $this->renderDynamicFilters(); 7007993756SAndreas Gohr $this->renderer->tablethead_close(); 7107993756SAndreas Gohr 7207993756SAndreas Gohr if ($this->resultCount) { 7307993756SAndreas Gohr // actual data 74a9fd81f9SAndreas Gohr $this->renderer->tabletbody_open(); 75986ab7e6SAndreas Gohr $this->renderResult(); 76a9fd81f9SAndreas Gohr $this->renderer->tabletbody_close(); 7707993756SAndreas Gohr 78a9fd81f9SAndreas Gohr // footer (tfoot is develonly currently) 79a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_open')) $this->renderer->tabletfoot_open(); 80986ab7e6SAndreas Gohr $this->renderSums(); 81986ab7e6SAndreas Gohr $this->renderPagingControls(); 82a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_close')) $this->renderer->tabletfoot_close(); 8307993756SAndreas Gohr } else { 8407993756SAndreas Gohr // nothing found 85986ab7e6SAndreas Gohr $this->renderEmptyResult(); 8607993756SAndreas Gohr } 8707993756SAndreas Gohr 8807993756SAndreas Gohr // table close 8907993756SAndreas Gohr $this->renderer->table_close(); 9007993756SAndreas Gohr } 9107993756SAndreas Gohr 9207993756SAndreas Gohr /** 9307993756SAndreas Gohr * Adds additional info to document and renderer in XHTML mode 9407993756SAndreas Gohr * 9507993756SAndreas Gohr * @see finishScope() 9607993756SAndreas Gohr */ 97*af0ce8d2SAndreas Gohr public function startScope() 98d6d97f60SAnna Dabrowska { 9907993756SAndreas Gohr // unique identifier for this aggregation 10007993756SAndreas Gohr $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true)); 10109dd691aSAndreas Gohr 102*af0ce8d2SAndreas Gohr parent::startScope(); 10307993756SAndreas Gohr } 10407993756SAndreas Gohr 10507993756SAndreas Gohr /** 10607993756SAndreas Gohr * Closes the table and anything opened in startScope() 10707993756SAndreas Gohr * 10807993756SAndreas Gohr * @see startScope() 10907993756SAndreas Gohr */ 110*af0ce8d2SAndreas Gohr public function finishScope() 111d6d97f60SAnna Dabrowska { 11207993756SAndreas Gohr // remove identifier from renderer again 11307993756SAndreas Gohr if (isset($this->renderer->info['struct_table_hash'])) { 11407993756SAndreas Gohr unset($this->renderer->info['struct_table_hash']); 11507993756SAndreas Gohr } 11609dd691aSAndreas Gohr 117*af0ce8d2SAndreas Gohr parent::finishScope(); 11807993756SAndreas Gohr } 11907993756SAndreas Gohr 12007993756SAndreas Gohr /** 12107993756SAndreas Gohr * Displays info about the currently applied filters 12207993756SAndreas Gohr */ 123d6d97f60SAnna Dabrowska protected function renderActiveFilters() 124d6d97f60SAnna Dabrowska { 12507993756SAndreas Gohr if ($this->mode != 'xhtml') return; 12607993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 12707993756SAndreas Gohr $filters = $dynamic->getFilters(); 12807993756SAndreas Gohr if (!$filters) return; 12907993756SAndreas Gohr 13007993756SAndreas Gohr $fltrs = array(); 13107993756SAndreas Gohr foreach ($filters as $column => $filter) { 13207993756SAndreas Gohr list($comp, $value) = $filter; 13304ec4785SAnna Dabrowska 13404ec4785SAnna Dabrowska // display the filters in a human readable format 13504ec4785SAnna Dabrowska foreach ($this->columns as $col) { 13604ec4785SAnna Dabrowska if ($column === $col->getFullQualifiedLabel()) { 13704ec4785SAnna Dabrowska $column = $col->getTranslatedLabel(); 13804ec4785SAnna Dabrowska } 13904ec4785SAnna Dabrowska } 1401f075418SAnna Dabrowska $fltrs[] = sprintf('"%s" %s "%s"', $column, $this->helper->getLang("comparator $comp"), $value); 14107993756SAndreas Gohr } 14207993756SAndreas Gohr 14307993756SAndreas Gohr $this->renderer->doc .= '<div class="filter">'; 14417a3a578SAndreas Gohr $this->renderer->doc .= '<h4>' . 14517a3a578SAndreas Gohr sprintf( 14617a3a578SAndreas Gohr $this->helper->getLang('tablefilteredby'), 14717a3a578SAndreas Gohr hsc(implode(' & ', $fltrs)) 14817a3a578SAndreas Gohr ) . 14917a3a578SAndreas Gohr '</h4>'; 15007993756SAndreas Gohr $this->renderer->doc .= '<div class="resetfilter">'; 15107993756SAndreas Gohr $this->renderer->internallink($this->id, $this->helper->getLang('tableresetfilter')); 15207993756SAndreas Gohr $this->renderer->doc .= '</div>'; 15307993756SAndreas Gohr $this->renderer->doc .= '</div>'; 15407993756SAndreas Gohr } 15507993756SAndreas Gohr 15607993756SAndreas Gohr /** 15707993756SAndreas Gohr * Shows the column headers with links to sort by column 15807993756SAndreas Gohr */ 159d6d97f60SAnna Dabrowska protected function renderColumnHeaders() 160d6d97f60SAnna Dabrowska { 16107993756SAndreas Gohr $this->renderer->tablerow_open(); 16207993756SAndreas Gohr 16307993756SAndreas Gohr // additional column for row numbers 16434ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 16507993756SAndreas Gohr $this->renderer->tableheader_open(); 16607993756SAndreas Gohr $this->renderer->cdata('#'); 16707993756SAndreas Gohr $this->renderer->tableheader_close(); 16807993756SAndreas Gohr } 16907993756SAndreas Gohr 17007993756SAndreas Gohr // show all headers 1718c4ee9beSAndreas Gohr foreach ($this->columns as $num => $column) { 1728c4ee9beSAndreas Gohr $header = ''; 1738c4ee9beSAndreas Gohr if (isset($this->data['headers'][$num])) { 1748c4ee9beSAndreas Gohr $header = $this->data['headers'][$num]; 1758c4ee9beSAndreas Gohr } 17607993756SAndreas Gohr 17707993756SAndreas Gohr // use field label if no header was set 17807993756SAndreas Gohr if (blank($header)) { 17901f8b845SAndreas Gohr if (is_a($column, 'dokuwiki\plugin\struct\meta\Column')) { 18007993756SAndreas Gohr $header = $column->getTranslatedLabel(); 18107993756SAndreas Gohr } else { 18207993756SAndreas Gohr $header = 'column ' . $num; // this should never happen 18307993756SAndreas Gohr } 18407993756SAndreas Gohr } 18507993756SAndreas Gohr 18607993756SAndreas Gohr // simple mode first 18707993756SAndreas Gohr if ($this->mode != 'xhtml') { 18807993756SAndreas Gohr $this->renderer->tableheader_open(); 18907993756SAndreas Gohr $this->renderer->cdata($header); 19007993756SAndreas Gohr $this->renderer->tableheader_close(); 19107993756SAndreas Gohr continue; 19207993756SAndreas Gohr } 19307993756SAndreas Gohr 19407993756SAndreas Gohr // still here? create custom header for more flexibility 19507993756SAndreas Gohr 1969113d04aSAndreas Gohr // width setting, widths are prevalidated, no escape needed 19707993756SAndreas Gohr $width = ''; 1989113d04aSAndreas Gohr if (isset($this->data['widths'][$num]) && $this->data['widths'][$num] != '-') { 1999113d04aSAndreas Gohr $width = ' style="min-width: ' . $this->data['widths'][$num] . ';' . 2009113d04aSAndreas Gohr 'max-width: ' . $this->data['widths'][$num] . ';"'; 20107993756SAndreas Gohr } 20207993756SAndreas Gohr 203d4b5a17cSAndreas Gohr // prepare data attribute for inline edits 204d6d97f60SAnna Dabrowska if ( 205d6d97f60SAnna Dabrowska !is_a($column, '\dokuwiki\plugin\struct\meta\PageColumn') && 206d4b5a17cSAndreas Gohr !is_a($column, '\dokuwiki\plugin\struct\meta\RevisionColumn') 207d4b5a17cSAndreas Gohr ) { 208d4b5a17cSAndreas Gohr $data = 'data-field="' . hsc($column->getFullQualifiedLabel()) . '"'; 209d4b5a17cSAndreas Gohr } else { 210d4b5a17cSAndreas Gohr $data = ''; 211d4b5a17cSAndreas Gohr } 212d4b5a17cSAndreas Gohr 21307993756SAndreas Gohr // sort indicator and link 21407993756SAndreas Gohr $sortclass = ''; 21507993756SAndreas Gohr $sorts = $this->searchConfig->getSorts(); 21607993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 217aa124708SAndreas Gohr $dynamic->setSort($column, true); 21807993756SAndreas Gohr if (isset($sorts[$column->getFullQualifiedLabel()])) { 219aa124708SAndreas Gohr list(/*colname*/, $currentSort) = $sorts[$column->getFullQualifiedLabel()]; 220aa124708SAndreas Gohr if ($currentSort) { 22107993756SAndreas Gohr $sortclass = 'sort-down'; 22207993756SAndreas Gohr $dynamic->setSort($column, false); 22307993756SAndreas Gohr } else { 22407993756SAndreas Gohr $sortclass = 'sort-up'; 22507993756SAndreas Gohr } 22607993756SAndreas Gohr } 22707993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 22807993756SAndreas Gohr 22907993756SAndreas Gohr // output XHTML header 230d4b5a17cSAndreas Gohr $this->renderer->doc .= "<th $width $data>"; 23117a3a578SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="' . $sortclass . '" ' . 23217a3a578SAndreas Gohr 'title="' . $this->helper->getLang('sort') . '">' . hsc($header) . '</a>'; 23307993756SAndreas Gohr $this->renderer->doc .= '</th>'; 23407993756SAndreas Gohr } 23507993756SAndreas Gohr 23607993756SAndreas Gohr $this->renderer->tablerow_close(); 23707993756SAndreas Gohr } 23807993756SAndreas Gohr 23907993756SAndreas Gohr /** 240b7e1d73bSAndreas Gohr * Is the result set currently dynamically filtered? 241b7e1d73bSAndreas Gohr * @return bool 242b7e1d73bSAndreas Gohr */ 243d6d97f60SAnna Dabrowska protected function isDynamicallyFiltered() 244d6d97f60SAnna Dabrowska { 245b7e1d73bSAndreas Gohr if ($this->mode != 'xhtml') return false; 246b7e1d73bSAndreas Gohr if (!$this->data['dynfilters']) return false; 247b7e1d73bSAndreas Gohr 248b7e1d73bSAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 249b7e1d73bSAndreas Gohr return (bool)$dynamic->getFilters(); 250b7e1d73bSAndreas Gohr } 251b7e1d73bSAndreas Gohr 252b7e1d73bSAndreas Gohr /** 25307993756SAndreas Gohr * Add input fields for dynamic filtering 25407993756SAndreas Gohr */ 255d6d97f60SAnna Dabrowska protected function renderDynamicFilters() 256d6d97f60SAnna Dabrowska { 25707993756SAndreas Gohr if ($this->mode != 'xhtml') return; 2581ca21e17SAnna Dabrowska if (empty($this->data['dynfilters'])) return; 2591bc467a4SMichael Grosse if (is_a($this->renderer, 'renderer_plugin_dw2pdf')) { 260e6ae02ecSMichael Grosse return; 261e6ae02ecSMichael Grosse } 2621bc467a4SMichael Grosse global $conf; 26307993756SAndreas Gohr 26407993756SAndreas Gohr $this->renderer->doc .= '<tr class="dataflt">'; 26507993756SAndreas Gohr 26607993756SAndreas Gohr // add extra column for row numbers 26707993756SAndreas Gohr if ($this->data['rownumbers']) { 26807993756SAndreas Gohr $this->renderer->doc .= '<th></th>'; 26907993756SAndreas Gohr } 27007993756SAndreas Gohr 27107993756SAndreas Gohr // each column gets a form 27207993756SAndreas Gohr foreach ($this->columns as $column) { 27307993756SAndreas Gohr $this->renderer->doc .= '<th>'; 27417a3a578SAndreas Gohr 27517a3a578SAndreas Gohr // BEGIN FORM 27607993756SAndreas Gohr $form = new \Doku_Form(array('method' => 'GET', 'action' => wl($this->id))); 27776195677SAndreas Gohr unset($form->_hidden['sectok']); // we don't need it here 27876195677SAndreas Gohr if (!$conf['userewrite']) $form->addHidden('id', $this->id); 27907993756SAndreas Gohr 28007993756SAndreas Gohr // current value 28107993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 28207993756SAndreas Gohr $filters = $dynamic->getFilters(); 28307993756SAndreas Gohr if (isset($filters[$column->getFullQualifiedLabel()])) { 28407993756SAndreas Gohr list(, $current) = $filters[$column->getFullQualifiedLabel()]; 28507993756SAndreas Gohr $dynamic->removeFilter($column); 28607993756SAndreas Gohr } else { 28707993756SAndreas Gohr $current = ''; 28807993756SAndreas Gohr } 28907993756SAndreas Gohr 29007993756SAndreas Gohr // Add current request params 29107993756SAndreas Gohr $params = $dynamic->getURLParameters(); 29207993756SAndreas Gohr foreach ($params as $key => $val) { 29307993756SAndreas Gohr $form->addHidden($key, $val); 29407993756SAndreas Gohr } 29507993756SAndreas Gohr 29607993756SAndreas Gohr // add input field 297db9b8745SAndreas Gohr $key = $column->getFullQualifiedLabel() . $column->getType()->getDefaultComparator(); 29817a3a578SAndreas Gohr $form->addElement( 29917a3a578SAndreas Gohr form_makeField('text', SearchConfigParameters::$PARAM_FILTER . '[' . $key . ']', $current, '') 30017a3a578SAndreas Gohr ); 30107993756SAndreas Gohr $this->renderer->doc .= $form->getForm(); 30217a3a578SAndreas Gohr // END FORM 30317a3a578SAndreas Gohr 30407993756SAndreas Gohr $this->renderer->doc .= '</th>'; 30507993756SAndreas Gohr } 30607993756SAndreas Gohr $this->renderer->doc .= '</tr>'; 30707993756SAndreas Gohr } 30807993756SAndreas Gohr 30907993756SAndreas Gohr /** 31007993756SAndreas Gohr * Display the actual table data 31107993756SAndreas Gohr */ 312d6d97f60SAnna Dabrowska protected function renderResult() 313d6d97f60SAnna Dabrowska { 31407993756SAndreas Gohr foreach ($this->result as $rownum => $row) { 31547eb8cceSSzymon Olewniczak $data = array( 31647eb8cceSSzymon Olewniczak 'id' => $this->id, 31747eb8cceSSzymon Olewniczak 'mode' => $this->mode, 31847eb8cceSSzymon Olewniczak 'renderer' => $this->renderer, 31947eb8cceSSzymon Olewniczak 'searchConfig' => $this->searchConfig, 32047eb8cceSSzymon Olewniczak 'data' => $this->data, 32147eb8cceSSzymon Olewniczak 'rownum' => &$rownum, 32247eb8cceSSzymon Olewniczak 'row' => &$row, 32347eb8cceSSzymon Olewniczak ); 32447eb8cceSSzymon Olewniczak $evt = new \Doku_Event('PLUGIN_STRUCT_AGGREGATIONTABLE_RENDERRESULTROW', $data); 32547eb8cceSSzymon Olewniczak if ($evt->advise_before()) { 326f107f479SAndreas Gohr $this->renderResultRow($rownum, $row); 327f107f479SAndreas Gohr } 32847eb8cceSSzymon Olewniczak $evt->advise_after(); 32947eb8cceSSzymon Olewniczak } 330f107f479SAndreas Gohr } 331f107f479SAndreas Gohr 332f107f479SAndreas Gohr /** 333f107f479SAndreas Gohr * Render a single result row 334f107f479SAndreas Gohr * 335f107f479SAndreas Gohr * @param int $rownum 336f107f479SAndreas Gohr * @param array $row 337f107f479SAndreas Gohr */ 338d6d97f60SAnna Dabrowska protected function renderResultRow($rownum, $row) 339d6d97f60SAnna Dabrowska { 34007993756SAndreas Gohr $this->renderer->tablerow_open(); 34107993756SAndreas Gohr 342d4b5a17cSAndreas Gohr // add data attribute for inline edit 343d4b5a17cSAndreas Gohr if ($this->mode == 'xhtml') { 344d4b5a17cSAndreas Gohr $pid = $this->resultPIDs[$rownum]; 3450ceefd5cSAnna Dabrowska $rid = $this->resultRids[$rownum]; 3466fd73b4bSAnna Dabrowska $rev = $this->resultRevs[$rownum]; 347d4b5a17cSAndreas Gohr $this->renderer->doc = substr(rtrim($this->renderer->doc), 0, -1); // remove closing '>' 3486fd73b4bSAnna Dabrowska $this->renderer->doc .= ' data-pid="' . hsc($pid) . '" data-rev="' . $rev . '" data-rid="' . $rid . '">'; 349d4b5a17cSAndreas Gohr } 350d4b5a17cSAndreas Gohr 35107993756SAndreas Gohr // row number column 35234ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 35307993756SAndreas Gohr $this->renderer->tablecell_open(); 3543215aebfSSzymon Olewniczak $searchConfigConf = $this->searchConfig->getConf(); 3553215aebfSSzymon Olewniczak $this->renderer->cdata($rownum + $searchConfigConf['offset'] + 1); 35607993756SAndreas Gohr $this->renderer->tablecell_close(); 35707993756SAndreas Gohr } 35807993756SAndreas Gohr 35907993756SAndreas Gohr /** @var Value $value */ 36007993756SAndreas Gohr foreach ($row as $colnum => $value) { 36134ea6e10SAnna Dabrowska $align = isset($this->data['align'][$colnum]) ? $this->data['align'][$colnum] : null; 36234ea6e10SAnna Dabrowska $this->renderer->tablecell_open(1, $align); 36307993756SAndreas Gohr $value->render($this->renderer, $this->mode); 36407993756SAndreas Gohr $this->renderer->tablecell_close(); 36507993756SAndreas Gohr 36607993756SAndreas Gohr // summarize 3671ca21e17SAnna Dabrowska if (!empty($this->data['summarize']) && is_numeric($value->getValue())) { 36807993756SAndreas Gohr if (!isset($this->sums[$colnum])) { 36907993756SAndreas Gohr $this->sums[$colnum] = 0; 37007993756SAndreas Gohr } 37107993756SAndreas Gohr $this->sums[$colnum] += $value->getValue(); 37207993756SAndreas Gohr } 37307993756SAndreas Gohr } 37407993756SAndreas Gohr $this->renderer->tablerow_close(); 37507993756SAndreas Gohr } 37607993756SAndreas Gohr 37707993756SAndreas Gohr /** 37807993756SAndreas Gohr * Renders an information row for when no results were found 37907993756SAndreas Gohr */ 380d6d97f60SAnna Dabrowska protected function renderEmptyResult() 381d6d97f60SAnna Dabrowska { 38207993756SAndreas Gohr $this->renderer->tablerow_open(); 38370cf6339SAndreas Gohr $this->renderer->tablecell_open(count($this->columns) + $this->data['rownumbers'], 'center'); 38407993756SAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 38507993756SAndreas Gohr $this->renderer->tablecell_close(); 38607993756SAndreas Gohr $this->renderer->tablerow_close(); 38707993756SAndreas Gohr } 38807993756SAndreas Gohr 38907993756SAndreas Gohr /** 39007993756SAndreas Gohr * Add sums if wanted 39107993756SAndreas Gohr */ 392d6d97f60SAnna Dabrowska protected function renderSums() 393d6d97f60SAnna Dabrowska { 394d18090e8SAndreas Gohr if (empty($this->data['summarize'])) return; 39507993756SAndreas Gohr 396a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 3978925ba29SAndreas Gohr if ($this->mode == 'xhtml') { 3988925ba29SAndreas Gohr /** @noinspection PhpMethodParametersCountMismatchInspection */ 3998925ba29SAndreas Gohr $this->renderer->tablerow_open('summarize'); 4008925ba29SAndreas Gohr } else { 40107993756SAndreas Gohr $this->renderer->tablerow_open(); 4028925ba29SAndreas Gohr } 40307993756SAndreas Gohr 40407993756SAndreas Gohr if ($this->data['rownumbers']) { 4058925ba29SAndreas Gohr $this->renderer->tableheader_open(); 4068925ba29SAndreas Gohr $this->renderer->tableheader_close(); 40707993756SAndreas Gohr } 40807993756SAndreas Gohr 409aee4116bSAndreas Gohr $len = count($this->columns); 41007993756SAndreas Gohr for ($i = 0; $i < $len; $i++) { 4118925ba29SAndreas Gohr $this->renderer->tableheader_open(1, $this->data['align'][$i]); 412aee4116bSAndreas Gohr if (!empty($this->sums[$i])) { 4139b97e610SAndreas Gohr $this->renderer->cdata('∑ '); 4149b97e610SAndreas Gohr $this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode); 41507993756SAndreas Gohr } else { 41607993756SAndreas Gohr if ($this->mode == 'xhtml') { 41707993756SAndreas Gohr $this->renderer->doc .= ' '; 41807993756SAndreas Gohr } 41907993756SAndreas Gohr } 4208925ba29SAndreas Gohr $this->renderer->tableheader_close(); 42107993756SAndreas Gohr } 42207993756SAndreas Gohr $this->renderer->tablerow_close(); 423a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = false; 42407993756SAndreas Gohr } 42507993756SAndreas Gohr 42607993756SAndreas Gohr /** 427986ab7e6SAndreas Gohr * Adds paging controls to the table 42807993756SAndreas Gohr */ 429d6d97f60SAnna Dabrowska protected function renderPagingControls() 430d6d97f60SAnna Dabrowska { 43107993756SAndreas Gohr if (empty($this->data['limit'])) return; 432a0bf8bb2SAndreas Gohr if ($this->mode != 'xhtml') return; 43307993756SAndreas Gohr 434a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 43507993756SAndreas Gohr $this->renderer->tablerow_open(); 4364bc1074dSMichael Grosse $this->renderer->tableheader_open((count($this->columns) + ($this->data['rownumbers'] ? 1 : 0))); 43707993756SAndreas Gohr $offset = $this->data['offset']; 43807993756SAndreas Gohr 43907993756SAndreas Gohr // prev link 44007993756SAndreas Gohr if ($offset) { 44107993756SAndreas Gohr $prev = $offset - $this->data['limit']; 44207993756SAndreas Gohr if ($prev < 0) { 44307993756SAndreas Gohr $prev = 0; 44407993756SAndreas Gohr } 44507993756SAndreas Gohr 44607993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 44707993756SAndreas Gohr $dynamic->setOffset($prev); 44807993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 44907993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="prev">' . $this->helper->getLang('prev') . '</a>'; 45007993756SAndreas Gohr } 45107993756SAndreas Gohr 45207993756SAndreas Gohr // next link 45307993756SAndreas Gohr if ($this->resultCount > $offset + $this->data['limit']) { 45407993756SAndreas Gohr $next = $offset + $this->data['limit']; 45507993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 45607993756SAndreas Gohr $dynamic->setOffset($next); 45707993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 45807993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="next">' . $this->helper->getLang('next') . '</a>'; 45907993756SAndreas Gohr } 46007993756SAndreas Gohr 46107993756SAndreas Gohr $this->renderer->tableheader_close(); 46207993756SAndreas Gohr $this->renderer->tablerow_close(); 463a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 46407993756SAndreas Gohr } 46509dd691aSAndreas Gohr 46609dd691aSAndreas Gohr /** 46709dd691aSAndreas Gohr * Adds CSV export controls 46809dd691aSAndreas Gohr */ 469d6d97f60SAnna Dabrowska protected function renderExportControls() 470d6d97f60SAnna Dabrowska { 47109dd691aSAndreas Gohr if ($this->mode != 'xhtml') return; 4727b240ca8SAndreas Gohr if (empty($this->data['csv'])) return; 47309dd691aSAndreas Gohr if (!$this->resultCount) return; 47409dd691aSAndreas Gohr 475c8ccdaf8SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 476c8ccdaf8SAndreas Gohr $params = $dynamic->getURLParameters(); 477c8ccdaf8SAndreas Gohr $params['hash'] = $this->renderer->info['struct_table_hash']; 478c8ccdaf8SAndreas Gohr 47909dd691aSAndreas Gohr // FIXME apply dynamic filters 480eafc109fSAndreas Gohr $link = exportlink($this->id, 'struct_csv', $params); 48109dd691aSAndreas Gohr 48217a3a578SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="export mediafile mf_csv">' . 48317a3a578SAndreas Gohr $this->helper->getLang('csvexport') . '</a>'; 48409dd691aSAndreas Gohr } 48507993756SAndreas Gohr} 486