0
1
Fork 0

Db.Model soporta actualizaciones bajo demanda, edicion de consignatarios, errores solucionados

This commit is contained in:
Juan Ferrer Toribio 2015-03-19 20:36:11 +01:00
parent d64160d891
commit 0a738a55d7
28 changed files with 911 additions and 484 deletions

View File

@ -1,5 +1,5 @@
Package: hedera-web Package: hedera-web
Version: 1.0-42 Version: 1.0-43
Architecture: all Architecture: all
Maintainer: Juan Ferrer Toribio <juan@verdnatura.es> Maintainer: Juan Ferrer Toribio <juan@verdnatura.es>
Depends: apache2, php5-mysql, php-vn-web Depends: apache2, php5-mysql, php-vn-web

View File

@ -0,0 +1,36 @@
Vn.Address = new Class
({
Extends: Vn.Module
,activate: function ()
{
this.$('return').addEventListener ('click', this.onReturnClick.bind (this));
this.$('accept').addEventListener ('click', this.onAcceptClick.bind (this));
this.$('iter').on ('status-changed', this.onStatusChange, this);
this.$('model').on ('operations-done', this.onOperationsDone, this);
}
,onStatusChange: function (form)
{
if (this.$('address').value == 0)
form.insertRow ();
}
,onOperationsDone: function ()
{
(new Htk.Toast ()).showMessage (_('ConsigneeChangedSuccessfully'));
this.onReturnClick ();
}
,onAcceptClick: function ()
{
this.$('iter').performOperations ();
}
,onReturnClick: function ()
{
window.history.back();
}
});

View File

@ -0,0 +1,31 @@
.address
{
padding: 1em;
}
.address .box
{
max-width: 40em;
}
.address .box .body
{
margin: 0 auto;
max-width: 25em;
padding: 3em;
}
div.form-group
{
padding: 0.4em;
}
.address label
{
display: block;
margin-bottom: 0.5em;
}
.address input,
.address select
{
margin: 0;
width: 100%;
}

View File

@ -0,0 +1,61 @@
<vn>
<vn-group>
<vn-param id="address">
<vn-hash-link key="address"/>
</vn-param>
<db-form id="iter">
<db-model id="model">
SELECT id, name, consignee, city, zip_code, province_id
FROM address_view
WHERE active != FALSE AND id = #address
<sql-batch property="batch">
<item name="address" param="address"/>
</sql-batch>
</db-model>
</db-form>
</vn-group>
<div id="form" class="address">
<div class="box">
<div class="header">
<h1><t>EditConsignee</t></h1>
<div class="action-bar">
<button id="return">
<img src="image/dark/go-previous.svg" alt=""/>
<t>Return</t>
</button>
<button id="accept">
<img src="image/dark/ok.svg" alt=""/>
<t>Accept</t>
</button>
</div>
</div>
<div class="body">
<div class="form-group">
<label><t>Name:</t></label>
<htk-entry column="consignee" form="iter"/>
</div>
<div class="form-group">
<label><t>Adress:</t></label>
<htk-entry column="name" form="iter"/>
</div>
<div class="form-group">
<label><t>City:</t></label>
<htk-entry column="city" form="iter"/>
</div>
<div class="form-group">
<label><t>ZipCode:</t></label>
<htk-entry column="zip_code" form="iter"/>
</div>
<div class="form-group">
<label><t>Province:</t></label>
<htk-combo column="province_id" form="iter">
<db-model property="model">
SELECT province_id, name FROM vn2008.province
ORDER BY name
</db-model>
</htk-combo>
</div>
</div>
</div>
</div>
</vn>

View File

