|
@@ -6105,6 +6105,73 @@ jQuery(document).ready(function(){
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ {
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__ = [];}
|
|
|
|
|
+ $p5Alias = [];
|
|
|
|
|
+ foreach ((array)$jsonData->cols as $fieldName => $conf) {
|
|
|
|
|
+ if ('p5:alias' == V::get('xsdType', '', $conf)) {
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__[$fieldName] = $conf;}
|
|
|
|
|
+ $aliasType = $acl->getXsdFieldParam($fieldName, 'type');// 'type' => 'sql_table_alias',
|
|
|
|
|
+ if ('sql_table_alias' == $aliasType) {
|
|
|
|
|
+ $p5Alias[$fieldName] = (array)$conf;
|
|
|
|
|
+ $p5Alias[$fieldName]['local_join_key'] = $acl->getXsdFieldParam($fieldName, 'local_join_key');// 'local_join_key' => 'ID',
|
|
|
|
|
+ $p5Alias[$fieldName]['remote_table_name'] = $acl->getXsdFieldParam($fieldName, 'remote_table_name');// 'remote_table_name' => 'CRM_LISTA_ZASOBOW_ORDERS_summary_view',
|
|
|
|
|
+ $p5Alias[$fieldName]['remote_join_key'] = $acl->getXsdFieldParam($fieldName, 'remote_join_key');// 'remote_join_key' => 'ID',
|
|
|
|
|
+ $p5Alias[$fieldName]['remote_column_value'] = $acl->getXsdFieldParam($fieldName, 'remote_column_value');// 'remote_column_value' => 'SUM_POS',
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$p5Alias'] = $p5Alias;}
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'] = [];}
|
|
|
|
|
+ if ($p5Alias) {
|
|
|
|
|
+ $sqlLocalTableName = $acl->getRootTableName();
|
|
|
|
|
+ $primaryKeyField = $acl->getPrimaryKeyField();
|
|
|
|
|
+ foreach ($p5Alias as $fieldName => $conf) {
|
|
|
|
|
+ $localKeys = [];
|
|
|
|
|
+ $localKeyName = V::get('local_join_key', '', $conf);
|
|
|
|
|
+ if ($localKeyName) {
|
|
|
|
|
+ if (!array_key_exists($localKeyName, $localKeys)) {
|
|
|
|
|
+ $localKeys[$localKeyName] = [];
|
|
|
|
|
+ foreach ($items as $item) {
|
|
|
|
|
+ $keyLocal = V::get($localKeyName, 0, $item);
|
|
|
|
|
+ if ($keyLocal) $localKeys[$localKeyName][] = DB::getPDO()->quote($keyLocal, PDO::PARAM_STR);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$localKeys'] = $localKeys;}
|
|
|
|
|
+ if (!empty($localKeys[$localKeyName])) {
|
|
|
|
|
+ $sqlRemoteTable = V::get('remote_table_name', '', $conf);
|
|
|
|
|
+ $sqlRemoteValueFieldName = V::get('remote_column_value', '', $conf);
|
|
|
|
|
+ $sqlRemoteKeyName = V::get('remote_join_key', '', $conf);
|
|
|
|
|
+ $sqlLocalKeyName = $acl->getSqlFieldName($localKeyName);
|
|
|
|
|
+ $aliasValuesRaw = DB::getPDO()->fetchAllByKey("
|
|
|
|
|
+ select r.{$sqlRemoteKeyName} as {$sqlLocalKeyName}, r.{$sqlRemoteValueFieldName} as remote_value
|
|
|
|
|
+ from {$sqlRemoteTable} r
|
|
|
|
|
+ where r.{$sqlRemoteKeyName} in(" . implode(",", $localKeys[$localKeyName]) . ")
|
|
|
|
|
+ ", $sqlLocalKeyName);
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['SQL__$aliasValuesRaw'][$fieldName] = "
|
|
|
|
|
+ select r.{$sqlRemoteKeyName} as {$sqlLocalKeyName}, r.{$sqlRemoteValueFieldName} as remote_value
|
|
|
|
|
+ from {$sqlRemoteTable} r
|
|
|
|
|
+ where r.{$sqlRemoteKeyName} in(" . implode(",", $localKeys[$localKeyName]) . ")
|
|
|
|
|
+ ";}
|
|
|
|
|
+ if(V::get('DBG', '', $_GET)){$jsonData->__DBG__['$aliasValuesRaw'][$fieldName] = $aliasValuesRaw;}
|
|
|
|
|
+ if (!empty($aliasValuesRaw)) {
|
|
|
|
|
+ if(V::get('DBG_P5', '', $_GET)){echo '{ "$aliasValuesRaw": '.json_encode($aliasValuesRaw).', "dbg": [' . "\n";}
|
|
|
|
|
+ array_walk($items, function (&$item) use ($fieldName, $sqlLocalKeyName, $aliasValuesRaw) {
|
|
|
|
|
+ $sqlValue = V::get($sqlLocalKeyName, null, $item);
|
|
|
|
|
+ if(V::get('DBG_P5', '', $_GET)){echo '{ "sqlValue": "'.$sqlValue.'", "remote_value": "'.$aliasValuesRaw[$sqlValue]['remote_value'].'", "item": '.json_encode($item) . '},' . "\n";}
|
|
|
|
|
+ if ($sqlValue !== null && array_key_exists($sqlValue, $aliasValuesRaw)) {
|
|
|
|
|
+ if(V::get('DBG_P5', '', $_GET)){echo '{ "TODO_update_value": "'.$aliasValuesRaw[$sqlValue]['remote_value'].'"},' . "\n";}
|
|
|
|
|
+ $item[$fieldName] = $aliasValuesRaw[$sqlValue]['remote_value'];
|
|
|
|
|
+ if(V::get('DBG_P5', '', $_GET)){echo '{ "TODO_updated_value": "'.$item[$fieldName].'"},' . "\n";}
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if(V::get('DBG_P5', '', $_GET)){echo "\n".'{}]}';die();}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
foreach ($items as $item) {
|
|
foreach ($items as $item) {
|
|
|
// TODO: hide items without 'R'
|
|
// TODO: hide items without 'R'
|
|
|
foreach ($visibleCols as $fieldName) {
|
|
foreach ($visibleCols as $fieldName) {
|