ClientAreaSidebarService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (27.03.19)
  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\App\Services\Vps;
  20. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\Sidebar;
  21. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\SidebarItem;
  22. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\SidebarService;
  23. use ModulesGarden\Servers\ProxmoxVps\App\Http\Client\BaseClientController;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Traits\WhmcsParams;
  25. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  26. class ClientAreaSidebarService
  27. {
  28. use HostingService;
  29. use WhmcsParams;
  30. use ProductService;
  31. use BaseClientController;
  32. /**
  33. * @var \WHMCS\View\Menu\Item
  34. */
  35. private $primarySidebar;
  36. /**
  37. * ClientAreaSidebarService constructor.
  38. * @param $hostingId
  39. */
  40. public function __construct($hostingId, \WHMCS\View\Menu\Item $primarySidebar)
  41. {
  42. $this->setHostingId($hostingId);
  43. $this->primarySidebar = $primarySidebar;
  44. }
  45. public function informationReplaceUri()
  46. {
  47. $overview = $this->primarySidebar->getChild('Service Details Overview');
  48. if (!is_a($overview, '\WHMCS\View\Menu\Item'))
  49. {
  50. return;
  51. }
  52. $panel = $overview->getChild('Information');
  53. if (!is_a($panel, '\WHMCS\View\Menu\Item'))
  54. {
  55. return;
  56. }
  57. $panel->setUri("clientarea.php?action=productdetails&id={$this->getHostingId()}");
  58. $panel->setAttributes([]);
  59. return $this;
  60. }
  61. public function changePasswordReplaceUri()
  62. {
  63. $actions = $this->primarySidebar->getChild('Service Details Overview');
  64. if (!is_a($actions, '\WHMCS\View\Menu\Item'))
  65. {
  66. return;
  67. }
  68. $panel = $actions->getChild('Change Password');
  69. if (!is_a($panel, '\WHMCS\View\Menu\Item'))
  70. {
  71. return;
  72. }
  73. $panel->setUri("clientarea.php?action=productdetails&id={$this->getHostingId()}#tabChangepw");
  74. $panel->setAttributes([]);
  75. return $this;
  76. }
  77. public function build()
  78. {
  79. /**
  80. * @var $sidebarService SidebarService
  81. */
  82. $sidebarService = sl("sidebar");
  83. $this->setProductId($this->hosting()->packageid);
  84. /**
  85. * @var $lang \ModulesGarden\Servers\ProxmoxVps\Core\Lang\Lang
  86. */
  87. $lang = sl("lang");
  88. $order = 671;
  89. foreach ($sidebarService->get() as $sidebar)
  90. {
  91. /**
  92. * @var Sidebar $sidebar
  93. */
  94. $newPanel = [
  95. 'label' => $lang->abtr($sidebar->getTitle()),
  96. 'order' => $order
  97. ];
  98. $order++;
  99. $childPanel = $this->primarySidebar->addChild($sidebar->getName(), $newPanel);
  100. foreach ($sidebar->getChildren() as $sidebarItem)
  101. {
  102. //acl
  103. if ($sidebarItem->getName() == "backup" && !$this->configuration()->isPermissionBackup() && !$this->configuration()->isPermissionBackupJob())
  104. {
  105. continue;
  106. }
  107. else
  108. {
  109. if ($sidebarItem->getName() != "backup" && $this->configuration()->get("permission" . ucfirst($sidebarItem->getName())) != "on")
  110. {
  111. continue;
  112. }
  113. }
  114. /**
  115. * @var SidebarItem $sidebarItem
  116. */
  117. $newItem = [
  118. 'label' => $lang->abtr($sidebarItem->getTitle()),
  119. 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  120. 'order' => $sidebarItem->getOrder(),
  121. "current" => $sidebarItem->isActive()
  122. ];
  123. $childPanel->addChild($sidebarItem->getName(), $newItem);
  124. }
  125. }
  126. }
  127. }