@ -1,5 +1,5 @@
Vn.Account = new Class Vn.Conf = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
@ -13,6 +13,15 @@ Vn.Account = new Class
this.$('new-password').addEventListener ('change', this.onPasswordChange.bind (this)); this.$('new-password').addEventListener ('change', this.onPasswordChange.bind (this));
this.$('repeat-password').addEventListener ('change', this.onPasswordChange.bind (this)); this.$('repeat-password').addEventListener ('change', this.onPasswordChange.bind (this));
this.$('user-name').addEventListener ('change', this.onUserChange.bind (this)); this.$('user-name').addEventListener ('change', this.onUserChange.bind (this));
this.$('add').addEventListener ('click', this.onAddClick.bind (this));
}
,onAddClick: function ()
{
this.hash.set ({
'form': 'account/address',
'address': 0
});
} }
,onUserDataReady: function (form) ,onUserDataReady: function (form)

View File

@ -0,0 +1,42 @@
.conf
{
padding: 1em;
}
.conf .box
{
max-width: 40em;
}
.conf .form
{
margin: 0 auto;
max-width: 25em;
padding: 2em;
}
.conf .form-group
{
padding: 0.4em;
}
.conf .form-group label
{
display: block;
margin-bottom: 0.5em;
}
.conf .form-group input[type=text],
.conf .form-group input[type=password]
{
margin: 0;
width: 100%;
}
.conf .form-group input[type=password]
{
margin-bottom: 0.5em;
}
.consignee
{
margin-bottom: 1em;
}
.consignee p
{
margin: 0.2em 0;
}

View File

@ -8,8 +8,14 @@
ON u.id = c.user_id ON u.id = c.user_id
</db-model> </db-model>
</db-form> </db-form>
<db-model id="consignees">
SELECT id, consignee, p.name province, zip_code, city, a.name
FROM address_view a
JOIN vn2008.province p ON a.province_id = p.province_id
WHERE active != FALSE
</db-model>
</vn-group> </vn-group>
<div id="form" class="account"> <div id="form" class="conf">
<div class="box"> <div class="box">
<div class="header"> <div class="header">
<h1><t>Configuration</t></h1> <h1><t>Configuration</t></h1>
@ -17,7 +23,7 @@
<div class="form"> <div class="form">
<div class="form-group"> <div class="form-group">
<label for="user-id"><t>UserNumber</t></label> <label for="user-id"><t>UserNumber</t></label>
<htk-label column="id" form="user-form"/> <htk-text column="id" form="user-form"/>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="user-name"><t>UserName</t></label> <label for="user-name"><t>UserName</t></label>
@ -38,5 +44,33 @@
</div> </div>
</div> </div>
</div> </div>
<div class="box">
<div class="header">
<h1><t>Consignees</t></h1>
<div class="action-bar">
<button id="add">
<img src="image/dark/add.svg" alt=""/>
<t>Add</t>
</button>
</div>
</div>
<div class="form">
<htk-repeater model="consignees" form-id="iter">
<div class="consignee">
<h2><htk-text form="iter" column="consignee"/></h2>
<p>
<htk-text form="iter" column="name"/>
</p>
<p>
<htk-text form="iter" column="zip_code"/> -
<htk-text form="iter" column="city"/>
</p>
<p>
<htk-text form="iter" column="province"/>
</p>
</div>
</htk-repeater>
</div>
</div>
</div> </div>
</vn> </vn>

View File

@ -1,34 +0,0 @@
.account
{
padding: 1em;
}
.account .box
{
max-width: 40em;
}
.account .form
{
margin: 0 auto;
max-width: 25em;
padding: 2em;
}
.account .form-group
{
padding: 0.4em;
}
.account .form-group label
{
display: block;
margin-bottom: 0.5em;
}
.account .form-group input[type=text],
.account .form-group input[type=password]
{
margin: 0;
width: 100%;
}
.account .form-group input[type=password]
{
margin-bottom: 0.5em;
}

View File

