GraphData.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxVps\App\UI\Graph\Pages;
  3. use ModulesGarden\ProxmoxAddon\App\Services\ApiService;
  4. use ModulesGarden\ProxmoxAddon\App\Services\Vps\ProductService;
  5. use ModulesGarden\ProxmoxAddon\Core\Models\ModuleSettings\Model;
  6. use function ModulesGarden\Servers\ProxmoxVps\Core\Helper\sl;
  7. trait GraphData
  8. {
  9. use ProductService;
  10. use ApiService;
  11. protected $timeframe = "week";
  12. public function chartData()
  13. {
  14. $request = [
  15. "timeframe" => $this->timeframe,
  16. "cf" => "MAX",
  17. ];
  18. return $this->vm()->rrdData($request);
  19. }
  20. protected function chartOptions()
  21. {
  22. $registrationDate = new \DateTime($this->getWhmcsParamByKey('model')->registrationDate->format("Y-m-d"));
  23. $options = ['hour' => sl("lang")->tr("Hour")];
  24. $dnow = new \DateTime();
  25. $dDiff = $registrationDate->diff($dnow);
  26. if ($dDiff->days >= 1)
  27. {
  28. $options['day'] = sl("lang")->tr("Day");
  29. }
  30. if ($dDiff->days >= 7)
  31. {
  32. $options['week'] = sl("lang")->tr("Week");
  33. }
  34. if ($dDiff->days >= 30)
  35. {
  36. $options['month'] = sl("lang")->tr("Month");
  37. }
  38. if ($dDiff->y >= 1)
  39. {
  40. $options['year'] = sl("lang")->tr("year");
  41. }
  42. return $options;
  43. }
  44. protected function loadSettings()
  45. {
  46. $this->configChartsSettings = json_decode(Model::where('setting', $this->graphSettingsKey)->first()->value);
  47. if ($this->configChartsSettings)
  48. {
  49. $this->setGraphFilterInfo(null, $this->configChartsSettings->start, $this->configChartsSettings->end);
  50. }
  51. return $this;
  52. }
  53. }