xref: /plugin/struct/meta/Column.php (revision 87fdbc6b82d3e7a1a263ca77b8909a1a130dbf1c)
1<?php
2
3namespace plugin\struct\meta;
4
5use plugin\struct\types\AbstractBaseType;
6
7/**
8 * Class Column
9 *
10 * This represents a single column within a schema and contains the configured BaseType as well as the
11 * column reference to the data table.
12 *
13 * It basically combines the information how a column's content behaves (as defines in the BaseType and its
14 * configuration) with where to find that content and adds some basic meta data (like sort or enabled)
15 *
16 * @package plugin\struct\meta
17 */
18class Column {
19
20    /** @var int fields are sorted by this value */
21    protected $sort;
22    /** @var AbstractBaseType the type of this column */
23    protected $type;
24    /** @var int the column in the datatable. columns count from 1 */
25    protected $colref;
26    /** @var bool is this column still enabled? */
27    protected $enabled=true;
28
29    /**
30     * Column constructor.
31     * @param int $sort
32     * @param AbstractBaseType $type
33     * @param int $colref
34     * @param bool $enabled
35     */
36    public function __construct($sort, AbstractBaseType $type, $colref=0, $enabled=true) {
37        $this->sort = (int) $sort;
38        $this->type = $type;
39        $this->colref = (int) $colref;
40        $this->enabled = (bool) $enabled;
41    }
42
43    /**
44     * @return int
45     */
46    public function getSort() {
47        return $this->sort;
48    }
49
50    /**
51     * @return int
52     */
53    public function getTid() {
54        return $this->type->getTid();
55    }
56
57    /**
58     * @return AbstractBaseType
59     */
60    public function getType() {
61        return $this->type;
62    }
63
64    /**
65     * @return int
66     */
67    public function getColref() {
68        return $this->colref;
69    }
70
71    /**
72     * @return boolean
73     */
74    public function isEnabled() {
75        return $this->enabled;
76    }
77
78    /**
79     * Returns a list of all available types
80     *
81     * @return array
82     */
83    static public function allTypes() {
84        $types = array();
85        $files = glob(DOKU_PLUGIN . 'struct/types/*.php');
86        foreach($files as $file) {
87            $file = basename($file, '.php');
88            if(substr($file, 0, 8) == 'Abstract') continue;
89            $types[] = $file;
90        }
91        sort($types);
92
93        return $types;
94    }
95
96}
97