JobsDataTable.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /* * ********************************************************************
  3. * Proxmox Addon product developed. (Oct 12, 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\Jobs\Pages;
  20. use http\Client;
  21. use ModulesGarden\ProxmoxAddon\App\Models\Job;
  22. use ModulesGarden\ProxmoxAddon\App\Models\Whmcs\Product;
  23. use ModulesGarden\ProxmoxAddon\App\UI\Jobs\Buttons\DeleteButton;
  24. use ModulesGarden\ProxmoxAddon\App\UI\Jobs\Buttons\InfoButton;
  25. use ModulesGarden\ProxmoxAddon\App\UI\Jobs\Buttons\MassDeleteButton;
  26. use ModulesGarden\ProxmoxAddon\App\UI\Jobs\Buttons\RunButton;
  27. use ModulesGarden\ProxmoxAddon\App\UI\Jobs\Others\StatusLabel;
  28. use ModulesGarden\ProxmoxAddon\Core\Models\Whmcs\Hosting;
  29. use ModulesGarden\ProxmoxAddon\Core\UI\Interfaces\AdminArea;
  30. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\Column;
  31. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\Providers\QueryDataProvider;
  32. use ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataTable;
  33. use function ModulesGarden\ProxmoxAddon\Core\Helper\sl;
  34. /**
  35. * Description of PluginPackageDataTable
  36. *
  37. * @author Pawel Kopec <pawelk@modulesgardne.com>
  38. */
  39. class JobsDataTable extends DataTable implements AdminArea
  40. {
  41. protected function loadHtml()
  42. {
  43. $this->initIds('jobsDataTable');
  44. $this->title = null;
  45. $j = (new Job())->getTable();
  46. $h = (new Hosting)->getTable();
  47. $p = (new Product())->getTable();
  48. $this->addColumn((new Column('id'))->setOrderable('DESC'))
  49. ->addColumn((new Column('name', $p))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  50. ->addColumn((new Column('domain', $h))->setSearchable(true, Column::TYPE_STRING)->setOrderable())
  51. ->addColumn((new Column('job', $j))->setSearchable(true, 'string'))
  52. ->addColumn((new Column('status', $j))->setSearchable(true, 'string'))
  53. ->addColumn((new Column('updated_at', $j))->setSearchable(true, 'date')->setOrderable())
  54. ->addColumn((new Column('created_at', $j))->setSearchable(true, 'date')->setOrderable());
  55. }
  56. public function initContent()
  57. {
  58. $this->addActionButton(new InfoButton());
  59. $this->addActionButton(new RunButton());
  60. //delete
  61. $this->addActionButton(new DeleteButton());
  62. //mass delete
  63. $this->addMassActionButton(new MassDeleteButton());
  64. }
  65. public function replaceFieldName($key, $row)
  66. {
  67. return sprintf('<a href="configproducts.php?action=edit&id=%s">%s</a>', $row->packageid, $row->name);
  68. }
  69. public function replaceFieldDomain($key, $row)
  70. {
  71. if (!$row->domain)
  72. {
  73. return sprintf('<a href="clientsservices.php?userid=%s&id=%s">%s</a>', $row->userid, $row->hostingId, '-');
  74. }
  75. return sprintf('<a href="clientsservices.php?userid=%s&id=%s">%s</a>', $row->userid, $row->hostingId, $row->domain);
  76. }
  77. public function replaceFieldid_($key, $row)
  78. {
  79. return $row->id;
  80. }
  81. public function replaceFieldJob($key, $row)
  82. {
  83. return sl('lang')->tr($row->job);
  84. }
  85. public function replaceFieldStatus($key, $row)
  86. {
  87. if (!$row->status)
  88. {
  89. $row->status = 'pending';
  90. }
  91. $label = new StatusLabel();
  92. $label->setStatus($row->status);
  93. return $label->getHtml();
  94. }
  95. public function replaceFieldUpdated_at($key, $row)
  96. {
  97. return fromMySQLDate($row->$key, true);
  98. }
  99. public function replaceFieldCreated_at($key, $row)
  100. {
  101. return fromMySQLDate($row->$key, true);
  102. }
  103. protected function loadData()
  104. {
  105. $j = (new Job)->getTable();
  106. $h = (new Hosting)->getTable();
  107. $p = (new Product())->getTable();
  108. $query = (new Job)
  109. ->query()
  110. ->getQuery()
  111. ->leftJoin($h, "{$j}.rel_id", '=', "{$h}.id")
  112. ->leftJoin($p, "{$h}.packageid", '=', "{$p}.id")
  113. ->select("{$j}.id", "{$j}.job", "{$j}.status", "{$j}.status AS statusRaw", "{$j}.created_at", "{$j}.updated_at",
  114. "{$h}.domain", "{$h}.userid", "{$h}.server", "{$h}.packageid", "{$h}.id AS hostingId",
  115. "{$p}.name"
  116. );
  117. $dataProv = new QueryDataProvider();
  118. $dataProv->setDefaultSorting("id", 'desc');
  119. $dataProv->setData($query);
  120. $this->setDataProvider($dataProv);
  121. }
  122. }