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