Piotr Labudda 9 роки тому
батько
коміт
fed0302137

+ 3 - 0
SE/se-lib/Core/AclHelper.php

@@ -49,6 +49,7 @@ class Core_AclHelper {// Helper class for Acl
   public static function getAclByNamespace($namespace, $forceTblAclInit = false) {
     $ns = self::parseNamespaceUrl($namespace);
 
+    DBG::_('DBG_ACL', '>3', "parseNamespaceUrl", $ns, __CLASS__, __FUNCTION__, __LINE__);
     $acl = User::getAcl()->getObjectAcl($ns['prefix'], $ns['name']);
     if (!$acl) throw new Exception("Could not get acl for '{$ns['prefix']}:{$ns['name']}'");
     $acl->init($forceTblAclInit);
@@ -194,6 +195,8 @@ class Core_AclHelper {// Helper class for Acl
     $aclList[] = 'default_objects:AccessGroupWrite';
     $aclList[] = 'default_objects:AccessOwner';
     $aclList[] = 'default_objects:SystemObject';// tabele i obiekty możliwe do podłączenia do procesu (default_db/*, default_objects/*)
+    $aclList[] = 'default_objects:SystemFunction';// funkcje możliwe do podłączenia do procesu UrlAction
+    // $aclList[] = 'default_objects:UserFunction';// TODO: funkcje możliwe do uruchomienia przez usera
     // $aclList[] = 'default_objects:UserObject';// TODO: tabele i obiekty widoczne dla aktualnego usera
     $aclList[] = 'default_objects:SystemProcess';// wszystkie proces init
     $aclList[] = 'default_objects:UserProcess';// proces init przypisane do aktualnego usera

+ 79 - 3
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -38,6 +38,16 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
         '@namespace' => 'default_db/ZALICZKA_POZYCJA/ZaliczkaPozycja',
         ...
       ]
+
+      'YT_LINK' => [ '@type' => 'p5:typeSpecialSimpleLink',
+        '@label' => "Youtube link",
+        '@@params' => [// $acl->getXsdFieldParam($col, 'format');
+          'format' => '<a href="https://www.youtube.com/watch?v={LINK}" target="_blank"></a>',
+          'aliasMap' => [
+            'LINK' => 'LINK'
+          ]
+        ]
+      ],
     ]
    */
   public $_simpleSchema = array();
@@ -68,7 +78,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
       $this->_sourceNamespace = implode('__x3A__', $this->_sourceNamespace);
     }
 
