|
|
@@ -462,6 +462,52 @@ class ACL {
|
|
|
return $refInfo;
|
|
|
}
|
|
|
|
|
|
+ public static function generateIsInstanceFunctionBody($namespace, $item = null) {
|
|
|
+ if (!$item) $item = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, [ 'propertyName' => '*,field' ]);
|
|
|
+ if (!in_array( $item['_type'], [ 'AntAcl' ] )) return null;
|
|
|
+ $dbName = DB::getPDO()->getDatabaseName();
|
|
|
+ $sqlFunBody = " RETURN 1; ";
|
|
|
+ $localFieldsWithRestrictions = array_filter($item['field'], function ($field) {
|
|
|
+ if (!$field['isLocal']) return false;
|
|
|
+ if (empty($field['xsdRestrictions'])) return false;
|
|
|
+ if ('[]' == $field['xsdRestrictions']) return false;
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+ // TODO: get fields with minOccurs > 1 (may require select by ref)
|
|
|
+ $sqlTablePrefix = 'root';
|
|
|
+ $sqlWhereFromRestrictions = (!empty($localFieldsWithRestrictions))
|
|
|
+ ? 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;
|
|
|
+ }, $localFieldsWithRestrictions),
|
|
|
+ function ($ret, $cur) {
|
|
|
+ return array_merge($ret, array_filter($cur, ['V', 'filterNotEmpty']));
|
|
|
+ },
|
|
|
+ []
|
|
|
+ )
|
|
|
+ : '';
|
|
|
+ DBG::nicePrint($localFieldsWithRestrictions, "\$localFieldsWithRestrictions");
|
|
|
+ DBG::nicePrint($sqlWhereFromRestrictions, "\$sqlWhereFromRestrictions");
|
|
|
+ $sqlWhereFromRestrictions = (!empty($sqlWhereFromRestrictions)) ? implode(" and ", $sqlWhereFromRestrictions) : "1=1";
|
|
|
+ $pkField = 'ID'; // TODO: primaryKeyField into SystemObject structure
|
|
|
+ $rootTableName = $item['_rootTableName'];
|
|
|
+ $sqlFunBody = (!empty($sqlWhereFromRestrictions))
|
|
|
+ ? " RETURN IF(
|
|
|
+ (select count(1) as cnt from `{$rootTableName}` root where root.`{$pkField}` = pk and {$sqlWhereFromRestrictions}) > 0
|
|
|
+ , 1, 0)
|
|
|
+ "
|
|
|
+ : " RETURN 1; ";
|
|
|
+ return $sqlFunBody;
|
|
|
+ }
|
|
|
+
|
|
|
public static function getInstanceId($namespace) {
|
|
|
$conf = self::getInstanceConfig($namespace);
|
|
|
return $conf['id'];
|