You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpGetDomainRecords.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * AUTO GENERATED BY LUTICATE GENERATOR
  4. * ANY CHANGES WILL BE OVERWRITTEN
  5. */
  6. namespace App\Http\DataAccess\SP;
  7. use Luticate\Utils\LuSpDbo;
  8. use Luticate\Utils\LuMultipleDbo;
  9. use Luticate\Utils\LuStringUtils;
  10. use Illuminate\Support\Facades\DB;
  11. class SpGetDomainRecords extends LuSpDbo {
  12. /**
  13. * @param $dam
  14. * @return \App\Http\DataAccess\SP\SpGetDomainRecords|null
  15. */
  16. protected static function damToDbo($dam)
  17. {
  18. if (is_null($dam))
  19. return null;
  20. $dbo = new SpGetDomainRecords();
  21. $dbo->setRecords(LuStringUtils::convertJsonString($dam->records));
  22. return $dbo;
  23. }
  24. /**
  25. * @param $domain_id integer
  26. * @param $query string
  27. * @return \App\Http\DataAccess\SP\SpGetDomainRecords[];
  28. */
  29. public static function execute($domain_id, $query)
  30. {
  31. $values = DB::select('SELECT to_json(data.records) AS records FROM sp_get_domain_records(:domain_id, :query) data', array(":domain_id" => $domain_id, ":query" => $query));
  32. $dboValues = array();
  33. foreach ($values as $value)
  34. $dboValues[] = self::damToDbo($value);
  35. return $dboValues;
  36. }
  37. /**
  38. * @param $domain_id integer
  39. * @param $query string
  40. * @param $page int The page number, 0 based
  41. * @param $perPage int The number of items per page
  42. * @return \Luticate\Utils\LuMultipleDbo;
  43. */
  44. public static function getMultipleJson($domain_id, $query, $page, $perPage)
  45. {
  46. $values = DB::select('SELECT (SELECT count(*) FROM sp_get_domain_records(:domain_id, :query)) as count, (SELECT json_agg(q) FROM (SELECT * FROM sp_get_domain_records(:domain_id, :query) OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
  47. array(":domain_id" => $domain_id, ":query" => $query, ":page" => $page, ":perPage" => $perPage));
  48. $value = $values[0];
  49. if (is_null($value->data))
  50. {
  51. $value->data = '[]';
  52. }
  53. $data = LuStringUtils::convertJsonString($value->data);
  54. return new LuMultipleDbo($value->count, $data);
  55. }
  56. public function jsonSerialize()
  57. {
  58. return array(
  59. "Records" => $this->_records
  60. );
  61. }
  62. public static function jsonDeserialize($json)
  63. {
  64. $dbo = new SpGetDomainRecords();
  65. if (isset($json["Records"])) {
  66. $dbo->setRecords($json["Records"]);
  67. }
  68. return $dbo;
  69. }
  70. public static function generateSample()
  71. {
  72. $dbo = new SpGetDomainRecords();
  73. $dbo->setRecords("sample string");
  74. return $dbo;
  75. }
  76. /**
  77. * @var USER-DEFINED
  78. */
  79. protected $_records;
  80. public function getRecords()
  81. {
  82. return $this->_records;
  83. }
  84. public function setRecords($value)
  85. {
  86. $this->_records = $value;
  87. }
  88. }