UserDataTable.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\ProxmoxVps\App\UI\Admin\User\Pages;
  20. use MGProvision\Proxmox\v2\models\User;
  21. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  22. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Vps\UserService;
  24. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Interfaces\AdminArea;
  25. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\Column;
  26. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  27. use ModulesGarden\Servers\ProxmoxVps\Core\UI\Widget\DataTable\DataTable;
  28. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  29. class UserDataTable extends DataTable implements AdminArea
  30. {
  31. use ProductService;
  32. use UserService;
  33. use ApiService;
  34. protected $id = 'userDataTable';
  35. protected $title = 'userDataTable';
  36. protected $searchable = false;
  37. protected $tableLength = "100";
  38. protected function loadHtml()
  39. {
  40. $this->addColumn((new Column('username')))
  41. ->addColumn((new Column('realm')))
  42. ->addColumn((new Column('password')))
  43. ->addColumn((new Column('enable')))
  44. ->addColumn((new Column('expire')))
  45. ->addColumn((new Column('name')))
  46. ->addColumn((new Column('comment')));
  47. }
  48. public function replaceFieldExpire($key, $row)
  49. {
  50. if ($row[$key] == 0)
  51. {
  52. return sl("lang")->tr("Never");
  53. }
  54. return $row[$key];
  55. }
  56. public function replaceFieldEnable($key, $row)
  57. {
  58. if ($row[$key])
  59. {
  60. return '<span class="lu-label lu-label--success lu-label--status">' . sl('lang')->tr("Yes") . '</span>';
  61. }
  62. return '<span class="lu-label lu-label--danger lu-label--status">' . sl('lang')->tr("No") . '</span>';
  63. }
  64. protected function loadData()
  65. {
  66. $data = [];
  67. if ($this->isUser())
  68. {
  69. $user = $this->getUser();
  70. $userService = new User("{$user->username}@{$user->realm}");
  71. $userService->setApi($this->api());
  72. $configuration = $userService->configuration();
  73. $data[] = [
  74. 'username' => $user->username,
  75. 'password' => $user->getPassword(),
  76. 'realm' => $user->realm,
  77. 'enable' => $configuration['enable'],
  78. 'expire' => $configuration['expire'],
  79. 'name' => $configuration['firstname'] . " " . $configuration['lastname'],
  80. 'comment' => $configuration['comment'],
  81. ];
  82. }
  83. $dataProv = new ArrayDataProvider();
  84. $dataProv->setData($data);
  85. $this->setDataProvider($dataProv);
  86. }
  87. public function initContent()
  88. {
  89. }
  90. public function isViewFooter()
  91. {
  92. return false;
  93. }
  94. public function isViewTopBody()
  95. {
  96. return false;
  97. }
  98. }