SidebarTrait.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. logModuleCall(
  47. 'proxmoxCloud',
  48. __FUNCTION__,
  49. $this,
  50. 'Debug',
  51. $id
  52. );
  53. if(!isset($this->children[$id])){
  54. throw new \Exception(sprintf("Sidebar %s does not exist", $id));
  55. }
  56. return $this->children[$id];
  57. }
  58. public function hasChildren(){
  59. return !empty($this->children);
  60. }
  61. public function childrenDelete($id){
  62. if(!isset($this->children[$id])){
  63. throw new \Exception(sprintf("Sidebar children %s does not exist", $id));
  64. }
  65. unset ($this->children[$id]);
  66. }
  67. /**
  68. * @return Sidebar[]
  69. */
  70. public function getChildren(){
  71. return $this->children;
  72. }
  73. public function destroy(){
  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. }