11c502704SAndreas Gohr<?php 21c502704SAndreas Gohr 31c502704SAndreas Gohrnamespace plugin\struct\meta; 41c502704SAndreas Gohr 51c502704SAndreas Gohruse plugin\struct\types\AbstractBaseType; 61c502704SAndreas Gohr 71c502704SAndreas Gohr/** 81c502704SAndreas Gohr * Class Column 91c502704SAndreas Gohr * 101c502704SAndreas Gohr * This represents a single column within a schema and contains the configured BaseType as well as the 117182938bSAndreas Gohr * column reference to the data table. 127182938bSAndreas Gohr * 137182938bSAndreas Gohr * It basically combines the information how a column's content behaves (as defines in the BaseType and its 147182938bSAndreas Gohr * configuration) with where to find that content and adds some basic meta data (like sort or enabled) 151c502704SAndreas Gohr * 161c502704SAndreas Gohr * @package plugin\struct\meta 171c502704SAndreas Gohr */ 181c502704SAndreas Gohrclass Column { 191c502704SAndreas Gohr 201c502704SAndreas Gohr /** @var int fields are sorted by this value */ 211c502704SAndreas Gohr protected $sort; 221c502704SAndreas Gohr /** @var AbstractBaseType the type of this column */ 231c502704SAndreas Gohr protected $type; 241c502704SAndreas Gohr /** @var int the column in the datatable. columns count from 1 */ 251c502704SAndreas Gohr protected $colref; 261c502704SAndreas Gohr /** @var bool is this column still enabled? */ 271c502704SAndreas Gohr protected $enabled=true; 281c502704SAndreas Gohr 291c502704SAndreas Gohr /** 301c502704SAndreas Gohr * Column constructor. 311c502704SAndreas Gohr * @param int $sort 321c502704SAndreas Gohr * @param AbstractBaseType $type 331c502704SAndreas Gohr * @param int $colref 341c502704SAndreas Gohr * @param bool $enabled 351c502704SAndreas Gohr */ 36*04eb61a6SAndreas Gohr public function __construct($sort, AbstractBaseType $type, $colref=0, $enabled=true) { 371c502704SAndreas Gohr $this->sort = (int) $sort; 381c502704SAndreas Gohr $this->type = $type; 391c502704SAndreas Gohr $this->colref = (int) $colref; 401c502704SAndreas Gohr $this->enabled = (bool) $enabled; 411c502704SAndreas Gohr } 421c502704SAndreas Gohr 431c502704SAndreas Gohr /** 441c502704SAndreas Gohr * @return int 451c502704SAndreas Gohr */ 461c502704SAndreas Gohr public function getSort() { 471c502704SAndreas Gohr return $this->sort; 481c502704SAndreas Gohr } 491c502704SAndreas Gohr 501c502704SAndreas Gohr /** 511c502704SAndreas Gohr * @return int 521c502704SAndreas Gohr */ 531c502704SAndreas Gohr public function getTid() { 54*04eb61a6SAndreas Gohr return $this->type->getTid(); 551c502704SAndreas Gohr } 561c502704SAndreas Gohr 571c502704SAndreas Gohr /** 581c502704SAndreas Gohr * @return AbstractBaseType 591c502704SAndreas Gohr */ 601c502704SAndreas Gohr public function getType() { 611c502704SAndreas Gohr return $this->type; 621c502704SAndreas Gohr } 631c502704SAndreas Gohr 641c502704SAndreas Gohr /** 651c502704SAndreas Gohr * @return int 661c502704SAndreas Gohr */ 671c502704SAndreas Gohr public function getColref() { 681c502704SAndreas Gohr return $this->colref; 691c502704SAndreas Gohr } 701c502704SAndreas Gohr 711c502704SAndreas Gohr /** 721c502704SAndreas Gohr * @return boolean 731c502704SAndreas Gohr */ 741c502704SAndreas Gohr public function isEnabled() { 751c502704SAndreas Gohr return $this->enabled; 761c502704SAndreas Gohr } 771c502704SAndreas Gohr 78ae697e1fSAndreas Gohr /** 79ae697e1fSAndreas Gohr * Returns a list of all available types 80ae697e1fSAndreas Gohr * 81ae697e1fSAndreas Gohr * @return array 82ae697e1fSAndreas Gohr */ 83ae697e1fSAndreas Gohr static public function allTypes() { 84ae697e1fSAndreas Gohr $types = array(); 85ae697e1fSAndreas Gohr $files = glob(DOKU_PLUGIN . 'struct/types/*.php'); 86ae697e1fSAndreas Gohr foreach($files as $file) { 87ae697e1fSAndreas Gohr $file = basename($file, '.php'); 88ae697e1fSAndreas Gohr if(substr($file, 0, 8) == 'Abstract') continue; 89ae697e1fSAndreas Gohr $types[] = $file; 90ae697e1fSAndreas Gohr } 91ae697e1fSAndreas Gohr sort($types); 921c502704SAndreas Gohr 93ae697e1fSAndreas Gohr return $types; 94ae697e1fSAndreas Gohr } 951c502704SAndreas Gohr 961c502704SAndreas Gohr} 97