SidebarTrait.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxCloudVps 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\Servers\ProxmoxCloudVps\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\Servers\ProxmoxCloudVps\Core\UI\Widget\Sidebar\Sidebar $sidebar
  37. * @return \ModulesGarden\Servers\ProxmoxCloudVps\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. if(!isset($this->children[$id])){
  47. throw new \Exception(sprintf("Sidebar %s does not exist", $id));
  48. }
  49. return $this->children[$id];
  50. }
  51. public function isChild($id){
  52. if(!isset($this->children[$id])){
  53. return false;
  54. }
  55. return true;
  56. }
  57. public function hasChildren(){
  58. return !empty($this->children);
  59. }
  60. public function childrenDelete($id){
  61. if(!isset($this->children[$id])){
  62. throw new \Exception(sprintf("Sidebar children %s does not exist", $id));
  63. }
  64. unset ($this->children[$id]);
  65. }
  66. /**
  67. * @return Sidebar[]
  68. */
  69. public function getChildren(){
  70. return $this->children;
  71. }
  72. public function destroy(){
  73. unset($this->children);
  74. return $this;
  75. }
  76. public function getParent()
  77. {
  78. return $this->parent;
  79. }
  80. public function setParent($parent)
  81. {
  82. $this->parent = $parent;
  83. return $this;
  84. }
  85. public function delete()
  86. {
  87. if ($this->id)
  88. {
  89. $this->parent->childrenDelete($this->id);
  90. }
  91. }
  92. public function isActive()
  93. {
  94. return $this->active===true;
  95. }
  96. public function setActive($active)
  97. {
  98. $this->active = (boolean)$active;
  99. return $this;
  100. }
  101. public function setOrder($order)
  102. {
  103. $this->order = $order;
  104. return $this;
  105. }
  106. public function getOrder()
  107. {
  108. return $this->order;
  109. }
  110. }