Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: schmunk42/yii2-giiant
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.15.0-beta2
Choose a base ref
...
head repository: schmunk42/yii2-giiant
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Sep 7, 2021

  1. Copy the full SHA
    258bab4 View commit details
  2. Copy the full SHA
    acbe3b7 View commit details

Commits on Sep 20, 2021

  1. disable pluralization

    eluhr committed Sep 20, 2021
    Copy the full SHA
    f846803 View commit details

Commits on Oct 8, 2021

  1. Copy the full SHA
    780075d View commit details
  2. Copy the full SHA
    e98dc79 View commit details

Commits on Oct 11, 2021

  1. Copy the full SHA
    a4caba4 View commit details

Commits on Oct 12, 2021

  1. Copy the full SHA
    a3d439c View commit details

Commits on Oct 13, 2021

  1. Copy the full SHA
    77457e8 View commit details

Commits on Oct 20, 2021

  1. Fixed relation provider

    eluhr committed Oct 20, 2021
    Copy the full SHA
    10381a9 View commit details

Commits on Nov 4, 2021

  1. Copy the full SHA
    d57f308 View commit details

Commits on Dec 9, 2021

  1. Copy the full SHA
    c3d7fd8 View commit details

Commits on Dec 14, 2021

  1. updated controller

    eluhr committed Dec 14, 2021
    Copy the full SHA
    667f8e2 View commit details

Commits on Jan 20, 2022

  1. Grid max columns

    eluhr committed Jan 20, 2022
    Copy the full SHA
    d2a659f View commit details

Commits on Jan 24, 2022

  1. Merge commit '1dbc6ede1e69d0a1d5064f8826fa2f2961d93b23' into feature/…

    …gabo
    
    # Conflicts:
    #	src/generators/crud/default/views/view.php - FIXED -
    eluhr committed Jan 24, 2022
    Copy the full SHA
    1def178 View commit details
  2. Copy the full SHA
    0e3376a View commit details

Commits on Feb 1, 2022

  1. removed not needed code

    eluhr committed Feb 1, 2022
    Copy the full SHA
    813ccb4 View commit details

Commits on Feb 22, 2022

  1. Copy the full SHA
    b4a80b9 View commit details
  2. Copy the full SHA
    6a2bc96 View commit details

Commits on Mar 23, 2023

  1. merge with parent method calls

    eluhr committed Mar 23, 2023
    Copy the full SHA
    f2352c7 View commit details

Commits on Mar 24, 2023

  1. Copy the full SHA
    6c539d7 View commit details
  2. Copy the full SHA
    890f9e9 View commit details
  3. Copy the full SHA
    40c195b View commit details
  4. cleanup controller

    eluhr committed Mar 24, 2023
    Copy the full SHA
    08bd2a5 View commit details
  5. Copy the full SHA
    47bf621 View commit details
  6. Copy the full SHA
    51972d6 View commit details
  7. Copy the full SHA
    059de44 View commit details
  8. Copy the full SHA
    9cdfdeb View commit details
  9. call static method

    eluhr committed Mar 24, 2023
    Copy the full SHA
    e5579bc View commit details

Commits on Mar 25, 2023

  1. no meta search

    eluhr committed Mar 25, 2023
    Copy the full SHA
    9dd40b6 View commit details

Commits on Mar 27, 2023

  1. Copy the full SHA
    b5dd8ee View commit details
  2. fixed relation column name

    eluhr committed Mar 27, 2023
    Copy the full SHA
    4cd779f View commit details
  3. simplify form view(s)

    eluhr committed Mar 27, 2023
    Copy the full SHA
    f33a31c View commit details

