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.

sp.php.twig 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {{ "<?php" }}
  2. /**
  3. * AUTO GENERATED BY LUTICATE GENERATOR
  4. * ANY CHANGES WILL BE OVERWRITTEN
  5. */
  6. namespace {{ sp_namespace.as_it }};
  7. use Luticate\Utils\LuSpDbo;
  8. use Luticate\Utils\LuMultipleDbo;
  9. use Luticate\Utils\LuStringUtils;
  10. use Illuminate\Support\Facades\DB;
  11. class {{ sp.sp_name.camel_upper }} extends LuSpDbo {
  12. /**
  13. * @param $dam
  14. * @return \{{ sp_namespace.as_it }}\{{ sp.sp_name.camel_upper }}|null
  15. */
  16. protected static function damToDbo($dam)
  17. {
  18. if (is_null($dam))
  19. return null;
  20. $dbo = new {{ sp.sp_name.camel_upper }}();
  21. {% for arg in args.out %}
  22. $dbo->set{{ arg.name.camel_upper }}(LuStringUtils::convertJsonString($dam->{{ arg.name.as_it }}));
  23. {% endfor %}
  24. return $dbo;
  25. }
  26. {% set spcall %}{{ sp.sp_name.as_it }}({% for arg in args.in %}:{{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}){% endset %}
  27. {% set argsarray %}{% for arg in args.in %}":{{ arg.name.as_it }}" => ${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}{% endset %}
  28. /**
  29. {% for arg in args.in %}
  30. * @param ${{ arg.name.as_it }} {{ arg.data_type.php.as_it }}
  31. {% endfor %}
  32. * @return \{{ sp_namespace.as_it }}\{{ sp.sp_name.camel_upper }}{% if sp.proretset %}[]{% endif %};
  33. */
  34. public static function execute({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %})
  35. {
  36. $values = DB::select('SELECT {% for arg in args.out %}to_json(data.{{ arg.name.as_it }}) AS {{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %} FROM {{ spcall }} data', array({{ argsarray }}));
  37. {% if sp.proretset %}
  38. $dboValues = array();
  39. foreach ($values as $value)
  40. $dboValues[] = self::damToDbo($value);
  41. return $dboValues;
  42. {% else %}
  43. return self::damToDbo($values[0]);
  44. {% endif %}
  45. }
  46. {% if sp.proretset %}
  47. /**
  48. {% for arg in args.in %}
  49. * @param ${{ arg.name.as_it }} {{ arg.data_type.php.as_it }}
  50. {% endfor %}
  51. * @param $page int The page number, 0 based
  52. * @param $perPage int The number of items per page
  53. * @return \Luticate\Utils\LuMultipleDbo;
  54. */
  55. public static function getMultipleJson({% for arg in args.in %}${{ arg.name.as_it }}, {% endfor %}$page, $perPage)
  56. {
  57. $values = DB::select('SELECT (SELECT count(*) FROM {{ spcall }}) as count, (SELECT json_agg(q) FROM (SELECT * FROM {{ spcall }} OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
  58. array({{ argsarray }}, ":page" => $page, ":perPage" => $perPage));
  59. $value = $values[0];
  60. if (is_null($value->data))
  61. {
  62. $value->data = '[]';
  63. }
  64. $data = LuStringUtils::convertJsonString($value->data);
  65. return new LuMultipleDbo($value->count, $data);
  66. }
  67. {% endif %}
  68. public function jsonSerialize()
  69. {
  70. return array(
  71. {% for arg in args.out %}
  72. "{{ arg.name.camel_upper }}" => $this->_{{ arg.name.camel_lower }}{{ loop.last ? "" : "," }}
  73. {% endfor %}
  74. );
  75. }
  76. public static function jsonDeserialize($json)
  77. {
  78. $dbo = new {{ sp.sp_name.camel_upper }}();
  79. {% for arg in args.out %}
  80. if (isset($json["{{ arg.name.camel_upper }}"])) {
  81. $dbo->set{{ arg.name.camel_upper }}($json["{{ arg.name.camel_upper }}"]);
  82. }
  83. {% endfor %}
  84. return $dbo;
  85. }
  86. public static function generateSample()
  87. {
  88. $dbo = new {{ sp.sp_name.camel_upper }}();
  89. {% for arg in args.out %}
  90. $dbo->set{{ arg.name.camel_upper }}({% if arg.data_type.php.as_it == "double" %}42.42{%
  91. elseif arg.data_type.php.as_it == "integer" %}42{%
  92. elseif arg.data_type.php.as_it == "boolean" %}true{%
  93. else %}"sample string"{% endif %});
  94. {% endfor %}
  95. return $dbo;
  96. }
  97. {% for arg in args.out %}
  98. /**
  99. * @var {{ arg.data_type.php.as_it }}
  100. */
  101. protected $_{{ arg.name.camel_lower }};
  102. public function get{{ arg.name.camel_upper }}()
  103. {
  104. return $this->_{{ arg.name.camel_lower }};
  105. }
  106. public function set{{ arg.name.camel_upper }}($value)
  107. {
  108. $this->_{{ arg.name.camel_lower }} = $value;
  109. }
  110. {% endfor %}
  111. }