1<?php
2
3namespace dokuwiki\plugin\struct\meta;
4
5use dokuwiki\plugin\struct\types\AbstractBaseType;
6use dokuwiki\plugin\struct\types\Page;
7
8/**
9 * Class PageColumn
10 *
11 * Just like a column, but does not reference one of the col* data columns but the pid column.
12 *
13 * @package dokuwiki\plugin\struct\meta
14 */
15class PageColumn extends Column
16{
17
18    /**
19     * PageColumn constructor.
20     *
21     * @param int $sort
22     * @param PageMeta $type
23     * @param string $table
24     */
25    public function __construct($sort, Page $type, $table = '')
26    {
27        if ($type->isMulti()) throw new StructException('PageColumns can not be multi value types!');
28        parent::__construct($sort, $type, 0, true, $table);
29    }
30
31    public function getColref()
32    {
33        throw new StructException('Accessing the colref of a PageColumn makes no sense');
34    }
35
36    /**
37     * @param bool $enforceSingleColumn ignored
38     * @return string
39     */
40    public function getColName($enforceSingleColumn = true)
41    {
42        return 'pid';
43    }
44
45    /**
46     * @param bool $enforceSingleColumn ignored
47     * @return string
48     */
49    public function getFullColName($enforceSingleColumn = true)
50    {
51        $col = $this->getColName($enforceSingleColumn);
52        if ($this->table) $col = 'data_' . $this->table . '.' . $col;
53        return $col;
54    }
55
56    /**
57     * @return string always '%pageid%'
58     */
59    public function getLabel()
60    {
61        $conf = $this->getType()->getConfig();
62        if ($conf['usetitles']) {
63            return '%title%';
64        } else {
65            return '%pageid%';
66        }
67    }
68
69    /**
70     * @return string always '%pageid%'
71     */
72    public function getFullQualifiedLabel()
73    {
74        // There is only one pageid for each row because we JOIN on it
75        // so we do not prefix it with the table
76        return $this->getLabel();
77    }
78
79    /**
80     * @return string preconfigured label
81     */
82    public function getTranslatedLabel()
83    {
84        /** @var \helper_plugin_struct_config $helper */
85        $helper = plugin_load('helper', 'struct_config');
86        return $helper->getLang('pagelabel');
87    }
88}
89