TaskHistoryDataTable.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /* * ********************************************************************
  3. * ProxmoxAddon product developed. (Aug 22, 2018)
  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\ProxmoxAddon\App\UI\TaskHistory\Pages;
  20. use ModulesGarden\ProxmoxAddon as main;
  21. use ModulesGarden\ProxmoxAddon\App\UI\TaskHistory\Buttons\DeleteMassButton;
  22. use ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Hosting;
  23. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  24. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\Column;
  25. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\Providers\QueryDataProvider;
  26. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataTable;
  27. /**
  28. * Description of ServersDataTable
  29. *
  30. * @author Pawel Kopec <pawelk@modulesgardne.com>
  31. */
  32. class TaskHistoryDataTable extends DataTable implements AdminArea
  33. {
  34. public function initContent()
  35. {
  36. $this->initIds('taskHistory');
  37. $this->title = null;
  38. $this->addActionButton(new main\App\UI\TaskHistory\Buttons\DeleteButton());
  39. $this->addMassActionButton(new DeleteMassButton);
  40. }
  41. public function replaceFieldDomain($key, $row)
  42. {
  43. if ($row->domain)
  44. {
  45. return sprintf('<a href="clientsservices.php?userid=%s&id=%s"> %s</a>', $row->userid, $row->hosting_id, $row->domain);
  46. }
  47. return sprintf('<a href="clientsservices.php?userid=%s&id=%s"> %s</a>', $row->userid, $row->hosting_id, $row->hosting_id);
  48. }
  49. public function replaceFieldStatus($key, $row)
  50. {
  51. $backgroundColor = [
  52. "0" => "f89406",
  53. "1" => "46a546",
  54. "2" => "d9534f",
  55. ];
  56. $label = new main\Core\UI\Widget\Others\Label();
  57. $lang = main\Core\ServiceLocator::call('lang');
  58. $label->setMessage($lang->absoluteT('status', $row->status))
  59. ->setTitle($lang->absoluteT('status', $row->status))
  60. ->setColor('fcffff')
  61. ->setBackgroundColor($backgroundColor[$row->status]);
  62. return $label->getHtml();
  63. }
  64. public function replaceFielDstart_trime($key, $row)
  65. {
  66. return fromMySQLDate($row->last_update, true);
  67. }
  68. protected function loadHtml()
  69. {
  70. $t = (new main\App\Models\TaskHistory)->getTable();
  71. $h = (new Hosting)->getTable();
  72. $this->addColumn((new Column('id', $t))->setSearchable(true, Column::TYPE_INT)->setOrderable('DESC'))
  73. ->addColumn((new Column('domain', $h))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  74. ->addColumn((new Column('node', $t))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  75. ->addColumn((new Column('vmid', $t))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  76. ->addColumn((new Column('status', $t))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  77. ->addColumn((new Column('name', $t))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  78. ->addColumn((new Column('description', $t))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  79. ->addColumn((new Column('start_time', $t))->setSearchable(true, Column::TYPE_DATE)->setOrderable());
  80. }
  81. protected function loadData()
  82. {
  83. $t = (new main\App\Models\TaskHistory)->getTable();
  84. $h = (new Hosting)->getTable();
  85. $p = (new main\Core\Models\Whmcs\Product)->getTable();
  86. $query = (new main\App\Models\TaskHistory)
  87. ->query()
  88. ->getQuery()
  89. ->leftJoin($h, "{$t}.hosting_id", '=', "{$h}.id")
  90. ->select("{$t}.*", "{$h}.domain", "{$h}.userid");
  91. $dataProv = new QueryDataProvider();
  92. $dataProv->setDefaultSorting("id", 'DESC');
  93. $dataProv->setData($query);
  94. $this->setDataProvider($dataProv);
  95. }
  96. }