@ -12,6 +12,7 @@ Vn.Catalog = new Class
model.setFieldFlags ('id', Db.Conn.Flag.AI); model.setFieldFlags ('id', Db.Conn.Flag.AI);
model.setFieldFlags ('Id_Article', Db.Conn.Flag.PRI_KEY); model.setFieldFlags ('Id_Article', Db.Conn.Flag.PRI_KEY);
this.$('price').renderer = this.priceRenderer;
this.$('type-column').renderer = this.typeRenderer.bind (this); this.$('type-column').renderer = this.typeRenderer.bind (this);
this.$('cat').renderer = this.catRenderer; this.$('cat').renderer = this.catRenderer;
this.$('basket-button').addEventListener ('click', this.basketClicked.bind (this)); this.$('basket-button').addEventListener ('click', this.basketClicked.bind (this));
@ -26,17 +27,12 @@ Vn.Catalog = new Class
this.$('warehouse').value = 1; this.$('warehouse').value = 1;
this.$('date').value = new Date (); this.$('date').value = new Date ();
if (!Vn.Url.getQuery ('guest')) var orderId = Vn.Cookie.getInt ('order');
{
var orderId = Vn.Cookie.getInt ('order'); if (!orderId)
this.configureView ();
if (!orderId)
this.configureView ();
else
this.$('order-batch').addValue ('order', orderId);
}
else else
this.$('order').value = 0; this.$('order-batch').addValue ('order', orderId);
} }
,onRealmsReload: function (model, status) ,onRealmsReload: function (model, status)
@ -189,17 +185,6 @@ Vn.Catalog = new Class
Vn.Cookie.unset ('order'); Vn.Cookie.unset ('order');
this.$('order').value = orderId; this.$('order').value = orderId;
var priceCol = new Htk.ColumnSpin
({
title: 'Price'
,digits: 2
,unit: '€'
,column: 'price'
,renderer: this.priceRenderer
});
grid.insertColumn (11, priceCol);
this.$('basket-button').disabled = false; this.$('basket-button').disabled = false;
} }

View File

