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