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