ClientAreaSidebarService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\App\Services;
  3. use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
  4. use ThurData\Servers\KerioEmail\App\Traits\HostingService;
  5. use ThurData\Servers\KerioEmail\App\Traits\ProductService;
  6. use function ThurData\Servers\KerioEmail\Core\Helper\sl;
  7. use ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar\Sidebar;
  8. use ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar\SidebarItem;
  9. use ThurData\Servers\KerioEmail\Core\UI\Widget\Sidebar\SidebarService;
  10. /**
  11. *
  12. * Created by PhpStorm.
  13. * User: ThurData
  14. * Date: 10.09.19
  15. * Time: 10:23
  16. * Class ClientAreaSidebarService
  17. */
  18. class ClientAreaSidebarService
  19. {
  20. const SUPPORTED_SERVER_TYPES = ['kerioEmail'];
  21. use HostingService;
  22. use \ThurData\Servers\KerioEmail\Core\UI\Traits\WhmcsParams;
  23. use ProductService;
  24. //use ProductService;
  25. //u/se BaseClientController;
  26. /**
  27. * @var \WHMCS\View\Menu\Item
  28. */
  29. private $primarySidebar;
  30. /**
  31. * ClientAreaSidebarService constructor.
  32. * @param $hostingId
  33. */
  34. public function __construct($hostingId, \WHMCS\View\Menu\Item $primarySidebar)
  35. {
  36. $this->setHostingId($hostingId);
  37. $this->primarySidebar = $primarySidebar;
  38. }
  39. /**
  40. * @return $this|void
  41. */
  42. public function informationReplaceUri()
  43. {
  44. $overview = $this->primarySidebar->getChild('Service Details Overview');
  45. if (!is_a($overview, '\WHMCS\View\Menu\Item'))
  46. {
  47. return;
  48. }
  49. $panel = $overview->getChild('Information');
  50. if (!is_a($panel, '\WHMCS\View\Menu\Item'))
  51. {
  52. return;
  53. }
  54. $panel->setUri("clientarea.php?action=productdetails&id={$this->getHostingId()}");
  55. $panel->setAttributes([]);
  56. return $this;
  57. }
  58. /**
  59. * @return $this|void
  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. /**
  78. *
  79. */
  80. public function build()
  81. {
  82. if(!in_array($this->hosting()->product->servertype, self::SUPPORTED_SERVER_TYPES))
  83. {
  84. return;
  85. }
  86. logModuleCall(
  87. 'kerioEmail',
  88. __FUNCTION__,
  89. $this->getWhmcsParamByKey('status'),
  90. 'Debug',
  91. $this->primarySidebar
  92. );
  93. /**
  94. * @var SidebarService $sidebarService
  95. */
  96. $sidebarService = sl("sidebar");
  97. $this->setProductId($this->hosting()->packageid);
  98. /**
  99. * product manager
  100. */
  101. $productManager = new ProductManager();
  102. $productManager->loadById($this->hosting()->packageid);
  103. /**
  104. * @var $lang \ThurData\Servers\ProxmoxVps\Core\Lang\Lang
  105. */
  106. $lang = sl("lang");
  107. $order = 671;
  108. foreach ($sidebarService->get() as $sidebar)
  109. {
  110. /**
  111. * @var Sidebar $sidebar
  112. */
  113. $newPanel = [
  114. 'label' => $lang->abtr($sidebar->getTitle()),
  115. 'order' => $order
  116. ];
  117. $order++;
  118. $childPanel = $this->primarySidebar->addChild($sidebar->getName(), $newPanel);
  119. foreach ($sidebar->getChildren() as $sidebarItem)
  120. {
  121. /**
  122. * @var SidebarItem $sidebarItem
  123. *
  124. * check if is enabled in configuration
  125. */
  126. if(!$productManager->isSidebarEnabled($sidebarItem->getTitle()))
  127. {
  128. continue;
  129. }
  130. /**
  131. *
  132. * add item to menu
  133. */
  134. $newItem = [
  135. 'label' => $lang->abtr($sidebarItem->getTitle()),
  136. 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  137. 'order' => $sidebarItem->getOrder(),
  138. "current" => $sidebarItem->isActive()
  139. ];
  140. $childPanel->addChild($sidebarItem->getName(), $newItem);
  141. }
  142. }
  143. }
  144. /**
  145. * @return bool
  146. */
  147. public function isActive()
  148. {
  149. return true;
  150. }
  151. /**
  152. * @return bool
  153. */
  154. public function isSupportedModule()
  155. {
  156. return true;
  157. }
  158. }