ClientAreaSidebarService.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\Cloud;
  20. use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
  21. use ModulesGarden\ProxmoxAddon\Core\UI\Traits\WhmcsParams;
  22. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\Sidebar;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\SidebarItem;
  24. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\Sidebar\SidebarService;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\Http\Client\BaseClientController;
  26. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\sl;
  27. class ClientAreaSidebarService
  28. {
  29. use HostingService;
  30. use WhmcsParams;
  31. use ProductService;
  32. use BaseClientController;
  33. /**
  34. * @var \WHMCS\View\Menu\Item
  35. */
  36. private $primarySidebar;
  37. /**
  38. * ClientAreaSidebarService constructor.
  39. * @param $hostingId
  40. */
  41. public function __construct($hostingId, \WHMCS\View\Menu\Item $primarySidebar)
  42. {
  43. $this->setHostingId($hostingId);
  44. $this->primarySidebar = $primarySidebar;
  45. }
  46. public function informationReplaceUri()
  47. {
  48. $overview = $this->primarySidebar->getChild('Service Details Overview');
  49. if (!is_a($overview, '\WHMCS\View\Menu\Item'))
  50. {
  51. return;
  52. }
  53. $panel = $overview->getChild('Information');
  54. if (!is_a($panel, '\WHMCS\View\Menu\Item'))
  55. {
  56. return;
  57. }
  58. $panel->setUri("clientarea.php?action=productdetails&id={$this->getHostingId()}");
  59. $panel->setAttributes([]);
  60. return $this;
  61. }
  62. public function serviceDetailsOverview(){
  63. if(!$this->getWhmcsParamByKey("packageid") || !$this->configuration()->isPermissionCustomTemplates()){
  64. return;
  65. }
  66. $overview = $this->primarySidebar->getChild('Service Details Overview');
  67. if (!is_a($overview, '\WHMCS\View\Menu\Item'))
  68. {
  69. return;
  70. }
  71. $order = 800;
  72. foreach ( sl("sidebar")->getSidebar('Service Details Overview')->get() as $sidebarItem)
  73. {
  74. /**
  75. * @var SidebarItem $sidebarItem
  76. */
  77. $newItem = [
  78. 'label' => sl('lang')->abtr($sidebarItem->getTitle()),
  79. 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  80. 'order' => $sidebarItem->getOrder(),
  81. "current" => $sidebarItem->isActive()
  82. ];
  83. $childOrder = $sidebarItem->getOrder();
  84. $overview->addChild($sidebarItem->getName(), $newItem);
  85. }
  86. // /**
  87. // * @var Sidebar $sidebar
  88. // */
  89. // $newPanel = [
  90. // 'label' => sl("lang")->abtr('customTemplates'),
  91. // 'order' => 6969
  92. // 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  93. // "current" => $sidebarItem->isActive()
  94. // ];
  95. // $childPanel = $this->primarySidebar->addChild('customTemplates', $newPanel);
  96. }
  97. public function build()
  98. {
  99. /**
  100. * @var $sidebarService SidebarService
  101. */
  102. $sidebarService = sl("sidebar");
  103. $this->setProductId($this->hosting()->packageid);
  104. /**
  105. * @var $lang \ModulesGarden\Servers\ProxmoxVps\Core\Lang\Lang
  106. */
  107. $lang = sl("lang");
  108. $request = sl('request');
  109. $order = 671;
  110. $vmUrl = 'clientarea.php?action=productdetails&id={$hostingId}&modop=custom&a=management&mg-page=vm&vm={$vmId}';
  111. /**
  112. * virtualMachines
  113. */
  114. foreach ($sidebarService->get() as $sidebar)
  115. {
  116. if($sidebar->getName()=='Service Details Overview'){
  117. continue;
  118. }
  119. /**
  120. * @var Sidebar $sidebar
  121. */
  122. $newPanel = [
  123. 'label' => $lang->abtr($sidebar->getTitle()),
  124. 'order' => $order
  125. ];
  126. $order++;
  127. $childPanel = $this->primarySidebar->addChild($sidebar->getName(), $newPanel);
  128. foreach ($sidebar->getChildren() as $sidebarItem)
  129. {
  130. /**
  131. * @var SidebarItem $sidebarItem
  132. */
  133. $newItem = [
  134. 'label' => $lang->abtr($sidebarItem->getTitle()),
  135. 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  136. 'order' => $sidebarItem->getOrder(),
  137. "current" => $sidebarItem->isActive()
  138. ];
  139. $childOrder = $sidebarItem->getOrder();
  140. $childPanel->addChild($sidebarItem->getName(), $newItem);
  141. }
  142. /**
  143. * @var VmModel $vmModel
  144. */
  145. foreach (VmModel::ofHostingId( $this->getHostingId())->notVmid(0)->notTemplate()->get() as $vmModel){
  146. $childOrder++;
  147. $newItem = [
  148. 'label' => $vmModel->name,
  149. 'uri' => str_replace(['{$hostingId}', '{$vmId}'], [$this->getHostingId(),$vmModel->id], $vmUrl),
  150. 'order' => $childOrder,
  151. "current" => $request->get('vm')==$vmModel->id
  152. ];
  153. $childPanel->addChild($vmModel->name, $newItem);
  154. }
  155. }
  156. }
  157. }