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