1<?php
2
3/**
4 * DokuWiki Plugin struct (Syntax Component)
5 *
6 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
7 * @author  Andreas Gohr, Michael Große <dokuwiki@cosmocode.de>
8 */
9
10use dokuwiki\plugin\struct\meta\AccessTablePage;
11use dokuwiki\plugin\struct\meta\AggregationEditorTable;
12
13class syntax_plugin_struct_global extends syntax_plugin_struct_table
14{
15    /** @var string which class to use for output */
16    protected $tableclass = AggregationEditorTable::class;
17
18    /**
19     * Connect lookup pattern to lexer.
20     *
21     * @param string $mode Parser mode
22     */
23    public function connectTo($mode)
24    {
25        $this->Lexer->addSpecialPattern('----+ *struct global *-+\n.*?\n----+', $mode, 'plugin_struct_global');
26
27        // deprecated:
28        $this->Lexer->addSpecialPattern('----+ *struct lookup *-+\n.*?\n----+', $mode, 'plugin_struct_global');
29    }
30
31    /**
32     * Handle matches of the struct syntax
33     *
34     * @param string $match The match of the syntax
35     * @param int $state The state of the handler
36     * @param int $pos The position in the document
37     * @param Doku_Handler $handler The handler
38     * @return array Data for the renderer
39     */
40    public function handle($match, $state, $pos, Doku_Handler $handler)
41    {
42        // usual parsing
43        $config = parent::handle($match, $state, $pos, $handler);
44        if (is_null($config)) return null;
45
46        // adjust some things for the lookup editor
47        $config['cols'] = $config['cols'] ?: ['*']; // optional columns definition
48        if (isset($config['rownumbers'])) unset($config['rownumbers']); // this annoying to update dynamically
49        return $config;
50    }
51
52    /**
53     * Filter based on primary key columns
54     *
55     * @param array $config
56     * @return array
57     */
58    protected function addTypeFilter($config)
59    {
60        $config['filter'][] = [
61            '%rowid%', '!=',
62            (string)AccessTablePage::DEFAULT_PAGE_RID, 'AND'
63        ];
64        $config['filter'][] = ['%pageid%', '=*', '^(?![\s\S])', 'AND'];
65        $config['withpid'] = 0; // flag for the editor to distinguish data types
66        return $config;
67    }
68}
69