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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $data = LuStringUtils::convertJsonString($value->data);
  43. return new LuMultipleDbo($value->count, $data);
  44. }
  45. {% endif %}
  46. {% for arg in args.out %}
  47. /**
  48. * @var {{ arg.data_type.php.as_it }}
  49. */
  50. protected $_{{ arg.name.camel_lower }};
  51. public function get{{ arg.name.camel_upper }}()
  52. {
  53. return $this->_{{ arg.name.camel_lower }};
  54. }
  55. public function set{{ arg.name.camel_upper }}($value)
  56. {
  57. $this->_{{ arg.name.camel_lower }} = $value;
  58. }
  59. {% endfor %}
  60. }