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 /** 16 * @var Column the column to be displayed 17 */ 18 protected $column; 19 20 /** @inheritdoc */ 21 public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 22 { 23 // limit to first result 24 $searchConfig->setLimit(1); 25 $searchConfig->setOffset(0); 26 27 parent::__construct($id, $mode, $renderer, $searchConfig); 28 } 29 30 /** 31 * Create the output on the renderer 32 * 33 * @param int $show_not_found Whether to display the default text for no records 34 */ 35 public function render($show_not_found = 0) 36 { 37 $this->startScope(); 38 39 // Check that we actually got a result 40 if ($this->resultCount) { 41 $this->renderValue($this->result[0]); // only one result 42 } else { 43 if ($show_not_found) { 44 $this->renderer->cdata($this->helper->getLang('none')); 45 } 46 } 47 48 $this->finishScope(); 49 } 50 51 /** 52 * Adds additional info to document and renderer in XHTML mode 53 * 54 * @see finishScope() 55 */ 56 protected function startScope() 57 { 58 // wrapping span 59 if ($this->mode != 'xhtml') { 60 return; 61 } 62 $this->renderer->doc .= "<span class=\"structaggregation valueaggregation\">"; 63 } 64 65 /** 66 * Closes anything opened in startScope() 67 * 68 * @see startScope() 69 */ 70 protected function finishScope() 71 { 72 // wrapping span 73 if ($this->mode != 'xhtml') { 74 return; 75 } 76 $this->renderer->doc .= '</span>'; 77 } 78 79 /** 80 * @param Value[] $resultrow 81 */ 82 protected function renderValue($resultrow) 83 { 84 foreach ($resultrow as $column => $value) { 85 if ($value->isEmpty()) { 86 continue; 87 } 88 if ($this->mode == 'xhtml') { 89 $type = 'struct_' . strtolower($value->getColumn()->getType()->getClass()); 90 $this->renderer->doc .= '<span class="' . $type . '">'; 91 } 92 $value->render($this->renderer, $this->mode); 93 if ($this->mode == 'xhtml') { 94 $this->renderer->doc .= '</span>'; 95 } 96 } 97 } 98} 99