| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- Lib::loadClass('Core_AclHelper');
- Lib::loadClass('TableAcl');
- Lib::loadClass('SchemaFactory');
- /**
- * Zasoby:
- * DATABASE
- * TABELA
- * KOMORKA
- */
- class P5 {
- public static function insert($namespace, $item) {
- $ns = Core_AclHelper::parseNamespace($namespace);
- $idDatabase = Core_AclHelper::getIdDatabaseFromNamespace($namespace);
- if ('default_db' == $ns['sourceName']) {
- // TODO: check if has A_RECORD_CREATE_AUTHOR field
- if (empty($item['A_RECORD_CREATE_AUTHOR'])) $item['A_RECORD_CREATE_AUTHOR'] = User::getLogin();
- // TODO: check if has A_RECORD_CREATE_DATE field
- if (empty($item['A_RECORD_CREATE_DATE'])) $item['A_RECORD_CREATE_DATE'] = 'NOW()';
- $id = DB::getPDO($idDatabase)->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__);
- }
- }
|