Commits on Jan 4, 2024

  1. Copy the full SHA
    86aeff6 View commit details
  2. Merge commit 'f33a31c10cbb709d06c4c407e877288e179fbe63' into feature/…

    …dev-elias
    
    # Conflicts:
    #	src/commands/BatchController.php - resolved -
    #	src/generators/crud/default/controller-rest.php - resolved -
    #	src/generators/crud/default/controller.php - resolved -
    eluhr committed Jan 4, 2024
    Copy the full SHA
    ea3447b View commit details
  3. small cleanups

    eluhr committed Jan 4, 2024
    Copy the full SHA
    a20f236 View commit details
  4. Copy the full SHA
    16dae88 View commit details
  5. use getters

    eluhr committed Jan 4, 2024
    Copy the full SHA
    633c6e9 View commit details
  6. remove overhead

    eluhr committed Jan 4, 2024
    Copy the full SHA
    56cb77f View commit details
  7. Copy the full SHA
    8850223 View commit details
  8. Copy the full SHA
    3eff8bd View commit details

Commits on Jan 29, 2024

  1. Copy the full SHA
    c69b994 View commit details
  2. Fixed access definitions

    eluhr committed Jan 29, 2024
    Copy the full SHA
    3b4b63a View commit details

Commits on Jan 30, 2024

  1. Copy the full SHA
    5d9faae View commit details

Commits on Jan 31, 2024

  1. Copy the full SHA
    98f4794 View commit details

Commits on Feb 6, 2024

  1. allow list crud

    eluhr committed Feb 6, 2024
    Copy the full SHA
    c8a1f1e View commit details

Commits on Feb 12, 2024

  1. Copy the full SHA
    2e2eb45 View commit details

Commits on Mar 25, 2024

  1. fix label in forms

    eluhr committed Mar 25, 2024
    Copy the full SHA
    53c7802 View commit details

Commits on Mar 26, 2024

  1. Copy the full SHA
    db9af44 View commit details
  2. Created GH-action

    schmunk42 authored Mar 26, 2024
    Copy the full SHA
    57de9eb View commit details
  3. Copy the full SHA
    246087a View commit details
Showing with 1,131 additions and 700 deletions.
  1. +27 −0 .github/workflows/docker-image.yml
  2. +6 −1 CHANGELOG.md
  3. +44 −5 src/commands/BatchController.php
  4. +109 −9 src/generators/crud/Generator.php
  5. +21 −15 src/generators/crud/ModelTrait.php
  6. +3 −3 src/generators/crud/callbacks/devgroup/Jsoneditor.php
  7. +3 −3 src/generators/crud/callbacks/dmstr/Pages.php
  8. +4 −2 src/generators/crud/callbacks/yii/Html.php
  9. +4 −4 src/generators/crud/default/access_definition.php
  10. +5 −3 src/generators/crud/default/controller-extended.php
  11. +33 −20 src/generators/crud/default/controller-rest.php
  12. +157 −172 src/generators/crud/default/controller.php
  13. +10 −10 src/generators/crud/default/migration_access.php
  14. +15 −4 src/generators/crud/default/search.php
  15. +35 −0 src/generators/crud/default/views/_form-fields.php
  16. +12 −58 src/generators/crud/default/views/_form.php
  17. +2 −2 src/generators/crud/default/views/_search.php
  18. +3 −3 src/generators/crud/default/views/create.php
  19. +42 −42 src/generators/crud/default/views/index.php
  20. +3 −3 src/generators/crud/default/views/update.php
  21. +105 −71 src/generators/crud/default/views/view.php
  22. +4 −4 src/generators/crud/editable/access_definition.php
  23. +1 −1 src/generators/crud/editable/controller-rest.php
  24. +36 −36 src/generators/crud/editable/controller.php
  25. +10 −10 src/generators/crud/editable/migration_access.php
  26. +3 −3 src/generators/crud/editable/views/_form.php
  27. +3 −3 src/generators/crud/editable/views/create.php
  28. +7 −7 src/generators/crud/editable/views/index.php
  29. +3 −3 src/generators/crud/editable/views/update.php
  30. +14 −14 src/generators/crud/editable/views/view.php
  31. +3 −1 src/generators/crud/providers/core/CallbackProvider.php
  32. +1 −1 src/generators/crud/providers/core/OptsProvider.php
  33. +44 −28 src/generators/crud/providers/core/RelationProvider.php
  34. +1 −1 src/generators/crud/providers/extensions/DateProvider.php
  35. +1 −1 src/generators/crud/providers/extensions/DateTimeProvider.php
  36. +5 −5 src/generators/crud/providers/extensions/EditorProvider.php
  37. +4 −4 src/generators/extension/default/Bootstrap.php
  38. +185 −38 src/generators/model/Generator.php
  39. +0 −21 src/generators/model/default/model-extended.php
  40. +111 −61 src/generators/model/default/model.php
  41. +8 −25 src/generators/model/default/query.php
  42. +41 −0 src/generators/model/default/translation-trait.php
  43. +3 −3 tests/Makefile
