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