1d90aa848SAndreas Gohr<?php 2d90aa848SAndreas Gohr 3d90aa848SAndreas Gohrnamespace dokuwiki\plugin\struct\meta; 4d90aa848SAndreas Gohr 5d90aa848SAndreas Gohr/** 6d90aa848SAndreas Gohr * Base contract for Aggregations 7d90aa848SAndreas Gohr * 8d90aa848SAndreas Gohr * @package dokuwiki\plugin\struct\meta 9d90aa848SAndreas Gohr */ 1000f71f17SAndreas Gohrabstract class Aggregation 1100f71f17SAndreas Gohr{ 12d90aa848SAndreas Gohr /** @var string the page id of the page this is rendered to */ 13d90aa848SAndreas Gohr protected $id; 14d90aa848SAndreas Gohr 15d90aa848SAndreas Gohr /** @var string the Type of renderer used */ 16d90aa848SAndreas Gohr protected $mode; 17d90aa848SAndreas Gohr 18d90aa848SAndreas Gohr /** @var \Doku_Renderer the DokuWiki renderer used to create the output */ 19d90aa848SAndreas Gohr protected $renderer; 20d90aa848SAndreas Gohr 21d90aa848SAndreas Gohr /** @var SearchConfig the configured search - gives access to columns etc. */ 22d90aa848SAndreas Gohr protected $searchConfig; 23d90aa848SAndreas Gohr 24d90aa848SAndreas Gohr /** @var Column[] the list of columns to be displayed */ 25d90aa848SAndreas Gohr protected $columns; 26d90aa848SAndreas Gohr 27d90aa848SAndreas Gohr /** @var Value[][] the search result */ 28d90aa848SAndreas Gohr protected $result; 29d90aa848SAndreas Gohr 30d90aa848SAndreas Gohr /** @var int number of all results */ 31d90aa848SAndreas Gohr protected $resultCount; 32d90aa848SAndreas Gohr 33d90aa848SAndreas Gohr /** 34d90aa848SAndreas Gohr * @todo we might be able to get rid of this helper and move this to SearchConfig 35d90aa848SAndreas Gohr * @var \helper_plugin_struct_config 36d90aa848SAndreas Gohr */ 37d90aa848SAndreas Gohr protected $helper; 38d90aa848SAndreas Gohr 39d90aa848SAndreas Gohr /** 40d90aa848SAndreas Gohr * @var array the original configuration data 41d90aa848SAndreas Gohr */ 42d90aa848SAndreas Gohr protected $data; 43d90aa848SAndreas Gohr 44d90aa848SAndreas Gohr /** 45d90aa848SAndreas Gohr * Initialize the Aggregation renderer and executes the search 46d90aa848SAndreas Gohr * 47*f4dbd3b0SAndreas Gohr * You need to call startScope(), render() and finishScope() on the resulting object. 48d90aa848SAndreas Gohr * 49*f4dbd3b0SAndreas Gohr * @param string $id The page this is rendered to 50*f4dbd3b0SAndreas Gohr * @param string $mode The renderer format 51*f4dbd3b0SAndreas Gohr * @param \Doku_Renderer $renderer The renderer to use for output 52*f4dbd3b0SAndreas Gohr * @param SearchConfig $searchConfig The configured search object to use for displaying the data 53d90aa848SAndreas Gohr */ 54d90aa848SAndreas Gohr public function __construct($id, $mode, \Doku_Renderer $renderer, SearchConfig $searchConfig) 55d90aa848SAndreas Gohr { 56d90aa848SAndreas Gohr $this->id = $id; 57d90aa848SAndreas Gohr $this->mode = $mode; 58d90aa848SAndreas Gohr $this->renderer = $renderer; 59d90aa848SAndreas Gohr $this->searchConfig = $searchConfig; 60d90aa848SAndreas Gohr $this->data = $searchConfig->getConf(); 61d90aa848SAndreas Gohr $this->columns = $searchConfig->getColumns(); 62d90aa848SAndreas Gohr $this->result = $this->searchConfig->execute(); 63d90aa848SAndreas Gohr $this->resultCount = $this->searchConfig->getCount(); 64d90aa848SAndreas Gohr $this->helper = plugin_load('helper', 'struct_config'); 65d90aa848SAndreas Gohr } 66d90aa848SAndreas Gohr 67d90aa848SAndreas Gohr /** 68d90aa848SAndreas Gohr * Returns the page id the aggregation is used on 69d90aa848SAndreas Gohr */ 70d90aa848SAndreas Gohr public function getID() 71d90aa848SAndreas Gohr { 72d90aa848SAndreas Gohr return $this->id; 73d90aa848SAndreas Gohr } 74d90aa848SAndreas Gohr 75d90aa848SAndreas Gohr /** 76af0ce8d2SAndreas Gohr * Return the list of classes that should be added to the scope when rendering XHTML 77af0ce8d2SAndreas Gohr * 78af0ce8d2SAndreas Gohr * @return string[] 79af0ce8d2SAndreas Gohr */ 80af0ce8d2SAndreas Gohr public function getScopeClasses() 81af0ce8d2SAndreas Gohr { 82af0ce8d2SAndreas Gohr // we're all aggregations 83af0ce8d2SAndreas Gohr $classes = ['structaggregation']; 84af0ce8d2SAndreas Gohr 85af0ce8d2SAndreas Gohr // which type of aggregation are we? 86af0ce8d2SAndreas Gohr $class = get_class($this); 87af0ce8d2SAndreas Gohr $class = substr($class, strrpos($class, "\\") + 1); 88af0ce8d2SAndreas Gohr $class = strtolower($class); 89af0ce8d2SAndreas Gohr $classes[] = 'struct' . $class; 90af0ce8d2SAndreas Gohr 91af0ce8d2SAndreas Gohr // config options 92af0ce8d2SAndreas Gohr if ($this->data['nesting']) { 93af0ce8d2SAndreas Gohr $classes[] = 'is-nested'; 94af0ce8d2SAndreas Gohr } 95af0ce8d2SAndreas Gohr if ($this->data['index']) { 96af0ce8d2SAndreas Gohr $classes[] = 'is-indexed'; 97af0ce8d2SAndreas Gohr } 98af0ce8d2SAndreas Gohr 99af0ce8d2SAndreas Gohr // custom classes 100af0ce8d2SAndreas Gohr $classes = array_merge($classes, $this->data['classes']); 101af0ce8d2SAndreas Gohr return $classes; 102af0ce8d2SAndreas Gohr } 103af0ce8d2SAndreas Gohr 104af0ce8d2SAndreas Gohr /** 105af0ce8d2SAndreas Gohr * Render the actual output to the renderer 106d90aa848SAndreas Gohr * 107d90aa848SAndreas Gohr * @param bool $showNotFound show a not found message when no data available? 108d90aa848SAndreas Gohr */ 109d90aa848SAndreas Gohr abstract public function render($showNotFound = false); 110af0ce8d2SAndreas Gohr 111af0ce8d2SAndreas Gohr /** 112af0ce8d2SAndreas Gohr * Adds additional info to document and renderer in XHTML mode 113af0ce8d2SAndreas Gohr * 114af0ce8d2SAndreas Gohr * Called before render() 115af0ce8d2SAndreas Gohr * 116af0ce8d2SAndreas Gohr * @see finishScope() 117af0ce8d2SAndreas Gohr */ 118af0ce8d2SAndreas Gohr public function startScope() 119af0ce8d2SAndreas Gohr { 120af0ce8d2SAndreas Gohr if ($this->mode == 'xhtml') { 121af0ce8d2SAndreas Gohr $classes = $this->getScopeClasses(); 122af0ce8d2SAndreas Gohr $this->renderer->doc .= '<div class="' . join(' ', $classes) . '">'; 123af0ce8d2SAndreas Gohr } 124af0ce8d2SAndreas Gohr } 125af0ce8d2SAndreas Gohr 126af0ce8d2SAndreas Gohr /** 127af0ce8d2SAndreas Gohr * Closes anything opened in startScope() 128af0ce8d2SAndreas Gohr * 129af0ce8d2SAndreas Gohr * Called after render() 130af0ce8d2SAndreas Gohr * 131af0ce8d2SAndreas Gohr * @see startScope() 132af0ce8d2SAndreas Gohr */ 133af0ce8d2SAndreas Gohr public function finishScope() 134af0ce8d2SAndreas Gohr { 135af0ce8d2SAndreas Gohr if ($this->mode == 'xhtml') { 136af0ce8d2SAndreas Gohr $this->renderer->doc .= '</div>'; 137af0ce8d2SAndreas Gohr } 138af0ce8d2SAndreas Gohr } 139d90aa848SAndreas Gohr} 140