EnabledField.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\UI\Admin\Custom\Fields;
  3. use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\Fields\BaseField;
  4. /**
  5. *
  6. * Created by PhpStorm.
  7. * User: Tomasz Bielecki ( tomasz.bi@thurdata.com )
  8. * Date: 12.11.19
  9. * Time: 10:49
  10. * Class EnabledField
  11. */
  12. class EnabledField extends BaseField
  13. {
  14. protected $id = 'enabledField';
  15. protected $name = 'enabledField';
  16. protected $title = 'field_enabled_';
  17. const TYPE_SUCCESS = 'success';
  18. const TYPE_DEFAULT = 'default';
  19. protected $enabled = false;
  20. protected $rawType = false;
  21. /**
  22. * @return bool
  23. */
  24. public function isEnabled()
  25. {
  26. return $this->enabled;
  27. }
  28. /**
  29. * @param bool $enabled
  30. */
  31. public function setEnabled($enabled)
  32. {
  33. $this->enabled = $enabled;
  34. }
  35. /**
  36. * @return string
  37. */
  38. public function getType()
  39. {
  40. if($this->getRawType())
  41. {
  42. return $this->getRawType();
  43. }
  44. if($this->isEnabled())
  45. {
  46. $type = self::TYPE_SUCCESS;
  47. }else{
  48. $type = self::TYPE_DEFAULT;
  49. }
  50. return $type;
  51. }
  52. /**
  53. * @return string|null
  54. */
  55. public function getTitle()
  56. {
  57. /**
  58. * if raw return raw
  59. */
  60. if($this->titleRaw)
  61. {
  62. return $this->titleRaw;
  63. }
  64. /**
  65. * return type depending on status
  66. */
  67. if($this->isEnabled())
  68. {
  69. $title = $this->title.self::TYPE_SUCCESS;
  70. }else{
  71. $title = $this->title.self::TYPE_DEFAULT;
  72. }
  73. /**
  74. *
  75. */
  76. return $title;
  77. }
  78. /**
  79. * @return bool
  80. */
  81. public function getRawType()
  82. {
  83. return $this->rawType;
  84. }
  85. /**
  86. * @param bool $rawType
  87. */
  88. public function setRawType($rawType)
  89. {
  90. $this->rawType = $rawType;
  91. }
  92. }