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 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\LuSpModel;
  8. use Luticate\Utils\LuMultipleDbo;
  9. use Luticate\Utils\LuStringUtils;
  10. use Illuminate\Support\Facades\DB;
  11. class {{ sp.sp_name.camel_upper }} extends LuSpModel {
  12. protected static function damToDbo($dam)
  13. {
  14. if (is_null($dam))
  15. return null;
  16. $dbo = new {{ sp.sp_name.camel_upper }}();
  17. {% for arg in args.out %}
  18. $dbo->set{{ arg.name.camel_upper }}($dam->{{ arg.name.as_it }});
  19. {% endfor %}
  20. return $dbo;
  21. }
  22. {% set spcall %}{{ sp.sp_name.as_it }}({% for arg in args.in %}:{{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}){% endset %}
  23. {% set argsarray %}{% for arg in args.in %}":{{ arg.name.as_it }}" => ${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}{% endset %}
  24. public static function execute({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %})
  25. {
  26. $values = DB::select('SELECT * FROM {{ spcall }}', array({{ argsarray }}));
  27. {% if sp.proretset %}
  28. $dboValues = array();
  29. foreach ($values as $value)
  30. $dboValues[] = self::damToDbo($value);
  31. return $dboValues;
  32. {% else %}
  33. return self::damToDbo($values[0]);
  34. {% endif %}
  35. }
  36. {% if sp.proretset %}
  37. public static function getMultipleJson({% for arg in args.in %}${{ arg.name.as_it }}, {% endfor %}$page, $perPage)
  38. {
  39. $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',
  40. array({{ argsarray }}, ":page" => $page, ":perPage" => $perPage));
  41. $value = $values[0];
  42. if (is_null($value->data))
  43. {
  44. $value->data = '[]';
  45. }
  46. $data = LuStringUtils::convertJsonString($value->data);
  47. return new LuMultipleDbo($value->count, $data);
  48. }
  49. {% endif %}
  50. {% for arg in args.out %}
  51. /**
  52. * @var {{ arg.data_type.php.as_it }}
  53. */
  54. protected $_{{ arg.name.camel_lower }};
  55. public function get{{ arg.name.camel_upper }}()
  56. {
  57. return $this->_{{ arg.name.camel_lower }};
  58. }
  59. public function set{{ arg.name.camel_upper }}($value)
  60. {
  61. $this->_{{ arg.name.camel_lower }} = $value;
  62. }
  63. {% endfor %}
  64. }