Alerts.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\Core\UI\Traits;
  3. use \ModulesGarden\Servers\ProxmoxVps\Core\UI\Helpers\AlertTypesConstants;
  4. /**
  5. * Alerts related functions
  6. *
  7. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  8. */
  9. trait Alerts
  10. {
  11. protected $internalAlertMessage = null;
  12. protected $internalAlertMessageType = 'info';
  13. protected $internalAlertMessageRaw = false;
  14. protected $internalAlertSize = 'sm';
  15. public function setInternalAlertMessage($message)
  16. {
  17. if (is_string($message))
  18. {
  19. $this->internalAlertMessage = $message;
  20. }
  21. return $this;
  22. }
  23. public function getInternalAlertMessage()
  24. {
  25. return $this->internalAlertMessage;
  26. }
  27. public function setInternalAlertMessageType($type)
  28. {
  29. if (in_array($type, AlertTypesConstants::getAlertTypes()))
  30. {
  31. $this->internalAlertMessageType = $type;
  32. }
  33. return $this;
  34. }
  35. public function getInternalAlertMessageType()
  36. {
  37. return $this->internalAlertMessageType;
  38. }
  39. public function setInternalAlertMessageRaw($isRaw = false)
  40. {
  41. if (is_bool($isRaw))
  42. {
  43. $this->internalAlertMessageRaw = $isRaw;
  44. }
  45. return $this;
  46. }
  47. public function isInternalAlertMessageRaw()
  48. {
  49. return $this->internalAlertMessageRaw;
  50. }
  51. public function addInternalAlert($message = null, $type = null, $size = null, $isRaw = false)
  52. {
  53. $this->setInternalAlertMessage($message);
  54. $this->setInternalAlertMessageType($type);
  55. $this->setInternalAlertSize($size);
  56. $this->setInternalAlertMessageRaw($isRaw);
  57. return $this;
  58. }
  59. public function haveInternalAlertMessage()
  60. {
  61. return $this->internalAlertMessage !== null;
  62. }
  63. public function setInternalAlertSize($size = null)
  64. {
  65. if (in_array($size, AlertTypesConstants::getAlertSizes()))
  66. {
  67. $this->internalAlertSize = $size;
  68. }
  69. return $this;
  70. }
  71. public function getInternalAlertSize()
  72. {
  73. return $this->internalAlertSize;
  74. }
  75. }