xref: /plugin/struct/types/Text.php (revision 8824339dfb9d3e3672bb1214601296a5f483eeb4)
1<?php
2namespace dokuwiki\plugin\struct\types;
3
4use dokuwiki\plugin\struct\meta\QueryBuilder;
5
6class Text extends AbstractMultiBaseType {
7
8    protected $config = array(
9        'prefix' => '',
10        'postfix' => '',
11    );
12
13    /**
14     * Output the stored data
15     *
16     * @param string|int $value the value stored in the database
17     * @param \Doku_Renderer $R the renderer currently used to render the data
18     * @param string $mode The mode the output is rendered in (eg. XHTML)
19     * @return bool true if $mode could be satisfied
20     */
21    public function renderValue($value, \Doku_Renderer $R, $mode) {
22        $R->cdata($this->config['prefix'] . $value . $this->config['postfix']);
23        return true;
24    }
25
26    /**
27     * Comparisons are done against the full string (including prefix/postfix)
28     *
29     * @param QueryBuilder $QB
30     * @param string $tablealias
31     * @param string $colname
32     * @param string $comp
33     * @param string $value
34     * @param string $op
35     */
36    public function filter(QueryBuilder $QB, $tablealias, $colname, $comp, $value, $op) {
37        $column = "$tablealias.$colname";
38
39        if ($this->config['prefix']) {
40            $pl = $QB->addValue($this->config['prefix']);
41            $column = "$pl || $column";
42        }
43        if ($this->config['postfix']) {
44            $pl = $QB->addValue($this->config['postfix']);
45            $column = "$column || $pl";
46        }
47
48        $pl = $QB->addValue($value);
49        $QB->filters()->where($op, "$column $comp $pl");
50    }
51
52}
53