<commit_before><?php

namespace extpoint\yii2\gii\generators\model;

use extpoint\yii2\gii\helpers\GiiHelper;
use yii\gii\CodeFile;
use yii\gii\Generator;
use yii\helpers\ArrayHelper;

class ModelGenerator extends Generator
{
    public $moduleId;
    public $modelName;
    public $tableName;
    public $meta = [];
    public $relations = [];

    public function getName() {
        return 'model';
    }

    public function requiredTemplates()
    {
        return ['meta', 'migrationCreate', 'migrationUpdate'];
    }

    /**
     * @inheritdoc
     */
    public function generate()
    {
        $moduleDir = \Yii::getAlias('@app') . '/' . str_replace('.', '/', $this->moduleId);

        // Create/update meta information
        (new CodeFile(
            $moduleDir . '/models/meta/' . ucfirst($this->modelName) . 'Meta.php',
            $this->render('meta.php', [
                'namespace' => 'app\\' . str_replace('.', '\\', $this->moduleId) . '\\models\\meta',
                'className' =>  ucfirst($this->modelName) . 'Meta',
                'tableName' => $this->tableName,
                'meta' => $this->meta,
                'relations' => array_map(function($relation) {
                    $relation['model'] = GiiHelper::getModelByClass($relation['relationModelClassName']);
                    return $relation;
                }, $this->relations),
            ])
        ))->save();
        \Yii::$app->session->addFlash('success', 'Мета информция модели ' . ucfirst($this->modelName) . ' обновлена');

        // Create model, if not exists
        $modelFilePath = $moduleDir . '/models/' . ucfirst($this->modelName) . '.php';
        if (!file_exists($modelFilePath)) {
            (new CodeFile(
                $moduleDir . '/models/' . ucfirst($this->modelName) . '2.php',
                $this->render('model.php', [
                    'namespace' => 'app\\' . str_replace('.', '\\', $this->moduleId) . '\\models',
                    'className' =>  ucfirst($this->modelName),
                    'tableName' => $this->tableName,
                    'meta' => $this->meta,
                ])
            ))->save();<commit_msg>fix meta & relations format from js widget<commit_after><?php

namespace extpoint\yii2\gii\generators\model;

use extpoint\yii2\gii\helpers\GiiHelper;
use yii\gii\CodeFile;
use yii\gii\Generator;
use yii\helpers\ArrayHelper;

class ModelGenerator extends Generator
{
    public $moduleId;
    public $modelName;
    public $tableName;
    public $meta = [];
    public $relations = [];

    public function getName() {
        return 'model';
    }

    public function requiredTemplates()
    {
        return ['meta', 'migrationCreate', 'migrationUpdate'];
    }

    /**
     * @inheritdoc
     */
    public function generate()
    {
        if (!is_array($this->meta)) {
            $this->meta = [];
        }
        if (!is_array($this->relations)) {
            $this->relations = [];
        }

        $moduleDir = \Yii::getAlias('@app') . '/' . str_replace('.', '/', $this->moduleId);

        // Create/update meta information
        (new CodeFile(
            $moduleDir . '/models/meta/' . ucfirst($this->modelName) . 'Meta.php',
            $this->render('meta.php', [
                'namespace' => 'app\\' . str_replace('.', '\\', $this->moduleId) . '\\models\\meta',
                'className' =>  ucfirst($this->modelName) . 'Meta',
                'tableName' => $this->tableName,
                'meta' => $this->meta,
                'relations' => array_map(function($relation) {
                    $relation['model'] = GiiHelper::getModelByClass($relation['relationModelClassName']);
                    return $relation;
                }, $this->relations),
            ])
        ))->save();
        \Yii::$app->session->addFlash('success', 'Мета информция модели ' . ucfirst($this->modelName) . ' обновлена');

        // Create model, if not exists
        $modelFilePath = $moduleDir . '/models/' . ucfirst($this->modelName) . '.php';
        if (!file_exists($modelFilePath)) {
            (new CodeFile(
                $moduleDir . '/models/' . ucfirst($this->modelName) . '2.php',
                $this->render('model.php', [
                    'namespace' => 'app\\' . str_replace('.', '\\', $this->moduleId) . '\\models',
                    'className' =>  ucfirst($this->modelName),
                    'tableName' => $this->tableName,
                    'meta' => $this->meta,
                ])
            ))->save();
{'fraction_non_alphanumeric': 0.1767431597528685, 'fraction_numerical': 0.001323918799646955, 'mean_word_length': 1.9113680154142583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7472919', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1313, 'n_words': 235}