107993756SAndreas Gohr<?php 207993756SAndreas Gohr 3ba766201SAndreas Gohrnamespace dokuwiki\plugin\struct\meta; 407993756SAndreas Gohr 5*844a4f01SFrieder Schrempfuse dokuwiki\Extension\Event; 6*844a4f01SFrieder Schrempf 7d60f71efSAndreas Gohr/** 8d60f71efSAndreas Gohr * Creates the table aggregation output 9d60f71efSAndreas Gohr * 10ba766201SAndreas Gohr * @package dokuwiki\plugin\struct\meta 11d60f71efSAndreas Gohr */ 12d6d97f60SAnna Dabrowskaclass AggregationTable 13d6d97f60SAnna Dabrowska{ 1407993756SAndreas Gohr 1507993756SAndreas Gohr /** 1607993756SAndreas Gohr * @var string the page id of the page this is rendered to 1707993756SAndreas Gohr */ 1807993756SAndreas Gohr protected $id; 1907993756SAndreas Gohr /** 2007993756SAndreas Gohr * @var string the Type of renderer used 2107993756SAndreas Gohr */ 2207993756SAndreas Gohr protected $mode; 2307993756SAndreas Gohr /** 2407993756SAndreas Gohr * @var \Doku_Renderer the DokuWiki renderer used to create the output 2507993756SAndreas Gohr */ 2607993756SAndreas Gohr protected $renderer; 2707993756SAndreas Gohr /** 2807993756SAndreas Gohr * @var SearchConfig the configured search - gives access to columns etc. 2907993756SAndreas Gohr */ 3007993756SAndreas Gohr protected $searchConfig; 3107993756SAndreas Gohr 3207993756SAndreas Gohr /** 3307993756SAndreas Gohr * @var Column[] the list of columns to be displayed 3407993756SAndreas Gohr */ 3507993756SAndreas Gohr protected $columns; 3607993756SAndreas Gohr 3707993756SAndreas Gohr /** 3807993756SAndreas Gohr * @var Value[][] the search result 3907993756SAndreas Gohr */ 4007993756SAndreas Gohr protected $result; 4107993756SAndreas Gohr 4207993756SAndreas Gohr /** 4307993756SAndreas Gohr * @var int number of all results 4407993756SAndreas Gohr */ 4507993756SAndreas Gohr protected $resultCount; 4607993756SAndreas Gohr 4707993756SAndreas Gohr /** 48d4b5a17cSAndreas Gohr * @var string[] the result PIDs for each row 49d4b5a17cSAndreas Gohr */ 50d4b5a17cSAndreas Gohr protected $resultPIDs; 510ceefd5cSAnna Dabrowska protected $resultRids; 526fd73b4bSAnna Dabrowska protected $resultRevs; 53d4b5a17cSAndreas Gohr 54d4b5a17cSAndreas Gohr /** 5507993756SAndreas Gohr * @var array for summing up columns 5607993756SAndreas Gohr */ 5707993756SAndreas Gohr protected $sums; 5807993756SAndreas Gohr 5907993756SAndreas Gohr /** 606b5e52fdSAndreas Gohr * @var bool skip full table when no results found 616b5e52fdSAndreas Gohr */ 626b5e52fdSAndreas Gohr protected $simplenone = true; 636b5e52fdSAndreas Gohr 646b5e52fdSAndreas Gohr /** 6507993756SAndreas Gohr * @todo we might be able to get rid of this helper and move this to SearchConfig 6607993756SAndreas Gohr * @var \helper_plugin_struct_config 6707993756SAndreas Gohr */ 6807993756SAndreas Gohr protected $helper; 6907993756SAndreas Gohr 7007993756SAndreas Gohr /** 7107993756SAndreas Gohr * Initialize the Aggregation renderer and executes the search 7207993756SAndreas Gohr * 7307993756SAndreas Gohr * You need to call @see render() on the resulting object. 7407993756SAndreas Gohr * 7507993756SAndreas Gohr * @param string $id 7607993756SAndreas Gohr * @param string $mode 7707993756SAndreas Gohr * @param \Doku_Renderer $renderer 7807993756SAndreas Gohr * @param SearchConfig $searchConfig 7907993756SAndreas Gohr */ 808ce43f5aSAnna Dabrowska public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 81d6d97f60SAnna Dabrowska { 8207993756SAndreas Gohr $this->id = $id; 8307993756SAndreas Gohr $this->mode = $mode; 8407993756SAndreas Gohr $this->renderer = $renderer; 8507993756SAndreas Gohr $this->searchConfig = $searchConfig; 8607993756SAndreas Gohr $this->data = $searchConfig->getConf(); 8707993756SAndreas Gohr $this->columns = $searchConfig->getColumns(); 8807993756SAndreas Gohr 898ce43f5aSAnna Dabrowska $this->result = $this->searchConfig->execute(); 9007993756SAndreas Gohr $this->resultCount = $this->searchConfig->getCount(); 91d4b5a17cSAndreas Gohr $this->resultPIDs = $this->searchConfig->getPids(); 920ceefd5cSAnna Dabrowska $this->resultRids = $this->searchConfig->getRids(); 936fd73b4bSAnna Dabrowska $this->resultRevs = $this->searchConfig->getRevs(); 9407993756SAndreas Gohr $this->helper = plugin_load('helper', 'struct_config'); 9507993756SAndreas Gohr } 9607993756SAndreas Gohr 9707993756SAndreas Gohr /** 98*844a4f01SFrieder Schrempf * Returns the page id for the table 99*844a4f01SFrieder Schrempf */ 100*844a4f01SFrieder Schrempf public function getID() 101*844a4f01SFrieder Schrempf { 102*844a4f01SFrieder Schrempf return $this->id; 103*844a4f01SFrieder Schrempf } 104*844a4f01SFrieder Schrempf 105*844a4f01SFrieder Schrempf /** 10607993756SAndreas Gohr * Create the table on the renderer 10707993756SAndreas Gohr */ 108d6d97f60SAnna Dabrowska public function render() 109d6d97f60SAnna Dabrowska { 110b7e1d73bSAndreas Gohr 111b7e1d73bSAndreas Gohr // abort early if there are no results at all (not filtered) 1126b5e52fdSAndreas Gohr if (!$this->resultCount && !$this->isDynamicallyFiltered() && $this->simplenone) { 113b7e1d73bSAndreas Gohr $this->startScope(); 114b7e1d73bSAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 115b7e1d73bSAndreas Gohr $this->finishScope(); 116b7e1d73bSAndreas Gohr return; 117b7e1d73bSAndreas Gohr } 118b7e1d73bSAndreas Gohr 11907993756SAndreas Gohr $this->startScope(); 120986ab7e6SAndreas Gohr $this->renderActiveFilters(); 121*844a4f01SFrieder Schrempf 122*844a4f01SFrieder Schrempf $rendercontext = array( 123*844a4f01SFrieder Schrempf 'table' => $this, 124*844a4f01SFrieder Schrempf 'renderer' => $this->renderer, 125*844a4f01SFrieder Schrempf 'search' => $this->searchConfig, 126*844a4f01SFrieder Schrempf 'columns' => $this->columns, 127*844a4f01SFrieder Schrempf 'data' => $this->result 128*844a4f01SFrieder Schrempf ); 129*844a4f01SFrieder Schrempf 130*844a4f01SFrieder Schrempf Event::createAndTrigger( 131*844a4f01SFrieder Schrempf 'PLUGIN_STRUCT_RENDER_AGGREGATION_TABLE', 132*844a4f01SFrieder Schrempf $rendercontext, 133*844a4f01SFrieder Schrempf array($this, 'renderTable') 134*844a4f01SFrieder Schrempf ); 135*844a4f01SFrieder Schrempf 136*844a4f01SFrieder Schrempf // export handle 137*844a4f01SFrieder Schrempf $this->renderExportControls(); 138*844a4f01SFrieder Schrempf $this->finishScope(); 139*844a4f01SFrieder Schrempf } 140*844a4f01SFrieder Schrempf 141*844a4f01SFrieder Schrempf /** 142*844a4f01SFrieder Schrempf * Render the default aggregation table 143*844a4f01SFrieder Schrempf */ 144*844a4f01SFrieder Schrempf public function renderTable($rendercontext) 145*844a4f01SFrieder Schrempf { 14607993756SAndreas Gohr $this->renderer->table_open(); 14707993756SAndreas Gohr 14807993756SAndreas Gohr // header 14907993756SAndreas Gohr $this->renderer->tablethead_open(); 150986ab7e6SAndreas Gohr $this->renderColumnHeaders(); 151986ab7e6SAndreas Gohr $this->renderDynamicFilters(); 15207993756SAndreas Gohr $this->renderer->tablethead_close(); 15307993756SAndreas Gohr 15407993756SAndreas Gohr if ($this->resultCount) { 15507993756SAndreas Gohr // actual data 156a9fd81f9SAndreas Gohr $this->renderer->tabletbody_open(); 157986ab7e6SAndreas Gohr $this->renderResult(); 158a9fd81f9SAndreas Gohr $this->renderer->tabletbody_close(); 15907993756SAndreas Gohr 160a9fd81f9SAndreas Gohr // footer (tfoot is develonly currently) 161a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_open')) $this->renderer->tabletfoot_open(); 162986ab7e6SAndreas Gohr $this->renderSums(); 163986ab7e6SAndreas Gohr $this->renderPagingControls(); 164a9fd81f9SAndreas Gohr if (method_exists($this->renderer, 'tabletfoot_close')) $this->renderer->tabletfoot_close(); 16507993756SAndreas Gohr } else { 16607993756SAndreas Gohr // nothing found 167986ab7e6SAndreas Gohr $this->renderEmptyResult(); 16807993756SAndreas Gohr } 16907993756SAndreas Gohr 17007993756SAndreas Gohr // table close 17107993756SAndreas Gohr $this->renderer->table_close(); 17207993756SAndreas Gohr } 17307993756SAndreas Gohr 17407993756SAndreas Gohr /** 17507993756SAndreas Gohr * Adds additional info to document and renderer in XHTML mode 17607993756SAndreas Gohr * 17707993756SAndreas Gohr * @see finishScope() 17807993756SAndreas Gohr */ 179d6d97f60SAnna Dabrowska protected function startScope() 180d6d97f60SAnna Dabrowska { 18107993756SAndreas Gohr // unique identifier for this aggregation 18207993756SAndreas Gohr $this->renderer->info['struct_table_hash'] = md5(var_export($this->data, true)); 18309dd691aSAndreas Gohr 18409dd691aSAndreas Gohr // wrapping div 18509dd691aSAndreas Gohr if ($this->mode != 'xhtml') return; 18609dd691aSAndreas Gohr $this->renderer->doc .= "<div class=\"structaggregation\">"; 18707993756SAndreas Gohr } 18807993756SAndreas Gohr 18907993756SAndreas Gohr /** 19007993756SAndreas Gohr * Closes the table and anything opened in startScope() 19107993756SAndreas Gohr * 19207993756SAndreas Gohr * @see startScope() 19307993756SAndreas Gohr */ 194d6d97f60SAnna Dabrowska protected function finishScope() 195d6d97f60SAnna Dabrowska { 19607993756SAndreas Gohr // remove identifier from renderer again 19707993756SAndreas Gohr if (isset($this->renderer->info['struct_table_hash'])) { 19807993756SAndreas Gohr unset($this->renderer->info['struct_table_hash']); 19907993756SAndreas Gohr } 20009dd691aSAndreas Gohr 20109dd691aSAndreas Gohr // wrapping div 20209dd691aSAndreas Gohr if ($this->mode != 'xhtml') return; 20309dd691aSAndreas Gohr $this->renderer->doc .= '</div>'; 20407993756SAndreas Gohr } 20507993756SAndreas Gohr 20607993756SAndreas Gohr /** 20707993756SAndreas Gohr * Displays info about the currently applied filters 20807993756SAndreas Gohr */ 209d6d97f60SAnna Dabrowska protected function renderActiveFilters() 210d6d97f60SAnna Dabrowska { 21107993756SAndreas Gohr if ($this->mode != 'xhtml') return; 21207993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 21307993756SAndreas Gohr $filters = $dynamic->getFilters(); 21407993756SAndreas Gohr if (!$filters) return; 21507993756SAndreas Gohr 21607993756SAndreas Gohr $fltrs = array(); 21707993756SAndreas Gohr foreach ($filters as $column => $filter) { 21807993756SAndreas Gohr list($comp, $value) = $filter; 21904ec4785SAnna Dabrowska 22004ec4785SAnna Dabrowska // display the filters in a human readable format 22104ec4785SAnna Dabrowska foreach ($this->columns as $col) { 22204ec4785SAnna Dabrowska if ($column === $col->getFullQualifiedLabel()) { 22304ec4785SAnna Dabrowska $column = $col->getTranslatedLabel(); 22404ec4785SAnna Dabrowska } 22504ec4785SAnna Dabrowska } 2261f075418SAnna Dabrowska $fltrs[] = sprintf('"%s" %s "%s"', $column, $this->helper->getLang("comparator $comp"), $value); 22707993756SAndreas Gohr } 22807993756SAndreas Gohr 22907993756SAndreas Gohr $this->renderer->doc .= '<div class="filter">'; 23007993756SAndreas Gohr $this->renderer->doc .= '<h4>' . sprintf($this->helper->getLang('tablefilteredby'), hsc(implode(' & ', $fltrs))) . '</h4>'; 23107993756SAndreas Gohr $this->renderer->doc .= '<div class="resetfilter">'; 23207993756SAndreas Gohr $this->renderer->internallink($this->id, $this->helper->getLang('tableresetfilter')); 23307993756SAndreas Gohr $this->renderer->doc .= '</div>'; 23407993756SAndreas Gohr $this->renderer->doc .= '</div>'; 23507993756SAndreas Gohr } 23607993756SAndreas Gohr 23707993756SAndreas Gohr /** 23807993756SAndreas Gohr * Shows the column headers with links to sort by column 23907993756SAndreas Gohr */ 240d6d97f60SAnna Dabrowska protected function renderColumnHeaders() 241d6d97f60SAnna Dabrowska { 24207993756SAndreas Gohr $this->renderer->tablerow_open(); 24307993756SAndreas Gohr 24407993756SAndreas Gohr // additional column for row numbers 24534ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 24607993756SAndreas Gohr $this->renderer->tableheader_open(); 24707993756SAndreas Gohr $this->renderer->cdata('#'); 24807993756SAndreas Gohr $this->renderer->tableheader_close(); 24907993756SAndreas Gohr } 25007993756SAndreas Gohr 25107993756SAndreas Gohr // show all headers 2528c4ee9beSAndreas Gohr foreach ($this->columns as $num => $column) { 2538c4ee9beSAndreas Gohr $header = ''; 2548c4ee9beSAndreas Gohr if (isset($this->data['headers'][$num])) { 2558c4ee9beSAndreas Gohr $header = $this->data['headers'][$num]; 2568c4ee9beSAndreas Gohr } 25707993756SAndreas Gohr 25807993756SAndreas Gohr // use field label if no header was set 25907993756SAndreas Gohr if (blank($header)) { 26001f8b845SAndreas Gohr if (is_a($column, 'dokuwiki\plugin\struct\meta\Column')) { 26107993756SAndreas Gohr $header = $column->getTranslatedLabel(); 26207993756SAndreas Gohr } else { 26307993756SAndreas Gohr $header = 'column ' . $num; // this should never happen 26407993756SAndreas Gohr } 26507993756SAndreas Gohr } 26607993756SAndreas Gohr 26707993756SAndreas Gohr // simple mode first 26807993756SAndreas Gohr if ($this->mode != 'xhtml') { 26907993756SAndreas Gohr $this->renderer->tableheader_open(); 27007993756SAndreas Gohr $this->renderer->cdata($header); 27107993756SAndreas Gohr $this->renderer->tableheader_close(); 27207993756SAndreas Gohr continue; 27307993756SAndreas Gohr } 27407993756SAndreas Gohr 27507993756SAndreas Gohr // still here? create custom header for more flexibility 27607993756SAndreas Gohr 2779113d04aSAndreas Gohr // width setting, widths are prevalidated, no escape needed 27807993756SAndreas Gohr $width = ''; 2799113d04aSAndreas Gohr if (isset($this->data['widths'][$num]) && $this->data['widths'][$num] != '-') { 2809113d04aSAndreas Gohr $width = ' style="min-width: ' . $this->data['widths'][$num] . ';' . 2819113d04aSAndreas Gohr 'max-width: ' . $this->data['widths'][$num] . ';"'; 28207993756SAndreas Gohr } 28307993756SAndreas Gohr 284d4b5a17cSAndreas Gohr // prepare data attribute for inline edits 285d6d97f60SAnna Dabrowska if ( 286d6d97f60SAnna Dabrowska !is_a($column, '\dokuwiki\plugin\struct\meta\PageColumn') && 287d4b5a17cSAndreas Gohr !is_a($column, '\dokuwiki\plugin\struct\meta\RevisionColumn') 288d4b5a17cSAndreas Gohr ) { 289d4b5a17cSAndreas Gohr $data = 'data-field="' . hsc($column->getFullQualifiedLabel()) . '"'; 290d4b5a17cSAndreas Gohr } else { 291d4b5a17cSAndreas Gohr $data = ''; 292d4b5a17cSAndreas Gohr } 293d4b5a17cSAndreas Gohr 29407993756SAndreas Gohr // sort indicator and link 29507993756SAndreas Gohr $sortclass = ''; 29607993756SAndreas Gohr $sorts = $this->searchConfig->getSorts(); 29707993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 298aa124708SAndreas Gohr $dynamic->setSort($column, true); 29907993756SAndreas Gohr if (isset($sorts[$column->getFullQualifiedLabel()])) { 300aa124708SAndreas Gohr list(/*colname*/, $currentSort) = $sorts[$column->getFullQualifiedLabel()]; 301aa124708SAndreas Gohr if ($currentSort) { 30207993756SAndreas Gohr $sortclass = 'sort-down'; 30307993756SAndreas Gohr $dynamic->setSort($column, false); 30407993756SAndreas Gohr } else { 30507993756SAndreas Gohr $sortclass = 'sort-up'; 30607993756SAndreas Gohr } 30707993756SAndreas Gohr } 30807993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 30907993756SAndreas Gohr 31007993756SAndreas Gohr // output XHTML header 311d4b5a17cSAndreas Gohr $this->renderer->doc .= "<th $width $data>"; 31207993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="' . $sortclass . '" title="' . $this->helper->getLang('sort') . '">' . hsc($header) . '</a>'; 31307993756SAndreas Gohr $this->renderer->doc .= '</th>'; 31407993756SAndreas Gohr } 31507993756SAndreas Gohr 31607993756SAndreas Gohr $this->renderer->tablerow_close(); 31707993756SAndreas Gohr } 31807993756SAndreas Gohr 31907993756SAndreas Gohr /** 320b7e1d73bSAndreas Gohr * Is the result set currently dynamically filtered? 321b7e1d73bSAndreas Gohr * @return bool 322b7e1d73bSAndreas Gohr */ 323d6d97f60SAnna Dabrowska protected function isDynamicallyFiltered() 324d6d97f60SAnna Dabrowska { 325b7e1d73bSAndreas Gohr if ($this->mode != 'xhtml') return false; 326b7e1d73bSAndreas Gohr if (!$this->data['dynfilters']) return false; 327b7e1d73bSAndreas Gohr 328b7e1d73bSAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 329b7e1d73bSAndreas Gohr return (bool) $dynamic->getFilters(); 330b7e1d73bSAndreas Gohr } 331b7e1d73bSAndreas Gohr 332b7e1d73bSAndreas Gohr /** 33307993756SAndreas Gohr * Add input fields for dynamic filtering 33407993756SAndreas Gohr */ 335d6d97f60SAnna Dabrowska protected function renderDynamicFilters() 336d6d97f60SAnna Dabrowska { 33707993756SAndreas Gohr if ($this->mode != 'xhtml') return; 33807993756SAndreas Gohr if (!$this->data['dynfilters']) return; 3391bc467a4SMichael Grosse if (is_a($this->renderer, 'renderer_plugin_dw2pdf')) { 340e6ae02ecSMichael Grosse return; 341e6ae02ecSMichael Grosse } 3421bc467a4SMichael Grosse global $conf; 34307993756SAndreas Gohr 34407993756SAndreas Gohr $this->renderer->doc .= '<tr class="dataflt">'; 34507993756SAndreas Gohr 34607993756SAndreas Gohr // add extra column for row numbers 34707993756SAndreas Gohr if ($this->data['rownumbers']) { 34807993756SAndreas Gohr $this->renderer->doc .= '<th></th>'; 34907993756SAndreas Gohr } 35007993756SAndreas Gohr 35107993756SAndreas Gohr // each column gets a form 35207993756SAndreas Gohr foreach ($this->columns as $column) { 35307993756SAndreas Gohr $this->renderer->doc .= '<th>'; 35407993756SAndreas Gohr { 35507993756SAndreas Gohr $form = new \Doku_Form(array('method' => 'GET', 'action' => wl($this->id))); 35676195677SAndreas Gohr unset($form->_hidden['sectok']); // we don't need it here 35776195677SAndreas Gohr if (!$conf['userewrite']) $form->addHidden('id', $this->id); 35807993756SAndreas Gohr 35907993756SAndreas Gohr // current value 36007993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 36107993756SAndreas Gohr $filters = $dynamic->getFilters(); 36207993756SAndreas Gohr if (isset($filters[$column->getFullQualifiedLabel()])) { 36307993756SAndreas Gohr list(, $current) = $filters[$column->getFullQualifiedLabel()]; 36407993756SAndreas Gohr $dynamic->removeFilter($column); 36507993756SAndreas Gohr } else { 36607993756SAndreas Gohr $current = ''; 36707993756SAndreas Gohr } 36807993756SAndreas Gohr 36907993756SAndreas Gohr // Add current request params 37007993756SAndreas Gohr $params = $dynamic->getURLParameters(); 37107993756SAndreas Gohr foreach ($params as $key => $val) { 37207993756SAndreas Gohr $form->addHidden($key, $val); 37307993756SAndreas Gohr } 37407993756SAndreas Gohr 37507993756SAndreas Gohr // add input field 376db9b8745SAndreas Gohr $key = $column->getFullQualifiedLabel() . $column->getType()->getDefaultComparator(); 377d60f71efSAndreas Gohr $form->addElement(form_makeField('text', SearchConfigParameters::$PARAM_FILTER . '[' . $key . ']', $current, '')); 37807993756SAndreas Gohr $this->renderer->doc .= $form->getForm(); 37907993756SAndreas Gohr } 38007993756SAndreas Gohr $this->renderer->doc .= '</th>'; 38107993756SAndreas Gohr } 38207993756SAndreas Gohr $this->renderer->doc .= '</tr>'; 38307993756SAndreas Gohr } 38407993756SAndreas Gohr 38507993756SAndreas Gohr /** 38607993756SAndreas Gohr * Display the actual table data 38707993756SAndreas Gohr */ 388d6d97f60SAnna Dabrowska protected function renderResult() 389d6d97f60SAnna Dabrowska { 39007993756SAndreas Gohr foreach ($this->result as $rownum => $row) { 39147eb8cceSSzymon Olewniczak $data = array( 39247eb8cceSSzymon Olewniczak 'id' => $this->id, 39347eb8cceSSzymon Olewniczak 'mode' => $this->mode, 39447eb8cceSSzymon Olewniczak 'renderer' => $this->renderer, 39547eb8cceSSzymon Olewniczak 'searchConfig' => $this->searchConfig, 39647eb8cceSSzymon Olewniczak 'data' => $this->data, 39747eb8cceSSzymon Olewniczak 'rownum' => &$rownum, 39847eb8cceSSzymon Olewniczak 'row' => &$row, 39947eb8cceSSzymon Olewniczak ); 40047eb8cceSSzymon Olewniczak $evt = new \Doku_Event('PLUGIN_STRUCT_AGGREGATIONTABLE_RENDERRESULTROW', $data); 40147eb8cceSSzymon Olewniczak if ($evt->advise_before()) { 402f107f479SAndreas Gohr $this->renderResultRow($rownum, $row); 403f107f479SAndreas Gohr } 40447eb8cceSSzymon Olewniczak $evt->advise_after(); 40547eb8cceSSzymon Olewniczak } 406f107f479SAndreas Gohr } 407f107f479SAndreas Gohr 408f107f479SAndreas Gohr /** 409f107f479SAndreas Gohr * Render a single result row 410f107f479SAndreas Gohr * 411f107f479SAndreas Gohr * @param int $rownum 412f107f479SAndreas Gohr * @param array $row 413f107f479SAndreas Gohr */ 414d6d97f60SAnna Dabrowska protected function renderResultRow($rownum, $row) 415d6d97f60SAnna Dabrowska { 41607993756SAndreas Gohr $this->renderer->tablerow_open(); 41707993756SAndreas Gohr 418d4b5a17cSAndreas Gohr // add data attribute for inline edit 419d4b5a17cSAndreas Gohr if ($this->mode == 'xhtml') { 420d4b5a17cSAndreas Gohr $pid = $this->resultPIDs[$rownum]; 4210ceefd5cSAnna Dabrowska $rid = $this->resultRids[$rownum]; 4226fd73b4bSAnna Dabrowska $rev = $this->resultRevs[$rownum]; 423d4b5a17cSAndreas Gohr $this->renderer->doc = substr(rtrim($this->renderer->doc), 0, -1); // remove closing '>' 4246fd73b4bSAnna Dabrowska $this->renderer->doc .= ' data-pid="' . hsc($pid) . '" data-rev="' . $rev . '" data-rid="' . $rid . '">'; 425d4b5a17cSAndreas Gohr } 426d4b5a17cSAndreas Gohr 42707993756SAndreas Gohr // row number column 42834ea6e10SAnna Dabrowska if (!empty($this->data['rownumbers'])) { 42907993756SAndreas Gohr $this->renderer->tablecell_open(); 4303215aebfSSzymon Olewniczak $searchConfigConf = $this->searchConfig->getConf(); 4313215aebfSSzymon Olewniczak $this->renderer->cdata($rownum + $searchConfigConf['offset'] + 1); 43207993756SAndreas Gohr $this->renderer->tablecell_close(); 43307993756SAndreas Gohr } 43407993756SAndreas Gohr 43507993756SAndreas Gohr /** @var Value $value */ 43607993756SAndreas Gohr foreach ($row as $colnum => $value) { 43734ea6e10SAnna Dabrowska $align = isset($this->data['align'][$colnum]) ? $this->data['align'][$colnum] : null; 43834ea6e10SAnna Dabrowska $this->renderer->tablecell_open(1, $align); 43907993756SAndreas Gohr $value->render($this->renderer, $this->mode); 44007993756SAndreas Gohr $this->renderer->tablecell_close(); 44107993756SAndreas Gohr 44207993756SAndreas Gohr // summarize 44307993756SAndreas Gohr if ($this->data['summarize'] && is_numeric($value->getValue())) { 44407993756SAndreas Gohr if (!isset($this->sums[$colnum])) { 44507993756SAndreas Gohr $this->sums[$colnum] = 0; 44607993756SAndreas Gohr } 44707993756SAndreas Gohr $this->sums[$colnum] += $value->getValue(); 44807993756SAndreas Gohr } 44907993756SAndreas Gohr } 45007993756SAndreas Gohr $this->renderer->tablerow_close(); 45107993756SAndreas Gohr } 45207993756SAndreas Gohr 45307993756SAndreas Gohr /** 45407993756SAndreas Gohr * Renders an information row for when no results were found 45507993756SAndreas Gohr */ 456d6d97f60SAnna Dabrowska protected function renderEmptyResult() 457d6d97f60SAnna Dabrowska { 45807993756SAndreas Gohr $this->renderer->tablerow_open(); 45970cf6339SAndreas Gohr $this->renderer->tablecell_open(count($this->columns) + $this->data['rownumbers'], 'center'); 46007993756SAndreas Gohr $this->renderer->cdata($this->helper->getLang('none')); 46107993756SAndreas Gohr $this->renderer->tablecell_close(); 46207993756SAndreas Gohr $this->renderer->tablerow_close(); 46307993756SAndreas Gohr } 46407993756SAndreas Gohr 46507993756SAndreas Gohr /** 46607993756SAndreas Gohr * Add sums if wanted 46707993756SAndreas Gohr */ 468d6d97f60SAnna Dabrowska protected function renderSums() 469d6d97f60SAnna Dabrowska { 470d18090e8SAndreas Gohr if (empty($this->data['summarize'])) return; 47107993756SAndreas Gohr 472a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 4738925ba29SAndreas Gohr if ($this->mode == 'xhtml') { 4748925ba29SAndreas Gohr /** @noinspection PhpMethodParametersCountMismatchInspection */ 4758925ba29SAndreas Gohr $this->renderer->tablerow_open('summarize'); 4768925ba29SAndreas Gohr } else { 47707993756SAndreas Gohr $this->renderer->tablerow_open(); 4788925ba29SAndreas Gohr } 47907993756SAndreas Gohr 48007993756SAndreas Gohr if ($this->data['rownumbers']) { 4818925ba29SAndreas Gohr $this->renderer->tableheader_open(); 4828925ba29SAndreas Gohr $this->renderer->tableheader_close(); 48307993756SAndreas Gohr } 48407993756SAndreas Gohr 485aee4116bSAndreas Gohr $len = count($this->columns); 48607993756SAndreas Gohr for ($i = 0; $i < $len; $i++) { 4878925ba29SAndreas Gohr $this->renderer->tableheader_open(1, $this->data['align'][$i]); 488aee4116bSAndreas Gohr if (!empty($this->sums[$i])) { 4899b97e610SAndreas Gohr $this->renderer->cdata('∑ '); 4909b97e610SAndreas Gohr $this->columns[$i]->getType()->renderValue($this->sums[$i], $this->renderer, $this->mode); 49107993756SAndreas Gohr } else { 49207993756SAndreas Gohr if ($this->mode == 'xhtml') { 49307993756SAndreas Gohr $this->renderer->doc .= ' '; 49407993756SAndreas Gohr } 49507993756SAndreas Gohr } 4968925ba29SAndreas Gohr $this->renderer->tableheader_close(); 49707993756SAndreas Gohr } 49807993756SAndreas Gohr $this->renderer->tablerow_close(); 499a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = false; 50007993756SAndreas Gohr } 50107993756SAndreas Gohr 50207993756SAndreas Gohr /** 503986ab7e6SAndreas Gohr * Adds paging controls to the table 50407993756SAndreas Gohr */ 505d6d97f60SAnna Dabrowska protected function renderPagingControls() 506d6d97f60SAnna Dabrowska { 50707993756SAndreas Gohr if (empty($this->data['limit'])) return; 508a0bf8bb2SAndreas Gohr if ($this->mode != 'xhtml') return; 50907993756SAndreas Gohr 510a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 51107993756SAndreas Gohr $this->renderer->tablerow_open(); 5124bc1074dSMichael Grosse $this->renderer->tableheader_open((count($this->columns) + ($this->data['rownumbers'] ? 1 : 0))); 51307993756SAndreas Gohr $offset = $this->data['offset']; 51407993756SAndreas Gohr 51507993756SAndreas Gohr // prev link 51607993756SAndreas Gohr if ($offset) { 51707993756SAndreas Gohr $prev = $offset - $this->data['limit']; 51807993756SAndreas Gohr if ($prev < 0) { 51907993756SAndreas Gohr $prev = 0; 52007993756SAndreas Gohr } 52107993756SAndreas Gohr 52207993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 52307993756SAndreas Gohr $dynamic->setOffset($prev); 52407993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 52507993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="prev">' . $this->helper->getLang('prev') . '</a>'; 52607993756SAndreas Gohr } 52707993756SAndreas Gohr 52807993756SAndreas Gohr // next link 52907993756SAndreas Gohr if ($this->resultCount > $offset + $this->data['limit']) { 53007993756SAndreas Gohr $next = $offset + $this->data['limit']; 53107993756SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 53207993756SAndreas Gohr $dynamic->setOffset($next); 53307993756SAndreas Gohr $link = wl($this->id, $dynamic->getURLParameters()); 53407993756SAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="next">' . $this->helper->getLang('next') . '</a>'; 53507993756SAndreas Gohr } 53607993756SAndreas Gohr 53707993756SAndreas Gohr $this->renderer->tableheader_close(); 53807993756SAndreas Gohr $this->renderer->tablerow_close(); 539a0bf8bb2SAndreas Gohr $this->renderer->info['struct_table_meta'] = true; 54007993756SAndreas Gohr } 54109dd691aSAndreas Gohr 54209dd691aSAndreas Gohr /** 54309dd691aSAndreas Gohr * Adds CSV export controls 54409dd691aSAndreas Gohr */ 545d6d97f60SAnna Dabrowska protected function renderExportControls() 546d6d97f60SAnna Dabrowska { 54709dd691aSAndreas Gohr if ($this->mode != 'xhtml') return; 5487b240ca8SAndreas Gohr if (empty($this->data['csv'])) return; 54909dd691aSAndreas Gohr if (!$this->resultCount) return; 55009dd691aSAndreas Gohr 551c8ccdaf8SAndreas Gohr $dynamic = $this->searchConfig->getDynamicParameters(); 552c8ccdaf8SAndreas Gohr $params = $dynamic->getURLParameters(); 553c8ccdaf8SAndreas Gohr $params['hash'] = $this->renderer->info['struct_table_hash']; 554c8ccdaf8SAndreas Gohr 55509dd691aSAndreas Gohr // FIXME apply dynamic filters 556eafc109fSAndreas Gohr $link = exportlink($this->id, 'struct_csv', $params); 55709dd691aSAndreas Gohr 55809dd691aSAndreas Gohr $this->renderer->doc .= '<a href="' . $link . '" class="export mediafile mf_csv">' . $this->helper->getLang('csvexport') . '</a>'; 55909dd691aSAndreas Gohr } 56007993756SAndreas Gohr} 561