-    if (empty($this->_simpleSchema['root']['@primaryKey'])) $this->_simpleSchema['root']['@primaryKey'] = 'ID';// TODO: throw new Exception("Missing @primaryKey in simpleSchema");
+    if (empty($this->_simpleSchema['root']['@primaryKey'])) $this->_simpleSchema['root']['@primaryKey'] = 'ID';// TODO: throw new Exception("Missing @primaryKey in simpleSchema '{$this->_name}'");
     $this->_primaryKey = $this->_simpleSchema['root']['@primaryKey'];// TODO: check if field exists
 
     {// validate and fix _simpleSchema:
@@ -241,12 +251,24 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
   public function getItem($primaryKey) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
   public function getItems($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
-  public function fetchItemRef(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
-  public function addItem($itemTodo) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
+  public function fetchItemRef(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: , $fieldName = ''
+  public function fetchItemFieldRefs($primaryKey, $fieldName) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
+  public function addItem($itemTodo) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
   public function updateItem($itemPatch) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
 
   public function getGeomFieldType($fieldName) { return null; }
   public function getPrimaryKeyField() { return $this->_primaryKey; }
+  public function getSqlPrimaryKeyField() {
+    return (!empty($this->_simpleSchema['root'][$this->_primaryKey]['@alias']))
+      ? $this->_simpleSchema['root'][$this->_primaryKey]['@alias']
+      : $this->_primaryKey;
+  }
+  public function getSqlFieldName($fieldName) {
+    if (empty($this->_simpleSchema['root'][$fieldName])) throw new Exception("Missing field in schema '{$fieldName}'");
+    return (!empty($this->_simpleSchema['root'][$fieldName]['@alias']))
+      ? $this->_simpleSchema['root'][$fieldName]['@alias']
+      : $fieldName;
+  }
   public function getID() { return 0; }
   public function getAttributesFromZasoby() { return array(); }
   public function isEnumerationField($fieldName) { return false; }
@@ -265,4 +287,58 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     // return $this->parentAcl->isGeomField($fieldName);
   }
 
+  public function generateSqlSelectFromRootTable($prefix = 't') {
+    $sqlSelect = [];
+    foreach ($this->_simpleSchema['root'] as $key => $field) {
+      if ('@' == substr($key, 0, 1)) continue;// skip attr
+      if (!empty($field['@ref'])) continue;// skip ref
+      if (empty($field['@type'])) continue;// skip wrong simpleType structure - BUG
+      if ('xsd:' != substr($field['@type'], 0, 4)) continue;// skip non xsd types - eg. p5:typeSpecialSimpleLink
+      $sqlField = (!empty($field['@alias'])) ? $field['@alias'] : $key;
+      $sqlSelect[] = "{$prefix}.`{$sqlField}` as `$key`";
+    }
+    return implode("\n, ", $sqlSelect);
+  }
+
+  public function getXsdFieldParam($fieldName, $paramKey) {
+    if (empty($this->_simpleSchema['root'][$fieldName])) return null;
+    if (empty($this->_simpleSchema['root'][$fieldName]['@@params'])) return null;
+    if (empty($this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey])) return null;
+    return $this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey];
+	}
+
+  public function addP5Types(&$item, $key) {
+    DBG::_('DBG_ACL', '>1', "\$item", $item, __CLASS__, __FUNCTION__, __LINE__);
+    $sqlSelect = [];
+    foreach ($this->_simpleSchema['root'] as $key => $field) {
+      if ('@' == substr($key, 0, 1)) continue;// skip attr
+      if (empty($field['@type'])) continue;// skip ref
+      if ('p5:' != substr($field['@type'], 0, 3)) continue;// skip non p5 types
+      $fieldName = $key;
+      $item[$fieldName] = '';
+      switch ($field['@type']) {
+        case 'p5:typeSpecialSimpleLink': {
+          // '@@params' => [// $acl->getXsdFieldParam($col, 'format');
+          //   'format' => '<a href="https://www.youtube.com/watch?v={LINK}" target="_blank"></a>',
+          //   'aliasMap' => [
+          //     'LINK' => 'LINK'
+          //   ]
+          // ]
+          $link = $this->getXsdFieldParam($fieldName, 'format');
+          // $.each(_fieldProps._tsSimpleLink.aliasMap, function(i, v) {
+          //   //console.log('simpleLink aliasMap columnName:', columnName, 'i:', i, 'v:', v, 'props['+v+']', props[v], 'val', val, 'typeof val', typeof val);
+          //   if (undefined !== row[v]) {
+          //     valLink = valLink.replace(new RegExp('\{' + i + '\}', 'g'), row[v]);
+          //   }
+          // });
+          foreach ($this->getXsdFieldParam($fieldName, 'aliasMap') as $itemFieldName => $alias) {
+            DBG::_('DBG_ACL', '>1', "aliasMap({$itemFieldName} => {$alias})", $item[$itemFieldName], __CLASS__, __FUNCTION__, __LINE__);
+            $link = str_replace("{{$alias}}", $item[$itemFieldName], $link);
+          }
+          $item[$fieldName] = $link;
+        } break;
+      }
+    }
+  }
+
 }

+ 89 - 0
SE/se-lib/Schema/SystemFunctionStorageAcl.php

@@ -0,0 +1,89 @@
+<?php
+
+Lib::loadClass('Core_AclSimpleSchemaBase');
+Lib::loadClass('ParseOgcFilter');
+
+class Schema_SystemFunctionStorageAcl extends Core_AclSimpleSchemaBase {
+
+  public $_simpleSchema = [
+    'root' => [
+      '@namespace' => 'default_objects/SystemFunction',
+      '@primaryKey' => 'name',
+      'name' => [ '@type' => 'xsd:string' ],
+      'description' => [ '@type' => 'xsd:string', '@label' => "Opis" ],
+      'param' => [ '@type' => 'xsd:string', '@label' => "Parametry", '@macOccurs' => 'unbounded' ],
+      // 'autor' => [ '@type' => 'xsd:string' ],
+      // 'utworzono' => [ '@type' => 'xsd:date' ],
+      // 'zaktualizował' => [ '@type' => 'xsd:string' ],
+      // 'zaktualizowano' => [ '@type' => 'xsd:date' ]
+    ]
+  ];
+  public $_rootTableName = 'CRM_LISTA_ZASOBOW';
+
+  public function getTotal($params = []) {
+    return count($this->_getAllItems());
+  }
+
+  public function getItems($params = []) {
+    $items = $this->_getAllItems();
+    $currSortCol = V::get('order_by', 'ID', $params);
+    $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
+    // TODO: validate $currSortCol is in field list
+    // TODO: validate $currSortFlip ('asc' or 'desc')
+
+    $aliasMap = array();
+    foreach ($this->_simpleSchema['root'] as $key => $field) {
+      if ('@' === substr($key, 0, 1)) continue;
+      $aliasMap[ $key ] = $key;// (!empty($field['@alias'])) ? $field['@alias'] : $key;
+    }
+    // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
+    $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
+
+    if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
+      usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) {
+        $a = strtolower(V::get($currSortCol, '', $itemA));
+        $b = strtolower(V::get($currSortCol, '', $itemB));
+
+        if ($a == $b) return 0;
+        else if ('asc' == $currSortFlip)  return ($a < $b) ? -1 : 1;
+        else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1;
+        throw new Exception("BUG - Wrong sort param - order dir");
+      });
+    }
+
+    $limit = V::get('limit', 0, $params);
+    $limit = ($limit < 0) ? 0 : $limit;
+    $offset = V::get('limitstart', 0, $params);
+    $offset = ($offset < 0) ? 0 : $offset;
+    return array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
+  }
+
+  public function _getAllItems($params = []) {
+    static $_cacheAllItems = null;
+    if (null !== $_cacheAllItems) return $_cacheAllItems;
+
+    $_cacheAllItems = [];
+    $_cacheAllItems[] = [ 'name' => "Calendar", 'description' => "Calendar" ];
+    $_cacheAllItems[] = [ 'name' => "ProcesEditor", 'description' => "ProcesEditor" ];
+    $_cacheAllItems[] = [ 'name' => "ProcesView", 'description' => "ProcesView" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyKosztorys", 'description' => "ProjektyKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyKosztyWstepnychRobot", 'description' => "ProjektyKosztyWstepnychRobot" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyOdbiorKosztorys", 'description' => "ProjektyOdbiorKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyOfertaAdminKosztorys", 'description' => "ProjektyOfertaAdminKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyOfertaKosztorys", 'description' => "ProjektyOfertaKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaApproveZam", 'description' => "ProjektyProNetMediaApproveZam" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaBudget", 'description' => "ProjektyProNetMediaBudget" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaFinalApproveZam", 'description' => "ProjektyProNetMediaFinalApproveZam" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaRequestApproveZam", 'description' => "ProjektyProNetMediaRequestApproveZam" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaZamZlec", 'description' => "ProjektyProNetMediaZamZlec" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyPrzedmiarKosztorys", 'description' => "ProjektyPrzedmiarKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyZamowieniaKosztorys", 'description' => "ProjektyZamowieniaKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "ProjektyZestawienieSwMikRurKosztorys", 'description' => "ProjektyZestawienieSwMikRurKosztorys" ];
+    $_cacheAllItems[] = [ 'name' => "RaportyKasowe", 'description' => "RaportyKasowe" ];
+    $_cacheAllItems[] = [ 'name' => "UserProNetMediaZaliczka", 'description' => "UserProNetMediaZaliczka" ];
+    $_cacheAllItems[] = [ 'name' => "WmsGenerate", 'description' => "WmsGenerate" ];
+
+    return $_cacheAllItems;
+  }
+
+}

+ 1 - 1
SE/se-lib/TableAjax.php

@@ -948,7 +948,7 @@ var p5UI_TableAjax_generateFunctionNode = function(funObj, rowPK, props) {
 									&& undefined !== _fieldProps._tsSimpleLink) {
 								valLink = _fieldProps._tsSimpleLink.format;
 								$.each(_fieldProps._tsSimpleLink.aliasMap, function(i, v) {
-									//console.log('simpleLink aliasMap columnName:', columnName, 'i:', i, 'v:', v, 'props['+v+']', props[v], 'val', val, 'typeof val', typeof val);
+									// console.log('simpleLink aliasMap fldName:', fldName, 'i:', i, 'v:', v, 'row['+v+']', row[v], 'val', val, 'typeof val', typeof val);
 									if (undefined !== row[v]) {
 										valLink = valLink.replace(new RegExp('\{' + i + '\}', 'g'), row[v]);
 									}

+ 1 - 1
SE/se-lib/UserAcl.php

@@ -168,7 +168,7 @@ class UserAcl {
 			return new $objClassName();
 		} else if ('default_objects' == $sourceName && !empty($objName)) {
 			$objClassName = "Schema_{$objName}StorageAcl";
-			if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented", 501);
+			if (!Lib::tryLoadClass($objClassName)) throw new HttpException("Not implemented - storage object not found '{$objName}'", 501);
 			return new $objClassName();
 		} else if ('default_db__x3A__' == substr($sourceName, 0, 17) && !empty($objName)) {
 			$rootTableName = strtolower(substr($sourceName, 17));