1<?php 2 3namespace dokuwiki\plugin\struct\meta; 4 5/** 6 * Class AggregationValue 7 * 8 * @package dokuwiki\plugin\struct\meta 9 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 10 * @author Iain Hallam <iain@nineworlds.net> 11 */ 12class AggregationValue extends Aggregation 13{ 14 /** 15 * @var Column the column to be displayed 16 */ 17 protected $column; 18 19 /** @inheritdoc */ 20 public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 21 { 22 // limit to first result 23 $searchConfig->setLimit(1); 24 $searchConfig->setOffset(0); 25 26 parent::__construct($id, $mode, $renderer, $searchConfig); 27 28 $this->tagName = 'span'; 29 } 30 31 /** 32 * Create the output on the renderer 33 * 34 * @param int $showNotFound Whether to display the default text for no records 35 */ 36 public function render($showNotFound = 0) 37 { 38 // Check that we actually got a result 39 if ($this->searchConfig->getCount()) { 40 $this->renderValue($this->searchConfig->getRows()[0]); 41 // only one result 42 } elseif ($showNotFound) { 43 $this->renderer->cdata($this->helper->getLang('none')); 44 } 45 } 46 47 /** 48 * @param Value[] $resultrow 49 */ 50 protected function renderValue($resultrow) 51 { 52 foreach ($resultrow as $value) { 53 if ($value->isEmpty()) { 54 continue; 55 } 56 if ($this->mode == 'xhtml') { 57 $type = 'struct_' . strtolower($value->getColumn()->getType()->getClass()); 58 $this->renderer->doc .= '<span class="' . $type . '">'; 59 } 60 $value->render($this->renderer, $this->mode); 61 if ($this->mode == 'xhtml') { 62 $this->renderer->doc .= '</span>'; 63 } 64 } 65 } 66} 67