P5.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. Lib::loadClass('Core_AclHelper');
  3. Lib::loadClass('TableAcl');
  4. Lib::loadClass('SchemaFactory');
  5. /**
  6. * Zasoby:
  7. * DATABASE
  8. * TABELA
  9. * KOMORKA
  10. */
  11. class P5 {
  12. public static function insert($namespace, $item) {
  13. $ns = Core_AclHelper::parseNamespace($namespace);
  14. $idDatabase = Core_AclHelper::getIdDatabaseFromNamespace($namespace);
  15. if ('default_db' == $ns['sourceName']) {
  16. // TODO: check if has A_RECORD_CREATE_AUTHOR field
  17. if (empty($item['A_RECORD_CREATE_AUTHOR'])) $item['A_RECORD_CREATE_AUTHOR'] = User::getLogin();
  18. // TODO: check if has A_RECORD_CREATE_DATE field
  19. if (empty($item['A_RECORD_CREATE_DATE'])) $item['A_RECORD_CREATE_DATE'] = 'NOW()';
  20. $id = DB::getPDO($idDatabase)->insert($ns['name'], $item);
  21. // TODO: check if has _HIST table
  22. $item['ID_USERS2'] = $id;
  23. DB::getPDO($idDatabase)->insert("{$ns['name']}_HIST", $item);
  24. return $id;
  25. } else if ('table_objects' == $ns['sourceName']) {
  26. return Core_AclHelper::getAclByNamespace($namespace)->addItem($item);
  27. } else if ('default_objects' == $ns['sourceName']) {
  28. return Core_AclHelper::getAclByNamespace($namespace)->addItem($item);
  29. }
  30. }
  31. public static function getAclByNamespace($namespace) {
  32. DBG::log("getAclByNamespace({$namespace})");
  33. $objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace, ['propertyName' => '*,field']);
  34. DBG::log($objectItem, 'array', "getAclByNamespace({$namespace})");
  35. if ($objectItem['isStructInstalled']) {
  36. return self::buildAclFromSystemObject($objectItem, User::getID());
  37. }
  38. throw new Exception("Object not installed '{$namespace}'");
  39. }
  40. public static function buildAclFromSystemObject($objItem, $idUser) {
  41. if ('AntAcl' == $objItem['_type']) {
  42. Lib::loadClass('AntAclBase');
  43. return AntAclBase::buildInstance($objItem['idZasob'], $objItem);
  44. }
  45. if ('TableAcl' == $objItem['_type']) {
  46. // $this->_db = $arr['db'];
  47. // $this->_name = $arr['name'];
  48. // $this->_rootTableName = V::get('_rootTableName', null, $arr);
  49. // $this->_label = $arr['label'];
  50. // $this->_opis = $arr['opis'];
  51. // $this->_fields = V::get('fields', array(), $arr);
  52. // $this->_virtualFieldsIdList = V::get('virtualFieldsIdList', array(), $arr);
  53. // $this->_types = V::get('types', array(), $arr);
  54. $idTable = $objItem['idZasob'];
  55. $tableConfig = [
  56. 'db' => $objItem['idDatabase'],
  57. 'name' => $objItem['_rootTableName'],
  58. '_rootTableName' => $objItem['_rootTableName'],
  59. 'label' => '...', // TODO: fetch from Zasoby
  60. 'opis' => '...', // TODO: fetch from Zasoby
  61. 'fields' => [], // TODO: ...
  62. 'virtualFieldsIdList' => [], // TODO: fetch additional fields from Zasoby - or add this fields to Storage::reinstallObject action
  63. 'types' => [], // TODO: ...
  64. ];
  65. foreach ($objItem['field'] as $field) {
  66. $fieldName = $field['fieldNamespace'];
  67. $tableConfig['fields'][$fieldName] = [
  68. 'name' => $fieldName,
  69. 'xsdType' => $field['xsdType'],
  70. ];
  71. }
  72. return TableAcl::buildInstance($idTable, $tableConfig);
  73. }
  74. throw new Exception("TODO: buildAclFromSystemObject - type = '{$objItem['_type']}'");
  75. }
  76. public static function getAclById($id) {
  77. $sqlIdZasob = DB::getPDO()->quote($id, PDO::PARAM_INT);
  78. $zasobInfo = DB::getPDO()->fetchFirst("
  79. select t.ID as id
  80. , t.`DESC` as name
  81. , t.DESC_PL as label
  82. , t.OPIS as description
  83. , d.ID as idDatabase
  84. from CRM_LISTA_ZASOBOW t
  85. join CRM_LISTA_ZASOBOW d on(d.ID = t.PARENT_ID)
  86. where t.`TYPE` = 'TABELA'
  87. and t.A_STATUS in('NORMAL','WAITING')
  88. and d.A_STATUS in('NORMAL','WAITING')
  89. and t.ID = {$sqlIdZasob}
  90. ");
  91. if (!$zasobInfo) throw new Exception("Obiekt Nr '{$i}' nie istnieje w bazie zasobów");
  92. DBG::nicePrint($zasobInfo, '$zasobInfo');
  93. if (false !== strpos($zasobInfo['name'], '/')) {
  94. $namespace = "{$zasobInfo['name']}";
  95. } else {
  96. $sourceName = (DB::getPDO()->getZasobId() == $zasobInfo['idDatabase'])
  97. ? 'default_db'
  98. : "zasob_{$zasobInfo['idDatabase']}";
  99. $namespace = "{$sourceName}/{$zasobInfo['name']}";
  100. }
  101. $ns = Core_AclHelper::parseNamespaceUrl($namespace);
  102. DBG::nicePrint($ns, "P5::getAcl by idZasob({$id}) Namespace({$namespace})");
  103. }
  104. public static function getAcl($arg) {
  105. if (is_numeric($arg)) {// $idZasob
  106. return self::getAclById($arg);
  107. } else if (is_string($arg)) {// $namespace
  108. $namespace = $arg;
  109. $ns = Core_AclHelper::parseNamespaceUrl($namespace);
  110. DBG::nicePrint($ns, "P5::getAcl by Namespace({$namespace}) TODO: find idZasob");
  111. if ('default_db' == substr($ns['sourceName'], 0, strlen('default_db'))) {
  112. $idDatabase = DB::getPDO()->getZasobId();
  113. } else if ('zasob_' == substr($ns['sourceName'], 0, strlen('zasob_'))) {
  114. // 'zasob_931', 'zasob_931__x3A__...'
  115. $idDatabase = substr($ns['sourceName'], strlen('zasob_'));
  116. if (false !== strpos($idDatabase, '_')) $idDatabase = substr($idDatabase, 0, strpos($idDatabase, '_'));
  117. DBG::nicePrint($idDatabase, "P5::getAcl by Namespace({$namespace}) TODO: find idZasob - \$idDatabase");
  118. if (!$idDatabase || !is_numeric($idDatabase)) throw new Exception("Not implemented idDatabase({$idDatabase})");
  119. } else {
  120. throw new Exception("Error Processing Request", 1);
  121. }
  122. $sqlObjectName = DB::getPDO()->quote($ns['name'], PDO::PARAM_STR);
  123. $zasobInfo = DB::getPDO()->fetchFirst("
  124. select t.ID as id
  125. , t.`DESC` as name
  126. , t.DESC_PL as label
  127. , t.OPIS as description
  128. , d.ID as idDatabase
  129. from CRM_LISTA_ZASOBOW t
  130. join CRM_LISTA_ZASOBOW d on(d.ID = t.PARENT_ID)
  131. where t.`TYPE` = 'TABELA'
  132. and t.A_STATUS in('NORMAL','WAITING')
  133. and d.A_STATUS in('NORMAL','WAITING')
  134. and d.ID = {$idDatabase}
  135. and t.`DESC` = {$sqlObjectName}
  136. ");
  137. DBG::nicePrint($zasobInfo, "P5::getAcl by Namespace({$namespace}) DB({$idDatabase}) zasobInfo");
  138. if (!$zasobInfo) {// try to install object
  139. }
  140. // $acl = User::getAcl()->getObjectAcl($ns['prefix'], $ns['name']);
  141. // $acl->init($forceTblAclInit);
  142. // return $acl;
  143. }
  144. throw new Exception("TODO: P5::getAcl L." . __LINE__);
  145. }
  146. }