123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- {{ "<?php" }}
-
- /**
- * AUTO GENERATED BY LUTICATE GENERATOR
- * ANY CHANGES WILL BE OVERWRITTEN
- */
-
- namespace {{ sp_namespace.as_it }};
-
- use Luticate\Utils\LuSpDbo;
- use Luticate\Utils\LuMultipleDbo;
- use Luticate\Utils\LuStringUtils;
- use Illuminate\Support\Facades\DB;
-
- class {{ sp.sp_name.camel_upper }} extends LuSpDbo {
-
- /**
- * @param $dam
- * @return \{{ sp_namespace.as_it }}\{{ sp.sp_name.camel_upper }}|null
- */
- protected static function damToDbo($dam)
- {
- if (is_null($dam))
- return null;
- $dbo = new {{ sp.sp_name.camel_upper }}();
-
- {% for arg in args.out %}
- $dbo->set{{ arg.name.camel_upper }}(LuStringUtils::convertJsonString($dam->{{ arg.name.as_it }}));
- {% endfor %}
-
- return $dbo;
- }
-
- {% set spcall %}{{ sp.sp_name.as_it }}({% for arg in args.in %}:{{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}){% endset %}
- {% set argsarray %}{% for arg in args.in %}":{{ arg.name.as_it }}" => ${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %}{% endset %}
-
- /**
- {% for arg in args.in %}
- * @param ${{ arg.name.as_it }} {{ arg.data_type.php.as_it }}
- {% endfor %}
- * @return \{{ sp_namespace.as_it }}\{{ sp.sp_name.camel_upper }}{% if sp.proretset %}[]{% endif %};
- */
- public static function execute({% for arg in args.in %}${{ arg.name.as_it }}{{ loop.last ? "" : ", " }}{% endfor %})
- {
- $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 }}));
- {% if sp.proretset %}
- $dboValues = array();
- foreach ($values as $value)
- $dboValues[] = self::damToDbo($value);
- return $dboValues;
- {% else %}
- return self::damToDbo($values[0]);
- {% endif %}
- }
-
- {% if sp.proretset %}
- /**
- {% for arg in args.in %}
- * @param ${{ arg.name.as_it }} {{ arg.data_type.php.as_it }}
- {% endfor %}
- * @param $page int The page number, 0 based
- * @param $perPage int The number of items per page
- * @return \Luticate\Utils\LuMultipleDbo;
- */
- public static function getMultipleJson({% for arg in args.in %}${{ arg.name.as_it }}, {% endfor %}$page, $perPage)
- {
- $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',
- array({{ argsarray }}, ":page" => $page, ":perPage" => $perPage));
- $value = $values[0];
- if (is_null($value->data))
- {
- $value->data = '[]';
- }
- $data = LuStringUtils::convertJsonString($value->data);
- return new LuMultipleDbo($value->count, $data);
- }
- {% endif %}
-
- public function jsonSerialize()
- {
- return array(
- {% for arg in args.out %}
- "{{ arg.name.camel_upper }}" => $this->_{{ arg.name.camel_lower }}{{ loop.last ? "" : "," }}
- {% endfor %}
- );
- }
-
- public static function jsonDeserialize($json)
- {
- $dbo = new {{ sp.sp_name.camel_upper }}();
- {% for arg in args.out %}
- if (isset($json["{{ arg.name.camel_upper }}"])) {
- $dbo->set{{ arg.name.camel_upper }}($json["{{ arg.name.camel_upper }}"]);
- }
- {% endfor %}
- return $dbo;
- }
-
- public static function generateSample()
- {
- $dbo = new {{ sp.sp_name.camel_upper }}();
- {% for arg in args.out %}
- $dbo->set{{ arg.name.camel_upper }}({% if arg.data_type.php.as_it == "double" %}42.42{%
- elseif arg.data_type.php.as_it == "integer" %}42{%
- elseif arg.data_type.php.as_it == "boolean" %}true{%
- else %}"sample string"{% endif %});
- {% endfor %}
- return $dbo;
- }
-
- {% for arg in args.out %}
-
- /**
- * @var {{ arg.data_type.php.as_it }}
- */
- protected $_{{ arg.name.camel_lower }};
- public function get{{ arg.name.camel_upper }}()
- {
- return $this->_{{ arg.name.camel_lower }};
- }
- public function set{{ arg.name.camel_upper }}($value)
- {
- $this->_{{ arg.name.camel_lower }} = $value;
- }
- {% endfor %}
- }
|