@ -28,8 +28,7 @@
<db-model result-index="1" main-table="m" updatable="false" id="items-model"> <db-model result-index="1" main-table="m" updatable="false" id="items-model">
CALL item (#warehouse, #date); CALL item (#warehouse, #date);
SELECT i.grouping, m.amount, Foto, i.available, Article, Categoria, SELECT i.grouping, m.amount, Foto, i.available, Article, Categoria,
Medida, Tallos, Color, o.Abreviatura, price, fixed, m.id, Medida, Tallos, Color, o.Abreviatura, price, fixed, m.id, Id_Article
Id_Article
FROM vn2008.Articles a FROM vn2008.Articles a
INNER JOIN vn2008.item_catalog i ON i.item_id = a.Id_Article INNER JOIN vn2008.item_catalog i ON i.item_id = a.Id_Article
LEFT JOIN vn2008.Origen o ON a.id_origen = o.id LEFT JOIN vn2008.Origen o ON a.id_origen = o.id
@ -106,6 +105,7 @@
<htk-column-text title="_Color" column="Color"/> <htk-column-text title="_Color" column="Color"/>
<htk-column-text title="_Tallos" column="Tallos"/> <htk-column-text title="_Tallos" column="Tallos"/>
<htk-column-text title="_Origin" column="Abreviatura"/> <htk-column-text title="_Origin" column="Abreviatura"/>
<htk-column-text title="_Price" column="price" digits="2" unit="€" id="price"/>
</htk-grid> </htk-grid>
<p class="footer-message"> <p class="footer-message">
<t>IndicativePhotos</t> <t>IndicativePhotos</t>

View File

@ -5,11 +5,15 @@ Vn.New = new Class
,activate: function () ,activate: function ()
{ {
this.$('new-cancel').addEventListener ('click', this.onCancelClick.bind (this));
this.$('new-accept').addEventListener ('click', this.onAcceptClick.bind (this));
this.$('new-form').on ('status-changed', this.onStatusChange, this);
this.$('new-body').on ('changed', this.onBodyChange, this);
this.$('html-editor').id = 'html-editor'; this.$('html-editor').id = 'html-editor';
this.$('return').addEventListener ('click', this.onReturnClick.bind (this));
this.$('accept').addEventListener ('click', this.onAcceptClick.bind (this));
this.$('body').on ('changed', this.onBodyChange, this);
this.$('iter').on ('status-changed', this.onStatusChange, this);
this.$('model').on ('operations-done', this.onOperationsDone, this);
this.$('model').mode = Db.Model.Mode.ON_DEMAND;
this.$('model').setDefault ('user_id', 'news',
new Sql.Func ({schema: 'account', name: 'user_get_id'}));
tinymce.init ({ tinymce.init ({
mode : 'exact' mode : 'exact'
@ -36,54 +40,36 @@ Vn.New = new Class
,onStatusChange: function (form) ,onStatusChange: function (form)
{ {
if (this.$('new-param').value == 0) if (this.$('new-id').value == 0)
form.insertRow (); form.insertRow ();
} }
,onOperationsDone: function ()
{
(new Htk.Toast ()).showMessage (_('NewChangedSuccessfully'));
this.onReturnClick ();
}
,onBodyChange: function () ,onBodyChange: function ()
{ {
var newHtml = this.$('new-form').get ('text'); var newHtml = this.$('iter').get ('text');
if (!newHtml) if (!newHtml)
newHtml = ''; newHtml = '';
tinyMCE.get ('html-editor').setContent (newHtml); tinyMCE.get ('html-editor').setContent (newHtml);
} }
,onCancelClick: function ()
{
this.hash.set ({'form': 'news/news'});
}
,onAcceptClick: function () ,onAcceptClick: function ()
{ {
var form = this.$('new-form');
var newHtml = tinyMCE.get ('html-editor').getContent (); var newHtml = tinyMCE.get ('html-editor').getContent ();
this.$('iter').set ('text', newHtml);
if (this.$('new-param').value == 0) this.$('iter').performOperations ();
{
var batch = new Sql.Batch ();
batch.addValue ('title', form.get ('title'));
batch.addValue ('tag', form.get ('tag'));
batch.addValue ('text', newHtml);
var query = 'INSERT INTO news (title, text, tag, user_id) '
+'VALUES (#title, #text, #tag, account.user_get_id())';
this.conn.execQuery (query, this.newAdded.bind (this), batch);
// this.$('new-form').performOperations ();
}
else
{
form.set ('text', newHtml);
this.onCancelClick ();
}
} }
,newAdded: function (resultSet) ,onReturnClick: function ()
{ {
if (resultSet.fetchResult ()) this.hash.set ({'form': 'news/news'});
this.onCancelClick ();
} }
}); });

View File

@ -1,15 +1,15 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="new-param"> <vn-param id="new-id">
<vn-hash-link key="new"/> <vn-hash-link key="new"/>
</vn-param> </vn-param>
<db-form id="new-form"> <db-form id="iter">
<db-param column="text" id="new-body"/> <db-param column="text" id="body"/>
<db-model> <db-model id="model">
SELECT id, user_id, title, text, tag SELECT id, title, text, tag
FROM news WHERE id = #new FROM news WHERE id = #new
<sql-batch property="batch"> <sql-batch property="batch">
<item name="new" param="new-param"/> <item name="new" param="new-id"/>
</sql-batch> </sql-batch>
</db-model> </db-model>
</db-form> </db-form>
@ -18,15 +18,25 @@
<div class="box"> <div class="box">
<div class="header"> <div class="header">
<h1><t>AddNew</t></h1> <h1><t>AddNew</t></h1>
<div class="action-bar">
<button id="return">
<img src="image/dark/go-previous.svg" alt=""/>
<t>Return</t>
</button>
<button id="accept">
<img src="image/dark/ok.svg" alt=""/>
<t>Accept</t>
</button>
</div>
</div> </div>
<div class="form"> <div class="form">
<div class="form-group"> <div class="form-group">
<label><t>Title:</t></label> <label><t>Title:</t></label>
<htk-entry column="title" form="new-form"/> <htk-entry column="title" form="iter"/>
</div> </div>
<div class="form-group"> <div class="form-group">
<label><t>Tag:</t></label> <label><t>Tag:</t></label>
<htk-combo column="tag" form="new-form"> <htk-combo column="tag" form="iter">
<db-model property="model"> <db-model property="model">
SELECT name, description FROM news_tag SELECT name, description FROM news_tag
ORDER BY description ORDER BY description
@ -37,10 +47,6 @@
<label><t>NewBody:</t></label> <label><t>NewBody:</t></label>
<textarea id="html-editor"/> <textarea id="html-editor"/>
</div> </div>
<div class="foot">
<button id="new-cancel" class="vn"><t>Cancel</t></button>
<button id="new-accept" class="vn"><t>Accept</t></button>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -204,7 +204,7 @@ Db.Conn.implement
if (results[i] !== true) if (results[i] !== true)
{ {
var data = results[i].data; var data = results[i].data;
var columns = results[i].field; var columns = results[i].columns;
for (var j = 0; j < columns.length; j++) for (var j = 0; j < columns.length; j++)
{ {

View File

@ -1,30 +0,0 @@
Vn.HttpRequest = new Class
({
kvPairs: {}
,add: function (map)
{
for (var key in map)
this.kvPairs[key] = map[key];
}
,send: function (file, callback)
{
this.request = new XMLHttpRequest ();
this.request.open ('post', file, true);
this.request.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
this.request.onreadystatechange = this.requestStateChanged.bind (this, callback);
this.request.send (Vn.Url.makeUri (this.kvPairs));
}
,requestStateChanged: function (callback)
{
if (this.request.readyState == 4)
callback (this, this.request.status == 200);
}
,getJson: function ()
{
return eval ('('+ this.request.responseText +')');
}
});

File diff suppressed because it is too large Load Diff

View File

@ -46,7 +46,7 @@ Db.ResultSet = new Class
if (result !== null) if (result !== null)
{ {
if (result.data instanceof Array) if (result.data instanceof Array)
return new Db.Result (result.data, result.field); return new Db.Result (result);
else else
return true; return true;
} }

View File

@ -6,20 +6,22 @@ Db.Result = new Class
/** /**
* Initilizes the result object. * Initilizes the result object.
**/ **/
initialize: function (data, columns) initialize: function (result)
{ {
this.data = data; this.data = result.data;
this.columns = columns; this.tables = result.tables;
this.columnMap = null; this.columns = result.columns;
this.row = -1; this.row = -1;
if (columns) if (this.columns)
{ {
this.columnMap = {}; this.columnMap = {};
for (var i = 0; i < columns.length; i++) for (var i = 0; i < this.columns.length; i++)
this.columnMap[columns[i].name] = i; this.columnMap[this.columns[i].name] = i;
} }
else
this.columnMap = null;
} }
/** /**

View File

@ -14,6 +14,12 @@ Sql.Dml = new Class
this.field.push (new Sql.Field ({name: fieldName})); this.field.push (new Sql.Field ({name: fieldName}));
} }
,addExpr: function (fieldName, expr)
{
this.expr.push (expr);
this.field.push (new Sql.Field ({name: fieldName}));
}
,delSet: function () ,delSet: function ()
{ {
this.field.splice (0, this.field.length); this.field.splice (0, this.field.length);

View File

@ -14,6 +14,11 @@ Sql.Func = new Class
type: String type: String
,value: null ,value: null
}, },
schema:
{
type: String
,value: null
},
params: params:
{ {
type: Sql.List type: Sql.List
@ -23,6 +28,7 @@ Sql.Func = new Class
,render: function (batch) ,render: function (batch)
{ {
return this.name + '()'; var sql = (this.schema) ? '`' + this.schema + '`.' : '';
return sql + '`' + this.name + '`()';
} }
}); });

View File

@ -13,6 +13,11 @@ Sql.MultiStmt = new Class
return this.stmts.push (stmt); return this.stmts.push (stmt);
} }
,getStmt: function (stmtIndex)
{
return this.stmts[index];
}
,stmtChanged: function () ,stmtChanged: function ()
{ {
this.signalEmit ('changed'); this.signalEmit ('changed');
@ -35,7 +40,12 @@ Sql.MultiStmt = new Class
var sql = ''; var sql = '';
for (var i = 0; i < this.stmts.length; i++) for (var i = 0; i < this.stmts.length; i++)
sql += this.stmts[i].render (batch) + '; '; {
if (i > 0)
sql += ";\n";
sql += this.stmts[i].render (batch);
}
return sql; return sql;
} }

View File

@ -42,7 +42,7 @@ Vn.Builder = new Class
,loadXmlFromNode: function (node) ,loadXmlFromNode: function (node)
{ {
this.contexts = []; this.contexts = [];
var mainNode = this.loadNode (node, null); var mainNode = this.loadNode (node);
this.resolveProperties (); this.resolveProperties ();
delete this.contexts; delete this.contexts;
return mainNode; return mainNode;
@ -53,8 +53,9 @@ Vn.Builder = new Class
this.objectMap[id] = object; this.objectMap[id] = object;
} }
,loadNode: function (node, parentContext) ,loadNode: function (node)
{ {
var customNode;
var htmlNode = null; var htmlNode = null;
var tagName = null; var tagName = null;
@ -69,59 +70,32 @@ Vn.Builder = new Class
{ {
htmlNode = document.importNode (node, false); htmlNode = document.importNode (node, false);
} }
else if ((customNode = this.loadCustomNode (node, null)))
{
if (customNode instanceof Htk.Widget)
htmlNode = customNode.getNode ();
}
else else
{ {
var vnObject = null; htmlNode = document.createElement (tagName);
var context = null;
var htmlNode = null;
var klass = Vn.customTags[tagName];
var nodeId = node.getAttribute ('id');
if (klass) var a = node.attributes;
{
var vnObject = new klass ();
if (vnObject instanceof Htk.Widget)
htmlNode = vnObject.getNode ();
if (!this.tags[tagName])
this.tags[tagName] = [];
this.tags[tagName].push (vnObject);
context = {
node: node
,parent: parentContext
,object: vnObject
,klass: klass
};
this.contexts.push (context);
}
else
{
htmlNode = document.createElement (tagName);
vnObject = htmlNode;
var a = node.attributes; for (var i = 0; i < a.length; i++)
if (a[i].nodeName !== 'id')
htmlNode.setAttribute (a[i].nodeName,
this.translateValue (a[i].nodeValue));
for (var i = 0; i < a.length; i++) this.registerObject (node, htmlNode);
if (a[i].nodeName !== 'id')
htmlNode.setAttribute (a[i].nodeName,
this.translateValue (a[i].nodeValue));
}
if (nodeId)
this.objectMap[nodeId] = vnObject;
var childs = node.childNodes; var childs = node.childNodes;
if (childs) if (childs)
for (var i = 0; i < childs.length; i++) for (var i = 0; i < childs.length; i++)
{ {
var htmlChild = var htmlChild = this.loadNode (childs[i]);
this.loadNode (childs[i], context);
if (htmlChild && htmlNode) if (htmlChild)
htmlNode.appendChild (htmlChild); htmlNode.appendChild (htmlChild);
} }
} }
@ -129,6 +103,51 @@ Vn.Builder = new Class
return htmlNode; return htmlNode;
} }
,loadCustomNode: function (node, parentContext)
{
if (!node.tagName)
return null;
var tagName = node.tagName.toLowerCase ();
var klass = Vn.customTags[tagName];
if (!klass)
return null;
var customNode = new klass ();
if (!this.tags[tagName])
this.tags[tagName] = [];
this.tags[tagName].push (customNode);
var context = {
node: node
,parent: parentContext
,object: customNode
,klass: klass
};
this.contexts.push (context);
this.registerObject (node, customNode);
var childs = node.childNodes;
if (childs)
for (var i = 0; i < childs.length; i++)
this.loadCustomNode (childs[i], context);
return customNode;
}
,registerObject: function (node, object)
{
var nodeId = node.getAttribute ('id');
if (nodeId)
this.objectMap[nodeId] = object;
}
,translateValue: function (value) ,translateValue: function (value)
{ {
var chr = value.charAt (0); var chr = value.charAt (0);

View File

@ -4,6 +4,8 @@
,"Title:": "Títol:" ,"Title:": "Títol:"
,"NewBody:": "Cos:" ,"NewBody:": "Cos:"
,"Cancel": "Cancel" ,"Return": "Tornar"
,"Accept": "Acceptar" ,"Accept": "Acceptar"
,"NewChangedSuccessfully": "Notícia modificada correctament"
} }

View File

@ -4,6 +4,8 @@
,"Title:": "Título:" ,"Title:": "Título:"
,"NewBody:": "Cuerpo:" ,"NewBody:": "Cuerpo:"
,"Cancel": "Cancelar" ,"Return": "Volver"
,"Accept": "Aceptar" ,"Accept": "Aceptar"
,"NewChangedSuccessfully": "Noticia modificada correctamente"
} }

View File

@ -4,6 +4,8 @@
,"Title:": "Titre:" ,"Title:": "Titre:"
,"NewBody:": "Corps:" ,"NewBody:": "Corps:"
,"Cancel": "Annuler" ,"Return": "Reviens"
,"Accept": "Accepter" ,"Accept": "Accepter"
,"NewChangedSuccessfully": "Nouvelles modifié avec succès"
} }

View File

@ -21,12 +21,14 @@ class RestMod extends Rest\Module
if ($result !== FALSE) if ($result !== FALSE)
{ {
$tableMap = [];
$columns = $result->fetch_fields (); $columns = $result->fetch_fields ();
$resultMap = $resultMap =
[ [
'data' => [], 'data' => [],
'field' => [] 'columns' => [],
'tables' => []
]; ];
for ($i = 0; $i < $result->field_count; $i++) for ($i = 0; $i < $result->field_count; $i++)
@ -62,23 +64,39 @@ class RestMod extends Rest\Module
default; default;
$type = TYPE_STRING; $type = TYPE_STRING;
} }
if (!isset ($tableMap[$column->table]))
{
$resultMap['tables'][] =
[
'name' => $column->table,
'orgname' => $column->orgtable,
'schema' => $column->db,
'pks' => []
];
$tableIndex = count ($resultMap['tables']) - 1;
$tableMap[$column->table] = $tableIndex;
}
else
$tableIndex = $tableMap[$column->table];
if ($column->flags & MYSQLI_PRI_KEY_FLAG)
$resultMap['tables'][$tableIndex]['pks'][] = $i;
$default = $this->castValue ($column->def, $type); $default = $this->castValue ($column->def, $type);
$resultMap['field'][] = $resultMap['columns'][] =
[ [
'type' => $type,
'flags' => $column->flags,
'def' => $default,
'name' => $column->name, 'name' => $column->name,
'orgname' => $column->orgname, 'orgname' => $column->orgname,
'table' => $column->table, 'table' => $tableIndex
'orgtable' => $column->orgtable,
'def' => $default,
'db' => $column->db,
'flags' => $column->flags,
'type' => $type
]; ];
} }
$columns = $resultMap['field']; $columns = $resultMap['columns'];
while ($row = $result->fetch_row ()) while ($row = $result->fetch_row ())
{ {
@ -95,6 +113,8 @@ class RestMod extends Rest\Module
$results[] = TRUE; $results[] = TRUE;
} }
while ($conn->moreResults () && $conn->nextResult ()); while ($conn->moreResults () && $conn->nextResult ());
$conn->checkError ();
} }
catch (Db\Exception $e) catch (Db\Exception $e)
{ {