BackupDataTable.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\Backup\Pages;
  20. use MGProvision\Proxmox\v2\repository\FileRepository;
  21. use ModulesGarden\ProxmoxAddon\App\Libs\Format;
  22. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  23. use ModulesGarden\ProxmoxAddon\App\Services\Cloud\ProductService;
  24. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Backup\Buttons\CreateButton;
  25. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Backup\Buttons\DeleteButton;
  26. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Backup\Buttons\DeleteMassButton;
  27. use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Backup\Buttons\RestoreButton;
  28. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Interfaces\ClientArea;
  29. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\Column;
  30. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataProviders\Providers\ArrayDataProvider;
  31. use ModulesGarden\Servers\ProxmoxCloudVps\Core\UI\Widget\DataTable\DataTable;
  32. class BackupDataTable extends DataTable implements ClientArea
  33. {
  34. use ProductService, ApiService;
  35. protected $id = 'backupDataTable';
  36. protected $name = 'backupDataTableName';
  37. protected $title = 'backupDataTableTitle';
  38. public function isRawTitle()
  39. {
  40. return false;
  41. }
  42. public function initContent()
  43. {
  44. //Create
  45. $createButton = new CreateButton();
  46. $createButton->addClass("pmCreateBackupButton");
  47. if (!$this->resourceGuard()->hasBackupLimit())
  48. {
  49. $createButton->addClass("hidden");
  50. }
  51. $this->unsetShowTitle();
  52. if ($this->configuration()->isPermissionBackup())
  53. {
  54. $this->addButton($createButton);
  55. }
  56. //Restore
  57. $this->addActionButton(new RestoreButton());
  58. //Delete
  59. $this->addActionButton(new DeleteButton());
  60. //Delete Mass
  61. $this->addMassActionButton(new DeleteMassButton());
  62. }
  63. protected function loadHtml()
  64. {
  65. $this->addColumn((new Column('date'))->setSearchable(true, "date")->setOrderable('DESC'))
  66. ->addColumn((new Column('format'))->setSearchable(true)->setOrderable())
  67. ->addColumn((new Column('size'))->setSearchable(true)->setOrderable());
  68. }
  69. protected function loadData()
  70. {
  71. $vm = \ModulesGarden\ProxmoxAddon\Core\Helper\sl('Vm')->getVm();
  72. $backupRepository = new FileRepository();
  73. $backupRepository->setApi($this->api());
  74. $backupRepository->findBackup($vm)
  75. ->findByStorages([$this->configuration()->getBackupStorage()]);
  76. $data = [];
  77. foreach ($backupRepository->fetch() as $file)
  78. {
  79. $row = $file->getAttributes();
  80. $row['size'] = Format::convertBytes($row['size']);
  81. $row['date'] = $row['date'] . " " . $row['hour'];
  82. $data[] = array_merge(['id' => base64_encode(json_encode($row))], $row);
  83. }
  84. $dataProv = new ArrayDataProvider();
  85. $dataProv->setDefaultSorting("date", 'DESC');
  86. $dataProv->setData($data);
  87. $this->setDataProvider($dataProv);
  88. }
  89. }