QueryDataProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\Providers;
  3. use \ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\DataQuery;
  4. use \ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\RawDataQuery;
  5. /**
  6. *
  7. */
  8. class QueryDataProvider extends \ModulesGarden\ProxmoxAddon\Core\UI\Widget\DataTable\DataProviders\DataProvider
  9. {
  10. private $query = null;
  11. protected $unset = false;
  12. public function unsetSort()
  13. {
  14. $this->unset = true;
  15. return $this;
  16. }
  17. public function setData($query, $params = [])
  18. {
  19. $this->query = ($query instanceof \Illuminate\Database\Query\Builder) ? new DataQuery($query) : new RawDataQuery($query, $params);
  20. if ($this->unset === false)
  21. {
  22. $this->query->setSorting($this->orderColumn, $this->orderDir);
  23. }
  24. $this->query->setLimit($this->limit);
  25. $this->query->setOffset($this->offset);
  26. $this->query->setSearch($this->toSearch);
  27. return $this;
  28. }
  29. public function getData(array $avalibleCols = [])
  30. {
  31. return $this->query->getData($avalibleCols);
  32. }
  33. public function setDefaultSorting($column, $direction)
  34. {
  35. if ((!$this->request->query->get('iSortCol_0') && !$this->request->query->get('sSortDir_0')) && $this->unset === false)
  36. {
  37. $this->setSortBy($column);
  38. $this->setSortDir($direction);
  39. if ($this->query)
  40. {
  41. $this->query->setSorting($column, $direction);
  42. }
  43. }
  44. return $this;
  45. }
  46. }