| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable;
- use \ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
- /**
- * Description of Configuration
- *
- * @autor ThurData <info@thurdata.ch>
- */
- class Column
- {
- const TYPE_INT = 'int';
- const TYPE_STRING = 'string';
- const TYPE_DATE = 'date';
- protected $id;
- protected $name;
- protected $title;
- protected $rawTitle;
- protected $filter;
- protected $type = self::TYPE_STRING;
- protected $class;
- protected $orderable = false;
- protected $searchable = false;
- protected $orderableClass = '';
- protected $customJsDrawFunction = null;
- protected $tableName = null;
- public function __construct($name, $tableName = null)
- {
- $this->name = $name;
- $this->id = $name;
- $this->class = '';
- //will be taken from lang if possible
- $this->title = $name;
- if ($tableName)
- {
- $this->tableName = $tableName;
- }
- return $this;
- }
- public function setOrderable($isOrderable = true)
- {
- $allowed = [true, false, DataProvider::SORT_ASC, DataProvider::SORT_DESC];
- if (in_array($isOrderable, $allowed))
- {
- $this->orderable = $isOrderable;
- $this->orderableClass = $this->getOrderableClass($isOrderable);
- }
- return $this;
- }
- public function setSearchable($isSearchable, $type = self::TYPE_STRING)
- {
- $this->searchable = (bool)$isSearchable;
- $this->setType($type);
-
- return $this;
- }
- public function setTitle($title)
- {
- $this->title = $title;
- return $this;
- }
- public function setRawTitle($title)
- {
- $this->rawTitle = $title;
- return $this;
- }
- public function setFilter(\ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Filters $filter)
- {
- $this->filter = $filter;
- return $this;
- }
- public function setClass($className)
- {
- $this->class = $className;
- return $this;
- }
- public function setType($type)
- {
- $allowed = [self::TYPE_STRING, self::TYPE_DATE, self::TYPE_INT];
- $this->type = in_array($type, $allowed) ? $type : self::TYPE_STRING;
- return $this;
- }
- public function __get($name)
- {
- if (property_exists($this, $name))
- {
- return $this->{$name};
- }
- return null;
- }
- public function getOrderableClass($order)
- {
- if ($order === true)
- {
- return 'sorting';
- }
- $allowed = [DataProvider::SORT_ASC => 'sorting_asc', DataProvider::SORT_DESC => 'sorting_desc'];
- return $allowed[$order] ?: '';
- }
-
- public function setCustomJsDrawFunction($functionName)
- {
- $this->customJsDrawFunction = $functionName;
-
- return $this;
- }
-
- public function getCustomJsDrawFunction()
- {
- return $this->customJsDrawFunction;
- }
- public function setTableName($tableName)
- {
- if ($tableName)
- {
- $this->tableName = $tableName;
- }
- return $this;
- }
- public function getTableName()
- {
- return $this->tableName;
- }
- public function getFullName($wrapped = true)
- {
- $vWrapp = $wrapped ? '`' : '';
- if ($this->tableName)
- {
- return $vWrapp . $this->tableName . $vWrapp . '.' . $vWrapp . $this->name . $vWrapp;
- }
- return $vWrapp . $this->name . $vWrapp;
- }
- }
|