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