IpAddressDataTable.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxVPS Product developed. (26.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\Servers\ProxmoxCloudVps\App\UI\IpAddress\Pages;
  20. use ModulesGarden\ProxmoxAddon\App\Models\VmIpAddress;
  21. use ModulesGarden\ProxmoxAddon\App\Models\VmModel;
  22. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\IpAddress\Buttons\CreateButton;
  23. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\IpAddress\Buttons\DeleteButton;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\AdminArea;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\QueryDataProvider;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataTable;
  29. use function ModulesGarden\Servers\ProxmoxCloudVps\Core\Helper\isAdmin;
  30. class IpAddressDataTable extends DataTable implements ClientArea, AdminArea
  31. {
  32. protected $id = 'ipAddressDataTable';
  33. protected $name = 'ipAddressDataTable';
  34. protected $title = 'ipAddressDataTable';
  35. public function initContent()
  36. {
  37. $this->addClass('lu-text-left')
  38. ->addClass('lu-col-md-12');
  39. if (isAdmin())
  40. {
  41. $this->addButton(new CreateButton());
  42. $this->addActionButton(new DeleteButton());
  43. }
  44. else
  45. {
  46. $this->unsetShowTitle();
  47. }
  48. }
  49. protected function loadHtml()
  50. {
  51. if (isAdmin())
  52. {
  53. $this->addColumn((new Column('vmid')));
  54. }
  55. $this->addColumn((new Column('ip')))
  56. ->addColumn((new Column('mac_address')))
  57. ->addColumn((new Column('subnet_mask')))
  58. ->addColumn((new Column('gateway')));
  59. }
  60. public function replaceFieldMac_address($key, $row)
  61. {
  62. return $row->{$key} ? $row->{$key} : '-';
  63. }
  64. public function replaceFieldSubnet_mask($key, $row)
  65. {
  66. return $row->{$key} ? $row->{$key} : '-';
  67. }
  68. public function replaceFieldGateway($key, $row)
  69. {
  70. return $row->{$key} ? $row->{$key} : '-';
  71. }
  72. public function replaceFieldVmid($key, $row)
  73. {
  74. return $row->{$key} ? $row->{$key} : '-';
  75. }
  76. protected function loadData()
  77. {
  78. $vm = (new VmModel())->getTable();
  79. $i = (new VmIpAddress)->getTable();
  80. $query = VmIpAddress::select("{$vm}.vmid", "{$i}.id", "{$i}.ip", "{$i}.mac_address", "{$i}.subnet_mask", "{$i}.gateway")
  81. ->leftJoin($vm,"{$vm}.id", "=", "{$i}.vm_id")
  82. ->where("{$i}.hosting_id", $this->getWhmcsParamByKey('serviceid'));
  83. $query = $query->getQuery();
  84. $dataProv = new QueryDataProvider();
  85. $dataProv->setDefaultSorting("ip", 'ASC');
  86. $dataProv->setData($query);
  87. $this->setDataProvider($dataProv);
  88. }
  89. public function isViewFooter()
  90. {
  91. return false;
  92. }
  93. public function isViewTopBody()
  94. {
  95. return false;
  96. }
  97. }