|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
Lib::loadClass('Core_AclHelper');
|
|
|
+Lib::loadClass('AntAclBase');
|
|
|
|
|
|
class ACL {
|
|
|
|
|
|
@@ -320,15 +321,74 @@ SQL;
|
|
|
}
|
|
|
}
|
|
|
if (!$appInfoRootFieldName || !$appInfoChildFieldName) throw new Exception("Error Processing flat_relation_cache");
|
|
|
+ $sqlWhereFromRestrictions = [];
|
|
|
+ DBG::log(['root'=>$rootAcl->getFields(), 'child'=>$childAcl->getFields()], 'array', "rootAcl and childAcl fields - xsdRestrictions");
|
|
|
+ if ($rootAcl instanceof AntAclBase && $childAcl instanceof AntAclBase) {
|
|
|
+ $rootLocalFieldsWithRestrictions = array_filter($rootAcl->getFields(), function ($field) {
|
|
|
+ if (!$field['isLocal']) return false;
|
|
|
+ if (empty($field['xsdRestrictions'])) return false;
|
|
|
+ if ('[]' == $field['xsdRestrictions']) return false;
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ $childLocalFieldsWithRestrictions = array_filter($childAcl->getFields(), function ($field) {
|
|
|
+ if (!$field['isLocal']) return false;
|
|
|
+ if (empty($field['xsdRestrictions'])) return false;
|
|
|
+ if ('[]' == $field['xsdRestrictions']) return false;
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ DBG::log(['root'=>$rootLocalFieldsWithRestrictions, 'child'=>$childLocalFieldsWithRestrictions], 'array', "root and child fields with xsdRestrictions");
|
|
|
+ if (!empty($rootLocalFieldsWithRestrictions)) {
|
|
|
+ $sqlTablePrefix = 'root';
|
|
|
+ $sqlWhereFromRestrictions = array_reduce(
|
|
|
+ array_map(function ($field) use ($sqlTablePrefix) {
|
|
|
+ $sqlRestrictions = [];
|
|
|
+ // 'xsdRestrictions' => '{"enumeration":{"PROCES":"PROCES"}}',
|
|
|
+ $restrictions = @json_decode($field['xsdRestrictions'], $assoc = true);
|
|
|
+ if (!empty($restrictions)) {
|
|
|
+ if (!empty($restrictions['enumeration'])) {
|
|
|
+ $sqlRestrictions[] = "{$sqlTablePrefix}.`{$field['fieldNamespace']}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($restrictions['enumeration']))) . ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $sqlRestrictions;
|
|
|
+ }, $rootLocalFieldsWithRestrictions),
|
|
|
+ function ($ret, $cur) {
|
|
|
+ return array_merge($ret, array_filter($cur, ['V', 'filterNotEmpty']));
|
|
|
+ },
|
|
|
+ $sqlWhereFromRestrictions
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (!empty($childLocalFieldsWithRestrictions)) {
|
|
|
+ $sqlTablePrefix = 'child';
|
|
|
+ $sqlWhereFromRestrictions = array_reduce(
|
|
|
+ array_map(function ($field) use ($sqlTablePrefix) {
|
|
|
+ $sqlRestrictions = [];
|
|
|
+ // 'xsdRestrictions' => '{"enumeration":{"PROCES":"PROCES"}}',
|
|
|
+ $restrictions = @json_decode($field['xsdRestrictions'], $assoc = true);
|
|
|
+ if (!empty($restrictions)) {
|
|
|
+ if (!empty($restrictions['enumeration'])) {
|
|
|
+ $sqlRestrictions[] = "{$sqlTablePrefix}.`{$field['fieldNamespace']}` in (" . implode(",", array_map([DB::getPDO(), 'quote'], array_keys($restrictions['enumeration']))) . ")";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $sqlRestrictions;
|
|
|
+ }, $childLocalFieldsWithRestrictions),
|
|
|
+ function ($ret, $cur) {
|
|
|
+ return array_merge($ret, array_filter($cur, ['V', 'filterNotEmpty']));
|
|
|
+ },
|
|
|
+ $sqlWhereFromRestrictions
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $sqlWhereFromRestrictions = (!empty($sqlWhereFromRestrictions)) ? implode(" and ", $sqlWhereFromRestrictions) : "1=1";
|
|
|
$sql = "
|
|
|
- select l.{$rootPrimaryKeyField} as PRIMARY_KEY
|
|
|
- , r.{$childPrimaryKeyField} as REMOTE_PRIMARY_KEY
|
|
|
+ select root.{$rootPrimaryKeyField} as PRIMARY_KEY
|
|
|
+ , child.{$childPrimaryKeyField} as REMOTE_PRIMARY_KEY
|
|
|
, '' as REMOTE_TYPENAME
|
|
|
, 'WAITING' as A_STATUS
|
|
|
, 0 as TRANSACTION_ID
|
|
|
, {$lastActionDateField} as A_LAST_ACTION_DATE
|
|
|
- from `{$rootTableName}` l
|
|
|
- join `{$childTableName}` r on(r.{$appInfoRootFieldName} = l.{$appInfoChildFieldName})
|
|
|
+ from `{$rootTableName}` root
|
|
|
+ join `{$childTableName}` child on(child.{$appInfoRootFieldName} = root.{$appInfoChildFieldName})
|
|
|
+ where {$sqlWhereFromRestrictions}
|
|
|
";
|
|
|
DBG::log($sql, 'sql', "generateRefSelectSqlByFlatRelationCache");
|
|
|
return $sql;
|