SchemaReaderProcess.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. Lib::loadClass('User');
  3. Lib::loadClass('SchemaReader');
  4. class SchemaReaderProcess {
  5. private $_version;
  6. private $_date;
  7. private $_access = array();
  8. private $_accessGroups = array();
  9. private $_steps = array();
  10. private $_resourcesTable = array();
  11. private $_resources = array();
  12. public function __construct() {
  13. }
  14. public function parseIniConfig($config) {
  15. $configData = $config->getData();
  16. $this->_version = $config->get('version', 'CONFIG');
  17. $this->_date = $config->get('date', 'CONFIG');
  18. if('1' == V::get('DBG_SCH', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$configData (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($configData);echo'</pre>';}
  19. $configSections = array_keys($configData);
  20. if (in_array('ACCESS', $configSections)) {
  21. if (array_key_exists('HAS_ACCESS', $configData['ACCESS'])) {
  22. $this->_access = $configData['ACCESS']['HAS_ACCESS'];
  23. if (!is_array($this->_access)) $this->_access = array($this->_access);
  24. }
  25. if (array_key_exists('GROUPS', $configData['ACCESS'])) {
  26. $this->_accessGroups = $configData['ACCESS']['GROUPS'];
  27. if (!is_array($this->_accessGroups)) $this->_accessGroups = array($this->_accessGroups);
  28. }
  29. }
  30. $this->_steps = array();
  31. foreach ($configSections as $section) {
  32. if ('STEP' == substr($section, 0, 4)) {
  33. $sectionParts = explode(':', $section);
  34. $sectionPartsCnt = count($sectionParts);
  35. if ($sectionPartsCnt == 2) {// eg. [STEP:1]
  36. $stepNr = $sectionParts[1];
  37. $step = SchemaReader::buildProcessStepFromIni($stepNr, $configData[$section]);
  38. if ($step) {
  39. $this->_steps[$stepNr] = $step;
  40. }
  41. }
  42. }
  43. }
  44. if('1' == V::get('DBG_SCH', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$this->_steps:1 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_steps);echo'</pre>';}
  45. foreach ($configSections as $section) {
  46. if ('STEP' == substr($section, 0, 4)) {
  47. $sectionParts = explode(':', $section);
  48. $sectionPartsCnt = count($sectionParts);
  49. if ($sectionPartsCnt > 3) {// eg. [STEP:1:RESOURCE:1]
  50. $stepNr = $sectionParts[1];
  51. $resourceUri = V::get('uri', '', $configData[$section]);
  52. if (!$resourceUri) continue;
  53. $resource = SchemaReader::buildFromIni($resourceUri, $configData[$section]);
  54. if ($resource && array_key_exists($stepNr, $this->_steps)) {
  55. $this->_steps[$stepNr]->addResource($resource);
  56. }
  57. }
  58. }
  59. }
  60. if('1' == V::get('DBG_SCH', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">$this->_steps:2 (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_steps);echo'</pre>';}
  61. $this->_resourcesTable = array();
  62. foreach ($this->_steps as $step) {
  63. $stepTbls = $step->getTables();
  64. foreach ($stepTbls as $tblUri => $tbl) {
  65. if (array_key_exists($tblUri, $this->_resourcesTable)) {
  66. $this->_resourcesTable[$tblUri]->mergeFields($tbl);
  67. } else {
  68. $this->_resourcesTable[$tblUri] = $tbl;
  69. }
  70. }
  71. }
  72. if('1' == V::get('DBG_SCH', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;">this->_resourcesTable (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($this->_resourcesTable);echo'</pre>';}
  73. return true;
  74. }
  75. public function hasTables() {
  76. return !empty($this->_resourcesTable);
  77. }
  78. public function getTables() {
  79. return $this->_resourcesTable;
  80. }
  81. public function hasAccess() {
  82. if (!empty($this->_access)) {
  83. foreach ($this->_access as $accessName) {
  84. if (User::hasAccess($accessName)) {
  85. return true;
  86. }
  87. }
  88. }
  89. if (!empty($this->_accessGroups)) {
  90. foreach ($this->_accessGroups as $accessGroup) {
  91. if (User::hasGroup($accessGroup)) {
  92. return true;
  93. }
  94. }
  95. }
  96. return false;
  97. }
  98. }