ClientAreaSidebarService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. if ($this->getWhmcsParamByKey('status') !== 'Active')
  87. {
  88. return;
  89. }
  90. /**
  91. * @var SidebarService $sidebarService
  92. */
  93. $sidebarService = sl("sidebar");
  94. $this->setProductId($this->hosting()->packageid);
  95. /**
  96. * product manager
  97. */
  98. $productManager = new ProductManager();
  99. $productManager->loadById($this->hosting()->packageid);
  100. /**
  101. * @var $lang \ThurData\Servers\KerioEmail\Core\Lang\Lang
  102. */
  103. $lang = sl("lang");
  104. $order = 671;
  105. foreach ($sidebarService->get() as $sidebar)
  106. {
  107. /**
  108. * @var Sidebar $sidebar
  109. */
  110. $newPanel = [
  111. 'label' => $lang->abtr($sidebar->getTitle()),
  112. 'order' => $order
  113. ];
  114. $order++;
  115. $childPanel = $this->primarySidebar->addChild($sidebar->getName(), $newPanel);
  116. foreach ($sidebar->getChildren() as $sidebarItem)
  117. {
  118. /**
  119. * @var SidebarItem $sidebarItem
  120. *
  121. * check if is enabled in configuration
  122. */
  123. if(!$productManager->isSidebarEnabled($sidebarItem->getTitle()))
  124. {
  125. continue;
  126. }
  127. /**
  128. *
  129. * add item to menu
  130. */
  131. $newItem = [
  132. 'label' => $lang->abtr($sidebarItem->getTitle()),
  133. 'uri' => str_replace('{$hostingId}', $this->getHostingId(), $sidebarItem->getHref()),
  134. 'order' => $sidebarItem->getOrder(),
  135. "current" => $sidebarItem->isActive()
  136. ];
  137. $childPanel->addChild($sidebarItem->getName(), $newItem);
  138. }
  139. }
  140. }
  141. /**
  142. * @return bool
  143. */
  144. public function isActive()
  145. {
  146. return true;
  147. }
  148. /**
  149. * @return bool
  150. */
  151. public function isSupportedModule()
  152. {
  153. return true;
  154. }
  155. }