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 * 47d90aa848SAndreas Gohr * You need to call @param string $id 48d90aa848SAndreas Gohr * @param string $mode 49d90aa848SAndreas Gohr * @param \Doku_Renderer $renderer 50d90aa848SAndreas Gohr * @param SearchConfig $searchConfig 51d90aa848SAndreas Gohr * @see render() on the resulting object. 52d90aa848SAndreas Gohr * 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 /** 76*af0ce8d2SAndreas Gohr * Return the list of classes that should be added to the scope when rendering XHTML 77*af0ce8d2SAndreas Gohr * 78*af0ce8d2SAndreas Gohr * @return string[] 79*af0ce8d2SAndreas Gohr */ 80*af0ce8d2SAndreas Gohr public function getScopeClasses() 81*af0ce8d2SAndreas Gohr { 82*af0ce8d2SAndreas Gohr // we're all aggregations 83*af0ce8d2SAndreas Gohr $classes = ['structaggregation']; 84*af0ce8d2SAndreas Gohr 85*af0ce8d2SAndreas Gohr // which type of aggregation are we? 86*af0ce8d2SAndreas Gohr $class = get_class($this); 87*af0ce8d2SAndreas Gohr $class = substr($class, strrpos($class, "\\") + 1); 88*af0ce8d2SAndreas Gohr $class = strtolower($class); 89*af0ce8d2SAndreas Gohr $classes[] = 'struct' . $class; 90*af0ce8d2SAndreas Gohr 91*af0ce8d2SAndreas Gohr // config options 92*af0ce8d2SAndreas Gohr if ($this->data['nesting']) { 93*af0ce8d2SAndreas Gohr $classes[] = 'is-nested'; 94*af0ce8d2SAndreas Gohr } 95*af0ce8d2SAndreas Gohr if ($this->data['index']) { 96*af0ce8d2SAndreas Gohr $classes[] = 'is-indexed'; 97*af0ce8d2SAndreas Gohr } 98*af0ce8d2SAndreas Gohr 99*af0ce8d2SAndreas Gohr // custom classes 100*af0ce8d2SAndreas Gohr $classes = array_merge($classes, $this->data['classes']); 101*af0ce8d2SAndreas Gohr return $classes; 102*af0ce8d2SAndreas Gohr } 103*af0ce8d2SAndreas Gohr 104*af0ce8d2SAndreas Gohr /** 105*af0ce8d2SAndreas 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); 110*af0ce8d2SAndreas Gohr 111*af0ce8d2SAndreas Gohr /** 112*af0ce8d2SAndreas Gohr * Adds additional info to document and renderer in XHTML mode 113*af0ce8d2SAndreas Gohr * 114*af0ce8d2SAndreas Gohr * Called before render() 115*af0ce8d2SAndreas Gohr * 116*af0ce8d2SAndreas Gohr * @see finishScope() 117*af0ce8d2SAndreas Gohr */ 118*af0ce8d2SAndreas Gohr public function startScope() 119*af0ce8d2SAndreas Gohr { 120*af0ce8d2SAndreas Gohr if ($this->mode == 'xhtml') { 121*af0ce8d2SAndreas Gohr $classes = $this->getScopeClasses(); 122*af0ce8d2SAndreas Gohr $this->renderer->doc .= '<div class="' . join(' ', $classes) . '">'; 123*af0ce8d2SAndreas Gohr } 124*af0ce8d2SAndreas Gohr } 125*af0ce8d2SAndreas Gohr 126*af0ce8d2SAndreas Gohr /** 127*af0ce8d2SAndreas Gohr * Closes anything opened in startScope() 128*af0ce8d2SAndreas Gohr * 129*af0ce8d2SAndreas Gohr * Called after render() 130*af0ce8d2SAndreas Gohr * 131*af0ce8d2SAndreas Gohr * @see startScope() 132*af0ce8d2SAndreas Gohr */ 133*af0ce8d2SAndreas Gohr public function finishScope() 134*af0ce8d2SAndreas Gohr { 135*af0ce8d2SAndreas Gohr if ($this->mode == 'xhtml') { 136*af0ce8d2SAndreas Gohr $this->renderer->doc .= '</div>'; 137*af0ce8d2SAndreas Gohr } 138*af0ce8d2SAndreas Gohr } 139d90aa848SAndreas Gohr} 140