/** * @param ConfigManager $settings * @param RequestModel $model * @return string */ public static function getTableCreateQuery($settings, $model) { $cols = $model->getFlatColumnsDbTypes(); $uniqArr = $model->getUniques(); $uniColsStr = ''; foreach ($uniqArr as $uniKey) { $uniColsStr = $uniColsStr . ', UNIQUE INDEX `' . $uniKey . '_UNIQUE` (`' . $uniKey . '` ASC)'; } $colsStr = ''; foreach ($cols as $col => $type) { $colsStr = $colsStr . '`' . $col . '` ' . $type . ','; } $q = self::$CREATE_TABLE_QUERY_MODEL; $q = str_replace('<identifier>', self::getDbTableIdentifier($settings, $model), $q); $q = str_replace('<fields>', $colsStr, $q); $q = str_replace('<uniqueIndexes>', $uniColsStr, $q); return $q; }
public function serializeResponse($data) { $struct = $this->getModel()->getFlatTypes(); $modelName = $this->getModel()->getName(); $retData = array(); foreach ($data as $item) { foreach ($item as $k => $val) { if (array_key_exists($k, $struct)) { if (str_contains($struct[$k], Model::DATETIME) && $val === '0000-00-00 00:00:00') { $retItem[$k] = null; } else { if (str_contains($struct[$k], Model::BOOLEAN)) { if ($val === 1 || $val === '1') { $retItem[$k] = true; } else { $retItem[$k] = false; } } else { if (str_contains($struct[$k], Model::INTEGER) && ($val !== null || $val !== '')) { $retItem[$k] = intval($val); } else { if (str_contains($struct[$k], Model::DECIMAL) && ($val !== null || $val !== '')) { $retItem[$k] = floatval($val); } else { $retItem[$k] = $val; } } } } } } $retData[] = $retItem; } $res = json_decode(json_encode($this->json), true); unset($res['content']); $res['collection'] = []; foreach ($retData as $item) { $res['collection'][] = RequestModel::treeFromFlat($item); } return json_encode($res, JSON_PRETTY_PRINT); }