prepare(" select z.ID, z.TYPE, z.DESC, z.ALIAS_ID , c.ID as c_ID, c.TYPE as c_TYPE, c.DESC as c_DESC, c.ALIAS_ID as c_ALIAS_ID , a.ID as a_ID, a.TYPE as a_TYPE, a.DESC as a_DESC, a.ALIAS_ID as a_ALIAS_ID , za.ID as za_ID, za.TYPE as za_TYPE, za.DESC as za_DESC, za.ALIAS_ID as za_ALIAS_ID from CRM_LISTA_ZASOBOW z left join CRM_LISTA_ZASOBOW c on(c.PARENT_ID = z.ID) left join CRM_LISTA_ZASOBOW a on(a.ID = z.ALIAS_ID and z.ALIAS_ID > 0) left join CRM_LISTA_ZASOBOW za on(za.ID = c.ALIAS_ID and c.ALIAS_ID > 0) where z.PARENT_ID = 22444 -- TODO how to find ID, Typespecial with link "); $sth->execute(); $rawConf = $sth->fetchAll(); $conf = array(); $conf['type'] = array(); $conf['layer'] = array(); foreach ($rawConf as $z) { if ('INNE' == $z['TYPE']) { if (!array_key_exists($z['ID'], $conf['type'])) { $conf['type'][$z['ID']] = $z['DESC']; } } } foreach ($rawConf as $z) { if ('TABELA' == $z['TYPE']) { if (!array_key_exists($z['ID'], $conf['layer'])) { $layer = array(); $layer['label'] = $z['DESC']; $layer['tabela_id'] = $z['a_ID']; $layer['tabela_name'] = $z['a_DESC']; $layer['jednostka'] = ''; $layer['jednostka_zasob_id'] = array(); $layer['zasob_type'] = ''; $layer['zasob_field'] = ''; $layer['zasob_id'] = ''; $layer['ilosc_field'] = ''; $layer['type'] = array(); $conf['layer'][$z['ID']] = $layer; } if ($z['c_ID'] > 0) { if ('JEDNOSTKA_' == substr($z['c_DESC'], 0, 10)) { $layer = $conf['layer'][$z['ID']]; $layer['jednostka'] = substr($z['c_DESC'], 10); $layer['ilosc_field'] = $z['za_DESC']; $layer['zasob_id'] = $z['za_ID']; $conf['layer'][$z['ID']] = $layer; } /* [za_ID] => 20299 [za_TYPE] => KOMORKA [za_DESC] => OznKabla [za_ALIAS_ID] => 0 */ switch ($z['c_DESC']) { case 'ZASOB': { if ($z['za_ID'] > 0) { $layer = $conf['layer'][$z['ID']]; $layer['zasob_type'] = $z['c_DESC']; $layer['zasob_field'] = $z['za_DESC']; $layer['zasob_id'] = $z['za_ID']; $conf['layer'][$z['ID']] = $layer; } } break; case 'ZASOB_ID': { if ($z['za_ID'] > 0) { $layer = $conf['layer'][$z['ID']]; $layer['zasob_type'] = $z['c_DESC']; $layer['zasob_id'] = $z['za_ID']; $layer['zasob_label'] = $z['za_DESC']; $conf['layer'][$z['ID']] = $layer; $conf['layer'][$z['ID']]['type'][$z['za_ID']] = $z['za_DESC']; } } break; case 'TYPE': { //DBG::_(true, true, "z", $z, __CLASS__, __FUNCTION__, __LINE__); if (empty($z['c_ALIAS_ID'])) throw new Exception("Schema error - brak ALIAS_ID dla typu"); if (empty($conf['type'][$z['za_ID']])) ;// TODO: throw Exception("Brak typu w conf['type']") $conf['layer'][$z['ID']]['type'][$z['za_ID']] = $z['za_DESC']; } break; case 'TYPE_SZTUKA': { //DBG::_(true, true, "z", $z, __CLASS__, __FUNCTION__, __LINE__); if (empty($z['c_ALIAS_ID'])) throw new Exception("Schema error - brak ALIAS_ID dla typu"); if (empty($conf['type'][$z['za_ID']])) ;// TODO: throw Exception("Brak typu w conf['type']") $conf['layer'][$z['ID']]['jednostka_zasob_id'][$z['za_ID']] = 'SZTUKA'; } break; } } } } foreach ($rawConf as $z) { if ('INNE' == $z['TYPE']) { } else if ('TABELA' == $z['TYPE']) { } else { SE_Layout::alert('warnig', "BUG: unimplemented type '{$z['TYPE']}' for zasob nr: {$z['ID']}"); } } DBG::_('DBG', '>1', "config", $conf, __CLASS__, __FUNCTION__, __LINE__); {// validate schema - show warnings foreach ($conf['layer'] as $layer) { try { if (empty($layer['tabela_id'])) throw new Exception("brak zdefiniowanego aliasa do tabeli dla warstwy {$layer['label']}"); if (empty($layer['jednostka'])) throw new Exception("brak jednostki dla warstwy [{$layer['tabela_id']}] {$layer['label']}"); switch ($layer['jednostka']) { case 'METR': break; case 'SZTUKA': break; default: throw new Exception("Nieznana jednostka '{$layer['jednostka']}' dla warstwy [{$layer['tabela_id']}] {$layer['label']}"); } } catch (Exception $e) { SE_Layout::alert('warning', $e->getMessage()); } } } DBG::_('DBG', '>2', "rawConf", $rawConf, __CLASS__, __FUNCTION__, __LINE__); $_schema['config'] = $conf; } $_schema['nr'] = "Nr projektu"; $_schema['title'] = "Tytuł projektu"; $_schema['ownerName'] = "Osoba prowadząca"; $_schema['cost_total'] = "Szacowany koszt projektu [zł]"; return $_schema; } public static function getLayerJednostka($idLayer) { $schema = self::getSchema(); if (empty($schema['config']['layer'][$idLayer])) return null;// TODO: throw exception? return $schema['config']['layer'][$idLayer]['jednostka']; } }