From 840bb97a2c8cffc830c9f7f51cbee914af740ac6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 28 Jun 2021 15:47:53 -0400 Subject: [PATCH] APIv4 Explorer - Render joins using addJoin function in OOP --- ang/api4Explorer/Explorer.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index 1f7c7e065b..b99b422cf4 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -351,6 +351,16 @@ } } }); + _.each(params.join, function(join) { + // Add alias if not specified + if (!_.contains(join[0], 'AS')) { + join[0] += ' AS ' + join[0].toLowerCase(); + } + // Remove EntityBridge from join if empty + if (!join[2]) { + join.splice(2, 1); + } + }); _.each(objectParams, function(defaultVal, key) { if (params[key]) { var newParam = {}; @@ -358,7 +368,7 @@ var val = _.cloneDeep(item[1]); // Remove blank items from "chain" array if (_.isArray(val)) { - _.eachRight(item[1], function(v, k) { + _.eachRight(item[1], function(v) { if (v) { return false; } @@ -752,6 +762,10 @@ code += newLine + "->addChain('" + name + "', " + formatOOP(chain[0], chain[1], chain[2], 2 + indent); code += (chain.length > 3 ? ',' : '') + (!_.isEmpty(chain[2]) ? newLine : ' ') + (chain.length > 3 ? phpFormat(chain[3]) : '') + ')'; }); + } else if (key === 'join') { + _.each(param, function(join) { + code += newLine + "->addJoin(" + phpFormat(join).slice(1, -1) + ')'; + }); } else if (key !== 'checkPermissions') { code += newLine + "->set" + ucfirst(key) + '(' + phpFormat(param, 2 + indent) + ')'; @@ -1326,6 +1340,8 @@ function getExplicitJoins() { return _.transform(params.join, function(joins, join) { + // Fix capitalization of AS + join[0] = join[0].replace(/ as /i, ' AS '); var j = join[0].split(' AS '), joinEntity = _.trim(j[0]), joinAlias = _.trim(j[1]) || joinEntity.toLowerCase(); -- 2.25.1