SidebarTrait.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* * ********************************************************************
  3. * WordPress Manager product developed. (Nov 19, 2018)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar;
  20. /**
  21. * Description of SidebarTrait
  22. *
  23. * @author Pawel Kopec <pawelk@modulesgardne.com>
  24. */
  25. trait SidebarTrait
  26. {
  27. protected $order;
  28. protected $children = [];
  29. /**
  30. * @var Sidebar
  31. */
  32. protected $parent;
  33. protected $active = false;
  34. /**
  35. * Add Sidebar
  36. * @param \ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\Sidebar $sidebar
  37. * @return \ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\Sidebar
  38. */
  39. public function add($sidebar)
  40. {
  41. $this->children[$sidebar->getId()] = $sidebar;
  42. $sidebar->setParent($this);
  43. return $this;
  44. }
  45. public function getChild($id)
  46. {
  47. if (!isset($this->children[$id]))
  48. {
  49. throw new \Exception(sprintf("Sidebar %s does not exist", $id));
  50. }
  51. return $this->children[$id];
  52. }
  53. public function hasChildren()
  54. {
  55. return !empty($this->children);
  56. }
  57. public function childrenDelete($id)
  58. {
  59. if (!isset($this->children[$id]))
  60. {
  61. throw new \Exception(sprintf("Sidebar children %s does not exist", $id));
  62. }
  63. unset($this->children[$id]);
  64. }
  65. /**
  66. * @return Sidebar[]
  67. */
  68. public function getChildren()
  69. {
  70. return $this->children;
  71. }
  72. public function destroy()
  73. {
  74. unset($this->children);
  75. return $this;
  76. }
  77. public function getParent()
  78. {
  79. return $this->parent;
  80. }
  81. public function setParent($parent)
  82. {
  83. $this->parent = $parent;
  84. return $this;
  85. }
  86. public function delete()
  87. {
  88. if ($this->id)
  89. {
  90. $this->parent->childrenDelete($this->id);
  91. }
  92. }
  93. public function isActive()
  94. {
  95. return $this->active === true;
  96. }
  97. public function setActive($active)
  98. {
  99. $this->active = (boolean) $active;
  100. return $this;
  101. }
  102. public function setOrder($order)
  103. {
  104. $this->order = $order;
  105. return $this;
  106. }
  107. public function getOrder()
  108. {
  109. return $this->order;
  110. }
  111. }