schmunk42\giiant\generators\model\Generator::extractTranslations PHP Метод

extractTranslations() защищенный Метод

protected extractTranslations ( $tableName, $relations ) : array
$relations all database's relations
Результат array associative array containing the extracted relations and the modified translations
    protected function extractTranslations($tableName, $relations)
    {
        $langTableName = str_replace('{{table}}', $tableName, $this->languageTableName);
        if ($this->useTranslatableBehavior and isset($relations[$langTableName], $relations[$tableName])) {
            $db = $this->getDbConnection();
            $langTableSchema = $db->getTableSchema($langTableName);
            $langTableColumns = $langTableSchema->getColumnNames();
            $langTableKeys = array_merge($langTableSchema->primaryKey, array_map(function ($fk) {
                return array_keys($fk)[1];
            }, $langTableSchema->foreignKeys));
            $langClassName = $this->generateClassName($langTableName);
            foreach ($relations[$tableName] as $relationName => $relation) {
                list($code, $referencedClassName) = $relation;
                if ($referencedClassName === $langClassName) {
                    // found relation from model to modelLang.
                    // collect fields which are not PK, FK nor language code
                    $fields = [];
                    foreach ($langTableColumns as $columnName) {
                        if (!in_array($columnName, $langTableKeys) and strcasecmp($columnName, $this->languageCodeColumn) !== 0) {
                            $fields[] = $columnName;
                        }
                    }
                    unset($relations[$tableName][$relationName]);
                    return ['relations' => $relations, 'translations' => ['fields' => $fields, 'code' => $code, 'language_table' => $langTableName, 'language_table_pk' => $langTableSchema->primaryKey]];
                }
            }
        }
        return ['relations' => $relations, 'translations' => []];
    }