insert($ns['name'], $item); // TODO: check if has _HIST table $item['ID_USERS2'] = $id; DB::getPDO($idDatabase)->insert("{$ns['name']}_HIST", $item); return $id; } else if ('table_objects' == $ns['sourceName']) { return Core_AclHelper::getAclByNamespace($namespace)->addItem($item); } else if ('default_objects' == $ns['sourceName']) { return Core_AclHelper::getAclByNamespace($namespace)->addItem($item); } } public static function getAclByNamespace($namespace) { DBG::log("getAclByNamespace({$namespace})"); $objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, ['propertyName' => '*,field']); DBG::log($objectItem, 'array', "getAclByNamespace({$namespace})"); if ($objectItem['isStructInstalled']) { return self::buildAclFromSystemObject($objectItem, User::getID()); } throw new Exception("Object not installed '{$namespace}'"); } public static function buildAclFromSystemObject($objItem, $idUser) { if ('AntAcl' == $objItem['_type']) { Lib::loadClass('AntAclBase'); return AntAclBase::buildInstance($objItem['idZasob'], $objItem); } if ('TableAcl' == $objItem['_type']) { // $this->_db = $arr['db']; // $this->_name = $arr['name']; // $this->_rootTableName = V::get('_rootTableName', null, $arr); // $this->_label = $arr['label']; // $this->_opis = $arr['opis']; // $this->_fields = V::get('fields', array(), $arr); // $this->_virtualFieldsIdList = V::get('virtualFieldsIdList', array(), $arr); // $this->_types = V::get('types', array(), $arr); $idTable = $objItem['idZasob']; $tableConfig = [ 'db' => $objItem['idDatabase'], 'name' => $objItem['_rootTableName'], '_rootTableName' => $objItem['_rootTableName'], 'label' => '...', // TODO: fetch from Zasoby 'opis' => '...', // TODO: fetch from Zasoby 'fields' => [], // TODO: ... 'virtualFieldsIdList' => [], // TODO: fetch additional fields from Zasoby - or add this fields to Storage::reinstallObject action 'types' => [], // TODO: ... ]; foreach ($objItem['field'] as $field) { $fieldName = $field['fieldNamespace']; $tableConfig['fields'][$fieldName] = [ 'name' => $fieldName, 'xsdType' => $field['xsdType'], ]; } return TableAcl::buildInstance($idTable, $tableConfig); } throw new Exception("TODO: buildAclFromSystemObject - type = '{$objItem['_type']}'"); } public static function getAclById($id) { $sqlIdZasob = DB::getPDO()->quote($id, PDO::PARAM_INT); $zasobInfo = DB::getPDO()->fetchFirst(" select t.ID as id , t.`DESC` as name , t.DESC_PL as label , t.OPIS as description , d.ID as idDatabase from CRM_LISTA_ZASOBOW t join CRM_LISTA_ZASOBOW d on(d.ID = t.PARENT_ID) where t.`TYPE` = 'TABELA' and t.A_STATUS in('NORMAL','WAITING') and d.A_STATUS in('NORMAL','WAITING') and t.ID = {$sqlIdZasob} "); if (!$zasobInfo) throw new Exception("Obiekt Nr '{$i}' nie istnieje w bazie zasobów"); DBG::nicePrint($zasobInfo, '$zasobInfo'); if (false !== strpos($zasobInfo['name'], '/')) { $namespace = "{$zasobInfo['name']}"; } else { $sourceName = (DB::getPDO()->getZasobId() == $zasobInfo['idDatabase']) ? 'default_db' : "zasob_{$zasobInfo['idDatabase']}"; $namespace = "{$sourceName}/{$zasobInfo['name']}"; } $ns = Core_AclHelper::parseNamespaceUrl($namespace); DBG::nicePrint($ns, "P5::getAcl by idZasob({$id}) Namespace({$namespace})"); } public static function getAcl($arg) { if (is_numeric($arg)) {// $idZasob return self::getAclById($arg); } else if (is_string($arg)) {// $namespace $namespace = $arg; $ns = Core_AclHelper::parseNamespaceUrl($namespace); DBG::nicePrint($ns, "P5::getAcl by Namespace({$namespace}) TODO: find idZasob"); if ('default_db' == substr($ns['sourceName'], 0, strlen('default_db'))) { $idDatabase = DB::getPDO()->getZasobId(); } else if ('zasob_' == substr($ns['sourceName'], 0, strlen('zasob_'))) { // 'zasob_931', 'zasob_931__x3A__...' $idDatabase = substr($ns['sourceName'], strlen('zasob_')); if (false !== strpos($idDatabase, '_')) $idDatabase = substr($idDatabase, 0, strpos($idDatabase, '_')); DBG::nicePrint($idDatabase, "P5::getAcl by Namespace({$namespace}) TODO: find idZasob - \$idDatabase"); if (!$idDatabase || !is_numeric($idDatabase)) throw new Exception("Not implemented idDatabase({$idDatabase})"); } else { throw new Exception("Error Processing Request", 1); } $sqlObjectName = DB::getPDO()->quote($ns['name'], PDO::PARAM_STR); $zasobInfo = DB::getPDO()->fetchFirst(" select t.ID as id , t.`DESC` as name , t.DESC_PL as label , t.OPIS as description , d.ID as idDatabase from CRM_LISTA_ZASOBOW t join CRM_LISTA_ZASOBOW d on(d.ID = t.PARENT_ID) where t.`TYPE` = 'TABELA' and t.A_STATUS in('NORMAL','WAITING') and d.A_STATUS in('NORMAL','WAITING') and d.ID = {$idDatabase} and t.`DESC` = {$sqlObjectName} "); DBG::nicePrint($zasobInfo, "P5::getAcl by Namespace({$namespace}) DB({$idDatabase}) zasobInfo"); if (!$zasobInfo) {// try to install object } // $acl = User::getAcl()->getObjectAcl($ns['prefix'], $ns['name']); // $acl->init($forceTblAclInit); // return $acl; } throw new Exception("TODO: P5::getAcl L." . __LINE__); } }