27 changes: 27 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Codeception Tests
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: |
git fetch --unshallow
cd tests
make all
make test
- name: 'Upload Test Report'
uses: actions/upload-artifact@v4
with:
path: tests/_output
retention-days: 7
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
Changelog
=========

### 1.0.0-beta
### 1.0.1

- Cancel url in create form now points to overview
- Fix bug in Html provider for type string

### 1.0.0

- do not use auto-pluralization in views, pluralize via I18N
- Improved model generation performance (see`modelCacheRelationsData`)
49 changes: 44 additions & 5 deletions src/commands/BatchController.php
Original file line number Diff line number Diff line change
@@ -161,6 +161,16 @@ class BatchController extends Controller
*/
public $enableI18N = true;

/**
* @var bool whether to enable or disable the pluralization of the models name
*/
public $disablePluralization = false;

/**
* @var string prefix to prepend to the many many relation methods
*/
public $modelManyManyRelationSuffix = '';

/**
* @var bool whether the entity names will be singular or the same as the table name
*/
@@ -299,13 +309,26 @@ class BatchController extends Controller
* @var bool This indicates whether the generator should generate attribute hints by using the comments of the corresponding DB columns
*/
public $modelGenerateHintsFromComments = true;

/**
* @var bool Generate Relations from Current Schema
*/
public $modelGenerateRelationsFromCurrentSchema = true;

public $modelTranslationTableAdditions = ['name' => 'meta', 'fallbackLanguage' => false];

/**
* Whether the copy functionality for a crud should be created or not
*/
public $crudEnableCopy = true;

/**
* @var array application configuration for creating temporary applications
*/
protected $appConfig;

/**
* @var instance of class schmunk42\giiant\generators\model\Generator
* @var \schmunk42\giiant\generators\model\Generator instance of class schmunk42\giiant\generators\model\Generator
*/
protected $modelGenerator;

@@ -345,6 +368,8 @@ public function options($id)
'modelRemoveDuplicateRelations',
'modelCacheRelationsData',
'modelGenerateRelations',
'modelGenerateRelationsFromCurrentSchema',
'modelTranslationTableAdditions',
'modelGenerateJunctionRelationMode',
'modelGenerateQuery',
'modelQueryNamespace',
@@ -367,7 +392,9 @@ public function options($id)
'crudOverwriteSearchModelClass',
'crudOverwriteRestControllerClass',
'crudOverwriteControllerClass',
'generateAccessFilterMigrations'
'generateAccessFilterMigrations',
'disablePluralization',
'crudEnableCopy'
]
);
}
@@ -463,13 +490,17 @@ public function actionModels()
'removeDuplicateRelations' => $this->modelRemoveDuplicateRelations,
'cacheRelationsData' => $this->modelCacheRelationsData,
'generateRelations' => $this->modelGenerateRelations,
'generateRelationsFromCurrentSchema' => $this->modelGenerateRelationsFromCurrentSchema,
'translationTableAdditions' => $this->modelTranslationTableAdditions,
'generateJunctionRelationMode' => $this->modelGenerateJunctionRelationMode,
'tableNameMap' => $this->tableNameMap,
'generateQuery' => $this->modelGenerateQuery,
'queryNs' => $this->modelQueryNamespace,
'queryBaseClass' => $this->modelQueryBaseClass,
'generateLabelsFromComments' => $this->modelGenerateLabelsFromComments,
'generateHintsFromComments' => $this->modelGenerateHintsFromComments,
'disablePluralization' => $this->disablePluralization,
'manyManyRelationSuffix' => $this->modelManyManyRelationSuffix
];
$route = 'gii/giiant-model';

