SidebarTrait.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* * ********************************************************************
  3. * KerioEmail product developed. (Nov 19, 2018)
  4. * *
  5. *
  6. * CREATED BY THURDATA -> http://thurdata.com
  7. * CONTACT -> contact@thurdata.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 ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar;
  20. /**
  21. * Description of SidebarTrait
  22. *
  23. * @autor ThurData <info@thurdata.ch>
  24. */
  25. trait SidebarTrait
  26. {
  27. protected $order;
  28. protected $targetBlank = false;
  29. protected $children = [];
  30. /**
  31. * @var Sidebar
  32. */
  33. protected $parent;
  34. protected $active=false;
  35. /**
  36. * Add Sidebar
  37. * @param \ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar\Sidebar $sidebar
  38. * @return \ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar\Sidebar
  39. */
  40. public function add( $sidebar)
  41. {
  42. $this->children[$sidebar->getId()] = $sidebar;
  43. $sidebar->setParent($this);
  44. return $this;
  45. }
  46. public function getChild($id){
  47. if(!isset($this->children[$id])){
  48. throw new \Exception(sprintf("Sidebar %s does not exist", $id));
  49. }
  50. return $this->children[$id];
  51. }
  52. public function hasChildren(){
  53. return !empty($this->children);
  54. }
  55. public function childrenDelete($id){
  56. if(!isset($this->children[$id])){
  57. throw new \Exception(sprintf("Sidebar children %s does not exist", $id));
  58. }
  59. unset ($this->children[$id]);
  60. }
  61. /**
  62. * @return Sidebar[]
  63. */
  64. public function getChildren(){
  65. return $this->children;
  66. }
  67. public function destroy(){
  68. unset($this->children);
  69. return $this;
  70. }
  71. public function getParent()
  72. {
  73. return $this->parent;
  74. }
  75. public function setParent($parent)
  76. {
  77. $this->parent = $parent;
  78. return $this;
  79. }
  80. public function delete()
  81. {
  82. if ($this->id)
  83. {
  84. $this->parent->childrenDelete($this->id);
  85. }
  86. }
  87. public function isActive()
  88. {
  89. return $this->active===true;
  90. }
  91. public function setActive($active)
  92. {
  93. $this->active = (boolean)$active;
  94. return $this;
  95. }
  96. public function setOrder($order)
  97. {
  98. $this->order = $order;
  99. return $this;
  100. }
  101. public function getOrder()
  102. {
  103. return $this->order;
  104. }
  105. }