xref: /plugin/struct/meta/PageColumn.php (revision fc26989e4442674ded604c12f445cb8ca3510cf9)
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     * PageColumn constructor.
19     *
20     * @param int $sort
21     * @param Page $type
22     * @param string $table
23     */
24    public function __construct($sort, Page $type, $table='') {
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        throw new StructException('Accessing the colref of a PageColumn makes no sense');
31    }
32
33    /**
34     * @param bool $enforceSingleColumn ignored
35     * @return string
36     */
37    public function getColName($enforceSingleColumn = true) {
38        return 'pid';
39    }
40
41    /**
42     * @param bool $enforceSingleColumn ignored
43     * @return string
44     */
45    public function getFullColName($enforceSingleColumn = true) {
46        $col = $this->getColName($enforceSingleColumn);
47        if($this->table) $col = 'data_'.$this->table.'.'.$col;
48        return $col;
49    }
50
51    /**
52     * @return string always '%pageid%'
53     */
54    public function getLabel() {
55        $conf = $this->getType()->getConfig();
56        if($conf['usetitles']) {
57            return '%title%';
58        } else {
59            return '%pageid%';
60        }
61    }
62
63    /**
64     * @return string always '%pageid%'
65     */
66    public function getFullQualifiedLabel() {
67        // There is only one pageid for each row because we JOIN on it
68        // so we do not prefix it with the table
69        return $this->getLabel();
70    }
71
72    /**
73     * @return string preconfigured label
74     */
75    public function getTranslatedLabel() {
76        /** @var \helper_plugin_struct_config $helper */
77        $helper = plugin_load('helper', 'struct_config');
78        return $helper->getLang('pagelabel');
79    }
80
81}
82