@@ -540,6 +571,9 @@ public function actionCruds()
'gridMaxColumns' => $this->crudGridMaxColumns,
'generateAccessFilterMigrations' => $this->generateAccessFilterMigrations,
'actionButtonColumnPosition' => $this->crudActionButtonColumnPosition,
'disablePluralization' => $this->disablePluralization,
'gridMaxColumns' => $this->crudGridMaxColumns,
'enableCopy' => $this->crudEnableCopy
];
$route = 'gii/giiant-crud';
$app = \Yii::$app;
@@ -612,9 +646,14 @@ private function closeTempAppConnections(Application $app)
// since we don't know if there are any other than the "known" modelDb
if (isset($app->components)) {
foreach ($app->components as $cid => $component) {
$cObj = $app->get($cid);
if ($cObj instanceof \yii\db\Connection) {
$cObj->close();
try {
$cObj = $app->get($cid);
if ($cObj instanceof \yii\db\Connection) {
$cObj->close();
}
} catch (\Throwable $e) {
// ignore because we don't know if the component is a db connection
Yii::warning($e->getMessage());
}
}
}
118 changes: 109 additions & 9 deletions src/generators/crud/Generator.php
Original file line number Diff line number Diff line change
@@ -138,6 +138,11 @@ class Generator extends \yii\gii\generators\crud\Generator
*/
public $fixOptions = '';

/**
* @var bool whether to enable or disable the pluralization of the models name
*/
public $disablePluralization = false;

/**
* @var string form field for selecting and loading saved gii forms
*/
@@ -158,6 +163,10 @@ class Generator extends \yii\gii\generators\crud\Generator

private $_p = [];

public $translateRelations = ['translation', 'translation_meta'];

public $enableCopy = true;

/**
* {@inheritdoc}
*/
@@ -230,6 +239,7 @@ public function rules()
'generateAccessFilterMigrations',
'singularEntities',
'modelMessageCategory',
'enableCopy'
],
'safe',
],
@@ -270,6 +280,7 @@ public function formAttributes()
'accessFilter',
'singularEntities',
'modelMessageCategory',
'enableCopy'
];
}

@@ -305,20 +316,20 @@ public function getControllerID()
public function getModuleId()
{
if (!$this->moduleNs) {
$controllerNs = \yii\helpers\StringHelper::dirname(ltrim($this->controllerClass, '\\'));
$this->moduleNs = \yii\helpers\StringHelper::dirname(ltrim($controllerNs, '\\'));
$controllerNs = StringHelper::dirname(ltrim($this->controllerClass, '\\'));
$this->moduleNs = StringHelper::dirname(ltrim($controllerNs, '\\'));
}

return \yii\helpers\StringHelper::basename($this->moduleNs);
return StringHelper::basename($this->moduleNs);
}

