Column.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable;
  3. use \ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\DataProviders\DataProvider;
  4. /**
  5. * Description of Configuration
  6. *
  7. * @autor ThurData <info@thurdata.ch>
  8. */
  9. class Column
  10. {
  11. const TYPE_INT = 'int';
  12. const TYPE_STRING = 'string';
  13. const TYPE_DATE = 'date';
  14. protected $id;
  15. protected $name;
  16. protected $title;
  17. protected $rawTitle;
  18. protected $filter;
  19. protected $type = self::TYPE_STRING;
  20. protected $class;
  21. protected $orderable = false;
  22. protected $searchable = false;
  23. protected $orderableClass = '';
  24. protected $customJsDrawFunction = null;
  25. protected $tableName = null;
  26. public function __construct($name, $tableName = null)
  27. {
  28. $this->name = $name;
  29. $this->id = $name;
  30. $this->class = '';
  31. //will be taken from lang if possible
  32. $this->title = $name;
  33. if ($tableName)
  34. {
  35. $this->tableName = $tableName;
  36. }
  37. return $this;
  38. }
  39. public function setOrderable($isOrderable = true)
  40. {
  41. $allowed = [true, false, DataProvider::SORT_ASC, DataProvider::SORT_DESC];
  42. if (in_array($isOrderable, $allowed))
  43. {
  44. $this->orderable = $isOrderable;
  45. $this->orderableClass = $this->getOrderableClass($isOrderable);
  46. }
  47. return $this;
  48. }
  49. public function setSearchable($isSearchable, $type = self::TYPE_STRING)
  50. {
  51. $this->searchable = (bool)$isSearchable;
  52. $this->setType($type);
  53. return $this;
  54. }
  55. public function setTitle($title)
  56. {
  57. $this->title = $title;
  58. return $this;
  59. }
  60. public function setRawTitle($title)
  61. {
  62. $this->rawTitle = $title;
  63. return $this;
  64. }
  65. public function setFilter(\ThurData\Servers\KerioEmail\Core\UI\Widget\DataTable\Filters $filter)
  66. {
  67. $this->filter = $filter;
  68. return $this;
  69. }
  70. public function setClass($className)
  71. {
  72. $this->class = $className;
  73. return $this;
  74. }
  75. public function setType($type)
  76. {
  77. $allowed = [self::TYPE_STRING, self::TYPE_DATE, self::TYPE_INT];
  78. $this->type = in_array($type, $allowed) ? $type : self::TYPE_STRING;
  79. return $this;
  80. }
  81. public function __get($name)
  82. {
  83. if (property_exists($this, $name))
  84. {
  85. return $this->{$name};
  86. }
  87. return null;
  88. }
  89. public function getOrderableClass($order)
  90. {
  91. if ($order === true)
  92. {
  93. return 'sorting';
  94. }
  95. $allowed = [DataProvider::SORT_ASC => 'sorting_asc', DataProvider::SORT_DESC => 'sorting_desc'];
  96. return $allowed[$order] ?: '';
  97. }
  98. public function setCustomJsDrawFunction($functionName)
  99. {
  100. $this->customJsDrawFunction = $functionName;
  101. return $this;
  102. }
  103. public function getCustomJsDrawFunction()
  104. {
  105. return $this->customJsDrawFunction;
  106. }
  107. public function setTableName($tableName)
  108. {
  109. if ($tableName)
  110. {
  111. $this->tableName = $tableName;
  112. }
  113. return $this;
  114. }
  115. public function getTableName()
  116. {
  117. return $this->tableName;
  118. }
  119. public function getFullName($wrapped = true)
  120. {
  121. $vWrapp = $wrapped ? '`' : '';
  122. if ($this->tableName)
  123. {
  124. return $vWrapp . $this->tableName . $vWrapp . '.' . $vWrapp . $this->name . $vWrapp;
  125. }
  126. return $vWrapp . $this->name . $vWrapp;
  127. }
  128. }