xref: /plugin/struct/meta/PageColumn.php (revision d6d97f6064c3b0f90310be8341edc9585520ee54)
10561158fSAndreas Gohr<?php
20561158fSAndreas Gohr
3ba766201SAndreas Gohrnamespace dokuwiki\plugin\struct\meta;
40561158fSAndreas Gohr
5ba766201SAndreas Gohruse dokuwiki\plugin\struct\types\AbstractBaseType;
6918ccc27SAndreas Gohruse dokuwiki\plugin\struct\types\Page;
70561158fSAndreas Gohr
80561158fSAndreas Gohr/**
90561158fSAndreas Gohr * Class PageColumn
100561158fSAndreas Gohr *
110561158fSAndreas Gohr * Just like a column, but does not reference one of the col* data columns but the pid column.
120561158fSAndreas Gohr *
13ba766201SAndreas Gohr * @package dokuwiki\plugin\struct\meta
140561158fSAndreas Gohr */
15*d6d97f60SAnna Dabrowskaclass PageColumn extends Column
16*d6d97f60SAnna Dabrowska{
170561158fSAndreas Gohr
180561158fSAndreas Gohr    /**
190561158fSAndreas Gohr     * PageColumn constructor.
200561158fSAndreas Gohr     *
210561158fSAndreas Gohr     * @param int $sort
223aad9612SMichael Grosse     * @param PageMeta $type
230561158fSAndreas Gohr     * @param string $table
240561158fSAndreas Gohr     */
25*d6d97f60SAnna Dabrowska    public function __construct($sort, Page $type, $table = '')
26*d6d97f60SAnna Dabrowska    {
275b2d2a8cSAndreas Gohr        if ($type->isMulti()) throw new StructException('PageColumns can not be multi value types!');
280561158fSAndreas Gohr        parent::__construct($sort, $type, 0, true, $table);
290561158fSAndreas Gohr    }
300561158fSAndreas Gohr
31*d6d97f60SAnna Dabrowska    public function getColref()
32*d6d97f60SAnna Dabrowska    {
330561158fSAndreas Gohr        throw new StructException('Accessing the colref of a PageColumn makes no sense');
340561158fSAndreas Gohr    }
350561158fSAndreas Gohr
36d1b04e89SAndreas Gohr    /**
375a11127fSAndreas Gohr     * @param bool $enforceSingleColumn ignored
38d1b04e89SAndreas Gohr     * @return string
39d1b04e89SAndreas Gohr     */
40*d6d97f60SAnna Dabrowska    public function getColName($enforceSingleColumn = true)
41*d6d97f60SAnna Dabrowska    {
4227f6439fSAndreas Gohr        return 'pid';
4327f6439fSAndreas Gohr    }
4427f6439fSAndreas Gohr
4527f6439fSAndreas Gohr    /**
465a11127fSAndreas Gohr     * @param bool $enforceSingleColumn ignored
4727f6439fSAndreas Gohr     * @return string
4827f6439fSAndreas Gohr     */
49*d6d97f60SAnna Dabrowska    public function getFullColName($enforceSingleColumn = true)
50*d6d97f60SAnna Dabrowska    {
515a11127fSAndreas Gohr        $col = $this->getColName($enforceSingleColumn);
525b2d2a8cSAndreas Gohr        if ($this->table) $col = 'data_' . $this->table . '.' . $col;
53d1b04e89SAndreas Gohr        return $col;
54d1b04e89SAndreas Gohr    }
55d1b04e89SAndreas Gohr
569447008bSAndreas Gohr    /**
579447008bSAndreas Gohr     * @return string always '%pageid%'
589447008bSAndreas Gohr     */
59*d6d97f60SAnna Dabrowska    public function getLabel()
60*d6d97f60SAnna Dabrowska    {
61db7315f6SAndreas Gohr        $conf = $this->getType()->getConfig();
62db7315f6SAndreas Gohr        if ($conf['usetitles']) {
63db7315f6SAndreas Gohr            return '%title%';
64db7315f6SAndreas Gohr        } else {
659447008bSAndreas Gohr            return '%pageid%';
669447008bSAndreas Gohr        }
67db7315f6SAndreas Gohr    }
689447008bSAndreas Gohr
69c74e0e40SAndreas Gohr    /**
70c74e0e40SAndreas Gohr     * @return string always '%pageid%'
71c74e0e40SAndreas Gohr     */
72*d6d97f60SAnna Dabrowska    public function getFullQualifiedLabel()
73*d6d97f60SAnna Dabrowska    {
74c74e0e40SAndreas Gohr        // There is only one pageid for each row because we JOIN on it
75c74e0e40SAndreas Gohr        // so we do not prefix it with the table
76db7315f6SAndreas Gohr        return $this->getLabel();
77c74e0e40SAndreas Gohr    }
78c74e0e40SAndreas Gohr
7901f8b845SAndreas Gohr    /**
8001f8b845SAndreas Gohr     * @return string preconfigured label
8101f8b845SAndreas Gohr     */
82*d6d97f60SAnna Dabrowska    public function getTranslatedLabel()
83*d6d97f60SAnna Dabrowska    {
8401f8b845SAndreas Gohr        /** @var \helper_plugin_struct_config $helper */
8501f8b845SAndreas Gohr        $helper = plugin_load('helper', 'struct_config');
8601f8b845SAndreas Gohr        return $helper->getLang('pagelabel');
8701f8b845SAndreas Gohr    }
880561158fSAndreas Gohr}
89