SidebarTrait.php 2.8 KB

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