public function generate()
{
$accessDefinitions = require $this->getTemplatePath().'/access_definition.php';

$this->controllerNs = \yii\helpers\StringHelper::dirname(ltrim($this->controllerClass, '\\'));
$this->moduleNs = \yii\helpers\StringHelper::dirname(ltrim($this->controllerNs, '\\'));
$controllerName = substr(\yii\helpers\StringHelper::basename($this->controllerClass), 0, -10);
$this->controllerNs = StringHelper::dirname(ltrim($this->controllerClass, '\\'));
$this->moduleNs = StringHelper::dirname(ltrim($this->controllerNs, '\\'));
$controllerName = substr(StringHelper::basename($this->controllerClass), 0, -10);

if ($this->singularEntities) {
$this->modelClass = Inflector::singularize($this->modelClass);
@@ -345,7 +356,7 @@ public function generate()
}

$files[] = new CodeFile($baseControllerFile, $this->render('controller.php', ['accessDefinitions' => $accessDefinitions]));
$params['controllerClassName'] = \yii\helpers\StringHelper::basename($this->controllerClass);
$params['controllerClassName'] = StringHelper::basename($this->controllerClass);

if ($this->overwriteControllerClass || !is_file($controllerFile)) {
$files[] = new CodeFile($controllerFile, $this->render('controller-extended.php', $params));
@@ -365,12 +376,32 @@ public function generate()
$viewPath = $this->getViewPath();
$templatePath = $this->getTemplatePath().'/views';

$model = Yii::createObject($this->modelClass);
if (array_key_exists('crud-form', $model->scenarios())) {
$model->setScenario('crud-form');
} else {
$model->setScenario('crud');
}

$safeAttributes = $model->safeAttributes();
if (empty($safeAttributes)) {
$model->setScenario('default');
$safeAttributes = $model->safeAttributes();
}
if (empty($safeAttributes)) {
$safeAttributes = $model::getTableSchema()->columnNames;
}

foreach (scandir($templatePath) as $file) {
if (empty($this->searchModelClass) && $file === '_search.php') {
if ($file === '_search.php' && !$this->getRenderWithSearch()) {
continue;
}
if (is_file($templatePath.'/'.$file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$files[] = new CodeFile("$viewPath/$file", $this->render("views/$file", ['permisions' => $permisions]));
$files[] = new CodeFile("$viewPath/$file", $this->render("views/$file", [
'model' => $model,
'safeAttributes' => $safeAttributes,
'accessDefinitions' => $accessDefinitions
]));
}
}

@@ -462,4 +493,73 @@ public function var_export54($var, $indent = '')
return var_export($var, true);
}
}

/**
* @return array
* @throws \yii\base\InvalidConfigException
*/
public function generateSearchRules()
{

$rules = parent::generateSearchRules();
$model = \Yii::createObject($this->modelClass);
foreach ($model->behaviors() as $key => $behavior) {
if (!empty($behavior['translationAttributes'])) {
$rules[] = "[['" . implode("', '", $behavior['translationAttributes']) . "'], 'safe']";
}
}
return $rules;
}

/**
* @return array
* @throws \yii\base\InvalidConfigException
*/
public function generateSearchConditions()
{

$searchConditions = parent::generateSearchConditions();
$model = \Yii::createObject($this->modelClass);
foreach ($model->behaviors() as $key => $behavior) {
if (!empty($behavior['translationAttributes'])) {
foreach ($behavior['translationAttributes'] as $translationAttribute) {
$searchConditions[] = "\$query->andFilterWhere(['like','{$translationAttribute}', \$this->$translationAttribute]);";
}
}
}
return $searchConditions;
}


/**
* @return array
*/
public function getTranslationRelationModels()
{
$translationRelationModels = [];
foreach ($this->translateRelations as $translateRelation) {
$translationRelationModels[] = $this->modelClass . Inflector::camelize($translateRelation);
}
return $translationRelationModels;
}

/**
* @return string
*/
public function getTranslationModelClass() {
return '\\' . $this->modelClass . Inflector::camelize('translation');
}

/**
* @return bool
* @throws \yii\base\InvalidConfigException
*/
public function getHasTranslationRelation() {
return isset(\Yii::createObject($this->modelClass)->behaviors()['translation']);
}

public function getRenderWithSearch()
{
return $this->indexWidgetType !== 'grid' && $this->searchModelClass !== '';
}
}
Loading