Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find other solution for editable lists or disable it #170

Open
schmunk42 opened this issue Sep 17, 2016 · 4 comments
Open

find other solution for editable lists or disable it #170

schmunk42 opened this issue Sep 17, 2016 · 4 comments

Comments

@schmunk42
Copy link
Owner

@uldisn I needed to remove this from the model-extended template.
The template file should not contain any logic.

You can add this via baseModelTraits now.

Related #164


    public static $listBoxData;

<?php if (isset($translation)): ?>
    /**
     * create array for listbox
     * @param boolean $forValue list hidded elements
     * @return type
     */
    public static function forListbox($forValue = false)
    {

        if (self::$listBoxData){
            return self::$listBoxData;
        }    

        $query = self::find()
                ->select('`<?=$tableName?>`.`<?=$tableSchema->primaryKey[0]?>` `id`, `lang`.`<?=$translation['fields'][0]?>`  `name`')
                ->leftJoin('`<?=$translation['language_table']?>`  lang ', '<?=$tableName?>.`<?=$tableSchema->primaryKey[0]?>` = lang.<?=$tableName?>_id and lang.language = "'.Yii::$app->language.'" ')                
                ->orderBy('`lang`.`<?=$translation['fields'][0]?>`');

//        if (!$forValue) {
//            $query->where(['hidded' => 0]);
//        }

        $rows = $query->asArray()->all();

        return self::$listBoxData = \yii\helpers\ArrayHelper::map($rows,'id', 'name');        
    }        
<?php endif; ?>

<?php if (!isset($translation)): ?>
    /**
     * create array for listbox
     * @param boolean $forValue list hidded elements
     * @return type
     */    
    public static function forListbox($forValue = false)
    {

        if (self::$listBoxData){
            return self::$listBoxData;
        }

        $query = self::find()
                ->select('`<?=$tableSchema->primaryKey[0]?>` `id`, `name`')
                //->where(['hidded' => 0])
                ->orderBy('`name`');

//        if (!$forValue) {
//            $query->where(['hidded' => 0]);
//        }                

        $rows = $query->asArray()->all();

        return self::$listBoxData = \yii\helpers\ArrayHelper::map($rows,'id', 'name');        
    }        
<?php endif; ?>
@uldisn
Copy link
Contributor

uldisn commented Sep 18, 2016

I wrote function forListbox() in extended module, because in follow part need set correct column names:

                ->select('`<?=$tableSchema->primaryKey[0]?>` `id`, `name`')
                //->where(['hidded' => 0])
                ->orderBy('`name`');

@uldisn
Copy link
Contributor

uldisn commented Sep 18, 2016

If add to generator additional parameter "LabelField", forListbox() can move to base model and add method itemLabel().

Method forListbox() can use also in forms instead relation listboxs.

@schmunk42
Copy link
Owner Author

I'd like to limit the number of parameters of the generator, if possible I'd even reduce them.

You can easily add functions to generated classes with traits, work for models and controllers now.
With the above code you may create a ListboxModelTrait. In the model generator set baseTraits to my\namespace\ListboxModelTrait.

@uldisn
Copy link
Contributor

uldisn commented Sep 19, 2016

Limiting number of parameters no so actual, if use SaveForm.

Better way for listbox i see generating additional model - static model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants