Преглед изворни кода

added default_objects:SystemObject

Piotr Labudda пре 9 година
родитељ
комит
4b84adf7c7

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

@@ -193,6 +193,10 @@ class Core_AclHelper {// Helper class for Acl
     $aclList[] = 'default_objects:AccessGroupRead';
     $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:UserObject';// TODO: tabele i obiekty widoczne dla aktualnego usera
+    // $aclList[] = 'default_objects:SystemProcess';// TODO: wszystkie proces init
+    // $aclList[] = 'default_objects:UserProcess';// TODO: proces init przypisane do aktualnego usera
     $aclList[] = 'default_objects:File';
     $aclList[] = 'default_objects:Korespondencja';
     $aclList[] = 'default_objects:TestPerms';

+ 16 - 6
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -42,7 +42,9 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
   public $_simpleSchema = array();
   public $_xsdTypes = null;// set by parseXsdTypes()
   public $_name = '';
+  public $_namespace = '';
   public $_rootTableName = '';
+  public $_sourceNamespace = '';
   public $_xmlnsMap = [];
 
   public function __construct($simpleSchema = null) {
@@ -51,10 +53,18 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     if (!$this->_simpleSchema) throw new Exception("Missing simpleSchema");
     if (empty($this->_simpleSchema['root'])) throw new Exception("Wrong simpleSchema syntax");
     if (empty($this->_simpleSchema['root']['@namespace'])) throw new Exception("Missing @namespace in simpleSchema");
-    $ns = explode('/', $this->_simpleSchema['root']['@namespace']);
+    $this->_namespace = $this->_simpleSchema['root']['@namespace'];
+    $ns = explode('/', $this->_namespace);
     $this->_name = end($ns);
-    if (count($ns) < 2) throw new Exception("Wrong @namespace syntax in simpleSchema");
-    $this->_rootTableName = $ns[1];
+    if (empty($this->_rootTableName)) {
+      if (count($ns) < 3) throw new Exception("Wrong @namespace syntax in simpleSchema ns({$this->_simpleSchema['root']['@namespace']})");
+      $this->_rootTableName = $ns[1];
+    }
+    {
+      $this->_sourceNamespace = explode('/', $this->_namespace);
+      array_pop($this->_sourceNamespace);// remove name
+      $this->_sourceNamespace = implode('__x3A__', $this->_sourceNamespace);
+    }
 
     {// validate and fix _simpleSchema:
       // - convert field scalar to [ '@type' => ... ]
@@ -181,11 +191,11 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     return $tree;
   }
   public function getName() { return $this->_name; }
-  public function getRootTableName() { $this->_rootTableName; }
+  public function getRootTableName() { return $this->_rootTableName; }
   public function getXsdTypes() { return $this->_xsdTypes; }
 
-  public function getNamespace() { return 'default_db/' . $this->_rootTableName . '/' . $this->_name; }
-  public function getSourceName() { return 'default_db__x3A__' . $this->_rootTableName; }
+  public function getNamespace() { return $this->_namespace; }
+  public function getSourceName() { return $this->_sourceNamespace; }
   public function init($force = false) {}
   public function isInitialized() { return true; }
   public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }

+ 16 - 17
SE/se-lib/Route/Storage.php

@@ -1400,23 +1400,22 @@ jQuery(document).on('p5UIBtnAjax:Storage:addBaseProces:ajaxLoaded', function(e,
 		UI::menu();
 		$this->navView();
 		try {
-			throw new Exception("TODO: F." . __FUNCTION__ . ' L.' . __LINE__);
-	// 		$coreObjlist = OBJXSD::getSystemObjectsList();
-	// 		$objectList = array();
-	// 		foreach ($coreObjlist as $objName) {
-	// 			$objItem = array();
-	// 			$objItem['name'] = $objName;
-	// 			$objItem['struktura'] = '<a href="index.php?_route=Storage&_task=systemObjectsStruct&object=' . $objName . '">' . "struct" . '</a>';
-	// 			// $objItem['label'] = "";// TODO: read from json
-	// 			$objectList[] = $objItem;
-	// 		}
-	// 		usort($objectList, function($rowA, $rowB) {
-	// 			$a = $rowA['nazwa']; $b = $rowB['nazwa'];
-	// 			if ($a == $b) return 0;
-	// 			return ($a < $b) ? -1 : 1;
-	// 		});
-	//
-	// 		DBG::table("objectList", $objectList, __CLASS__, __FUNCTION__, __LINE__);
+			Lib::loadClass('Schema_SystemObjectStorageAcl');
+			$acl = new Schema_SystemObjectStorageAcl();
+			UI::table([
+				'rows' => array_map(
+					function ($item) {
+						return [
+							'ns' => $item['namespace'],
+							'edit' => '<a href="index.php?_route=ViewTableAjax&namespace=' . $item['namespace'] . '">edit</a>'
+						];
+					}
+					, $acl->getItems([
+						'order_by' => 'ID',
+						'order_dir' => 'asc'
+					])
+				)
+			]);
 		} catch (Exception $e) {
 			UI::alert('danger', "Error #" . $e->getCode() .  "|" . $e->getLine() .  ": " . $e->getMessage());
 		}

+ 11 - 9
SE/se-lib/Route/ViewTableAjax.php

@@ -80,13 +80,15 @@ class Route_ViewTableAjax extends RouteBase {
 				UI::tag('p', null, "TEST - load perms from db");
 				$idTable = $acl->getID();
 				UI::tag('p', null, "DBG idTable({$idTable})");
-				$dbgExecTime->log('before sql');
-				$aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
-				$dbgExecTime->log('after sql', ['sql']);
-				UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
-				$csvIdProces = array();
-				foreach ($aclTableRows as $row) {
-					if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
+				if ($idTable > 0) {
+					$dbgExecTime->log('before sql');
+					$aclTableRows = DB::getPDO()->fetchAll("select * from `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` where ID_TABLE = {$idTable}");
+					$dbgExecTime->log('after sql', ['sql']);
+					UI::table(['caption' => "from CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW", 'rows' => $aclTableRows]);
+					$csvIdProces = array();
+					foreach ($aclTableRows as $row) {
+						if (!in_array($row['ID_PROCES'], $csvIdProces)) $csvIdProces[] = $row['ID_PROCES'];
+					}
 				}
 
 				$tableName = $acl->getName();
@@ -133,9 +135,9 @@ class Route_ViewTableAjax extends RouteBase {
 					)
 				]);
 
-				$csvIdProces = implode(",", $csvIdProces);
-				UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
 				if (!empty($csvIdProces)) {
+					$csvIdProces = implode(",", $csvIdProces);
+					UI::tag('p', null, "DBG csvIdProces({$csvIdProces})");
 					$userLogin = User::getLogin();
 					$dbgExecTime->log('before sql');
 					$rows = DB::getPDO()->fetchAll("select ID_PROCES from `CRM_PROCES_idx_USER_to_PROCES_VIEW` where ADM_ACCOUNT = '{$userLogin}' and ID_PROCES in({$csvIdProces}) group by ID_PROCES");

+ 121 - 0
SE/se-lib/Schema/SystemObjectStorageAcl.php

@@ -0,0 +1,121 @@
+<?php
+
+Lib::loadClass('Core_AclSimpleSchemaBase');
+Lib::loadClass('ParseOgcFilter');
+
+class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
+
+  public $_simpleSchema = [
+    'root' => [
+      '@namespace' => 'default_objects/SystemObject',
+      'ID' => [ '@type' => 'xsd:integer' ],
+      'namespace' => [ '@type' => 'xsd:string' ],
+      'tabela' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
+      'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
+      'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
+      'id_zasob' => [ '@type' => 'xsd:integer' ],
+      'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' ],
+      'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' ],
+      'A_RECORD_UPDATE_AUTHOR' => [ '@type' => 'xsd:string' ],
+      'A_RECORD_UPDATE_DATE' => [ '@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')
+    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 ($limit > 0)
+      ? $this->_fixKeyItems(array_splice($items, $offset, $limit))
+      : $this->_fixKeyItems(array_splice($items, $offset));
+  }
+
+  public function _fixKeyItems($items) {
+    $fixed = array();
+    foreach ($items as $item) {
+      $fixed[ $this->_generateUniqueKeyFromNamespace($item['namespace']) ] = $item;
+    }
+    return $fixed;
+  }
+
+  public function _generateUniqueKeyFromNamespace($namespace) {
+    return str_replace('/', '__x3A__', $namespace);
+  }
+
+  public function _getAllItems($params = []) {
+    static $_cacheAllItems = null;
+    if (null !== $_cacheAllItems) return $_cacheAllItems;
+    $idMainDatabase = DB::getPDO()->getZasobId();
+    $_cacheAllItems = array_filter(
+      array_merge(
+        array_map(
+          function ($row) {
+            $row['namespace'] = "default_db/{$row['tabela']}";
+            $row['ID'] = $this->_generateUniqueKeyFromNamespace($row['namespace']);
+            return $row;
+          }
+          , DB::getPDO()->fetchAll("
+            select z.ID as id_zasob
+              , z.`DESC` as tabela
+              , IF(z.`DESC_PL` != '', z.`DESC_PL`, z.`DESC`) as nazwa
+              , z.`OPIS` as opis
+              , z.A_RECORD_CREATE_AUTHOR
+              , z.A_RECORD_CREATE_DATE
+              , z.A_RECORD_UPDATE_AUTHOR
+              , z.A_RECORD_UPDATE_DATE
+            from `CRM_LISTA_ZASOBOW` z
+            where z.PARENT_ID = {$idMainDatabase}
+              and z.`TYPE` = 'TABELA'
+              and z.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
+          ")
+        )
+        , array_map(
+          function ($typeName) {
+            $namespace = str_replace(':', '/', $typeName);
+            $namespace = str_replace('__x3A__', '/', $namespace);
+            return [
+              'ID' => $this->_generateUniqueKeyFromNamespace($namespace),
+              'namespace' => $namespace,
+              'tabela' => '', // TODO: $acl->getRootTableName(),
+              'nazwa' => substr($typeName, strrpos($typeName, ':') + 1),
+              'opis' => '...',
+              'A_RECORD_CREATE_AUTHOR' => '',
+              'A_RECORD_CREATE_DATE' => '',
+              'A_RECORD_UPDATE_AUTHOR' => '',
+              'A_RECORD_UPDATE_DATE' => ''
+            ];
+          }
+          , Core_AclHelper::getAclList()
+        )
+      )
+      , function ($item) use ($params) {
+        return true;
+      }
+    );
+    return $_cacheAllItems;
+  }
+
+}