1308cc83fSAndreas Gohr<?php 2308cc83fSAndreas Gohr 3308cc83fSAndreas Gohr/** 4308cc83fSAndreas Gohr * DokuWiki Plugin struct (Syntax Component) 5308cc83fSAndreas Gohr * 6308cc83fSAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 7308cc83fSAndreas Gohr * @author Andreas Gohr, Michael Große <dokuwiki@cosmocode.de> 8308cc83fSAndreas Gohr */ 9308cc83fSAndreas Gohr 10*7234bfb1Ssplitbrainuse dokuwiki\plugin\struct\meta\AccessTablePage; 11308cc83fSAndreas Gohruse dokuwiki\plugin\struct\meta\AggregationEditorTable; 12308cc83fSAndreas Gohr 13308cc83fSAndreas Gohrclass syntax_plugin_struct_global extends syntax_plugin_struct_table 14308cc83fSAndreas Gohr{ 15308cc83fSAndreas Gohr /** @var string which class to use for output */ 16308cc83fSAndreas Gohr protected $tableclass = AggregationEditorTable::class; 17308cc83fSAndreas Gohr 18308cc83fSAndreas Gohr /** 19308cc83fSAndreas Gohr * Connect lookup pattern to lexer. 20308cc83fSAndreas Gohr * 21308cc83fSAndreas Gohr * @param string $mode Parser mode 22308cc83fSAndreas Gohr */ 23308cc83fSAndreas Gohr public function connectTo($mode) 24308cc83fSAndreas Gohr { 25308cc83fSAndreas Gohr $this->Lexer->addSpecialPattern('----+ *struct global *-+\n.*?\n----+', $mode, 'plugin_struct_global'); 26308cc83fSAndreas Gohr 27308cc83fSAndreas Gohr // deprecated: 28308cc83fSAndreas Gohr $this->Lexer->addSpecialPattern('----+ *struct lookup *-+\n.*?\n----+', $mode, 'plugin_struct_global'); 29308cc83fSAndreas Gohr } 30308cc83fSAndreas Gohr 31308cc83fSAndreas Gohr /** 32308cc83fSAndreas Gohr * Handle matches of the struct syntax 33308cc83fSAndreas Gohr * 34308cc83fSAndreas Gohr * @param string $match The match of the syntax 35308cc83fSAndreas Gohr * @param int $state The state of the handler 36308cc83fSAndreas Gohr * @param int $pos The position in the document 37308cc83fSAndreas Gohr * @param Doku_Handler $handler The handler 38308cc83fSAndreas Gohr * @return array Data for the renderer 39308cc83fSAndreas Gohr */ 40308cc83fSAndreas Gohr public function handle($match, $state, $pos, Doku_Handler $handler) 41308cc83fSAndreas Gohr { 42308cc83fSAndreas Gohr // usual parsing 43308cc83fSAndreas Gohr $config = parent::handle($match, $state, $pos, $handler); 44308cc83fSAndreas Gohr if (is_null($config)) return null; 45308cc83fSAndreas Gohr 46308cc83fSAndreas Gohr // adjust some things for the lookup editor 4787788c7fSAnna Dabrowska $config['cols'] = $config['cols'] ?: ['*']; // optional columns definition 48308cc83fSAndreas Gohr if (isset($config['rownumbers'])) unset($config['rownumbers']); // this annoying to update dynamically 49308cc83fSAndreas Gohr return $config; 50308cc83fSAndreas Gohr } 51308cc83fSAndreas Gohr 52308cc83fSAndreas Gohr /** 53308cc83fSAndreas Gohr * Filter based on primary key columns 54308cc83fSAndreas Gohr * 55308cc83fSAndreas Gohr * @param array $config 56308cc83fSAndreas Gohr * @return array 57308cc83fSAndreas Gohr */ 58308cc83fSAndreas Gohr protected function addTypeFilter($config) 59308cc83fSAndreas Gohr { 6017a3a578SAndreas Gohr $config['filter'][] = [ 6117a3a578SAndreas Gohr '%rowid%', '!=', 62*7234bfb1Ssplitbrain (string)AccessTablePage::DEFAULT_PAGE_RID, 'AND' 6317a3a578SAndreas Gohr ]; 64308cc83fSAndreas Gohr $config['filter'][] = ['%pageid%', '=*', '^(?![\s\S])', 'AND']; 65308cc83fSAndreas Gohr $config['withpid'] = 0; // flag for the editor to distinguish data types 66308cc83fSAndreas Gohr return $config; 67308cc83fSAndreas Gohr } 68308cc83fSAndreas Gohr} 69