idDatabase = $idDatabase; $this->tblName = strtolower($tblName); $this->_types = array(); $this->_restrictions = array(); $this->initTypes(); } public function initTypes() {// TODO: override // parent::initTypes();// always call parent method // example: $this->_types['WWW'] = 'p5:www_link'; // example: $this->_restrictions['WWW'] = ['maxLength' => 255] // TODO:? $this->_types['WWW'] = new Type_Link($params = ['maxLength' => 255, ...]); } public function getType($fieldName) { return V::get($fieldName, '', $this->_types); } public function fixTypes($types) { if (empty($this->_types)) return $types; foreach ($types as $fldName => $type) { if (array_key_exists($fldName, $this->_types)) { $types[$fldName]['simpleType'] = $this->_types[$fldName]; } if (array_key_exists($fldName, $this->_restrictions)) { $types[$fldName]['restrictions'] = $this->_restrictions[$fldName]; } // TODO: add default xsdElementType('simpleType', 'complexType'), xsdType(p5Type:...), ... for every field } return $types; } public function getStruct() { if (!empty($this->_struct)) return $this->_struct; $storage = DB::getStorage($this->idDatabase); $struct = $storage->getTableStruct($this->tblName); $this->_struct = $struct; foreach ($this->_struct as $fldName => $field) { $this->_struct[$fldName] = $this->convertStorageTypeToXsdP5Type($storage->getType(), $field); } return $this->_struct; } public function convertStorageTypeToXsdP5Type($storageType, $field) { /* cat SE/schema/types.xsd |grep 'xs:simpleType name=' */ $field['p5_isComplexType'] = false; $field['p5_type'] = 'unknown';// TODO: default type or leave undefined? $field['p5_restrictions'] = array(); $field['p5_props'] = array(); if ('mysql' == $storageType) { switch ($field['type']) { case 'tinyint': case 'smallint': case 'bigint': case 'int': { $field['p5_type'] = 'integer'; } break; case 'decimal': { $field['p5_type'] = $field['type']; } break; case 'float': case 'double': { $field['p5_type'] = $field['type']; } break; case 'char': case 'varchar': { $field['p5_type'] = 'string'; } break; case 'mediumtext': case 'longtext': case 'text': { $field['p5_type'] = $field['type']; } break; case 'datetime': { $field['p5_type'] = 'dateTime'; } break; case 'date': { $field['p5_type'] = $field['type']; } break; case 'year': { $field['p5_type'] = $field['type']; } break; case 'time': { $field['p5_type'] = $field['type']; } break; case 'timestamp': { $field['p5_type'] = 'integer'; } break; case 'point': case 'polygon': case 'geometry': { $field['p5_type'] = $field['type']; } break; case 'linestring': { $field['p5_type'] = 'lineString'; } break; case 'multipoint': { $field['p5_type'] = 'multiPoint';// TODO: create multiPoint in types.xsd } break; case 'multipolygon': { $field['p5_type'] = 'multiPolygon';// TODO: create multiPolygon in types.xsd } break; case 'multilinestring': { $field['p5_type'] = 'multiLineString';// TODO: create multiLineString in types.xsd } break; case 'enum': { $field['p5_type'] = 'string'; $enumValues = substr($field['raw_storage_type'], 6, -2);// "enum('R','W','X','C')" $enumValues = explode("','", $enumValues); $field['p5_restrictions']['enumeration'] = $enumValues; } break; case 'set': { $field['p5_type'] = 'set'; $enumValues = substr($field['raw_storage_type'], 5, -2);// "set('R','W','X','C')" $enumValues = explode("','", $enumValues); // TODO: enumerations with all combinations // $baseComb = array(); foreach ($enumValues as $enumValue) { if ('' !== $enumValue) $baseComb[] = $enumValue; }; // $sizeCombinations = count($baseComb); // $allComb = pow(2, $sizeCombinations); // //DBG::_(true, true, "baseCombinations", $baseComb, __CLASS__, __FUNCTION__, __LINE__); // for ($b = 1; $b < $allComb; $b++) { // $curValues = array(); // $valBinary = sprintf("%0{$sizeCombinations}b", $b); // $binValues = str_split($valBinary); // //DBG::_(true, true, "curValues({$b}/{$valBinary})", $curValues, __CLASS__, __FUNCTION__, __LINE__); // foreach ($binValues as $idx => $isSet) { // if ($isSet) $curValues[] = $baseComb[$idx]; // } // $enumValues[] = implode(",", $curValues); // } //$field['p5_restrictions']['enumeration'] = $enumValues;// TODO: use p5_props $field['p5_props']['multiple_enumeration'] = $enumValues;// TODO: use p5_props } break; case 'tinyblob': case 'mediumblob': case 'longblob': case 'blob': case 'binary': case 'varbinary': { $field['p5_type'] = 'hexBinary'; } break; default: DBG::_(true, true, "TODO: storageType({$storageType}) field({$field['name']})", $field, __CLASS__, __FUNCTION__, __LINE__); } } else if ('pgsql' == $storageType) { } else { } return $field; } public function getPrimaryKeyField() {// TODO: use this method in TableAcl, Data_Source, etc. return 'ID'; } public function fixItemFieldValue($fieldName, /* array */ $item) { return $value; } public function getFieldParam($fieldName, $paramKey) { return (empty($this->_params[$fieldName])) ? null : (empty($this->_params[$fieldName][$paramKey])) ? null : $this->_params[$fieldName][$paramKey] ; } }