OptionGroup.php 4.36 KB
<?php
    
    namespace artbox\catalog\models;
    
    use artbox\catalog\behaviors\ManyToManyBehavior;
    use artbox\core\behaviors\LanguageBehavior;
    use Yii;
    use yii\behaviors\TimestampBehavior;
    use yii\db\ActiveQuery;
    use yii\db\ActiveRecord;
    use yii\web\Request;
    
    /**
     * This is the abstract model class for option group models.
     *
     * @property integer           $id
     * @property boolean           $is_filter
     * @property integer           $sort
     * @property boolean           $status
     * @property boolean           $in_menu
     * @property integer           $created_at
     * @property integer           $updated_at
     * @property Category[]        $categories
     * @property Option[]          $options
     *      * From language behavior *
     * @property OptionGroupLang   $lang
     * @property OptionGroupLang[] $langs
     * @property OptionGroupLang   $objectLang
     * @property string            $ownerKey
     * @property string            $langKey
     * @property OptionGroupLang[] $modelLangs
     * @property bool              $transactionStatus
     * @method string           getOwnerKey()
     * @method void             setOwnerKey( string $value )
     * @method string           getLangKey()
     * @method void             setLangKey( string $value )
     * @method ActiveQuery      getLangs()
     * @method ActiveQuery      getLang( integer $language_id )
     * @method OptionGroupLang[]    generateLangs()
     * @method void             loadLangs( Request $request )
     * @method bool             linkLangs()
     * @method bool             saveLangs()
     * @method bool             getTransactionStatus()
     * @method bool             loadWithLangs( Request $request )
     * @method bool             saveWithLangs()
     *      * End language behavior *
     *      * From ManyToManyBehavior
     * @method void linkMany( string $name, array $models, array $extraColumns = [] )
     *      * End ManyToManyBehavior
     * @see LanguageBehavior
     */
    abstract class OptionGroup extends ActiveRecord
    {
        
        public $categoryIds = [];
        
        /**
         * @var Option[] $currentOptions Container for current options
         */
        public $currentOptions = [];
        
        /**
         * @inheritdoc
         */
        public function behaviors()
        {
            return [
                'language'  => [
                    'class' => LanguageBehavior::className(),
                ],
                'timestamp' => [
                    'class' => TimestampBehavior::className(),
                ],
                [
                    'class' => ManyToManyBehavior::className(),
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [
                    [
                        'is_filter',
                        'status',
                        'in_menu',
                    ],
                    'boolean',
                ],
                [
                    [
                        'sort',
                    ],
                    'integer',
                ],
            ];
        }
        
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'id'         => Yii::t('catalog', 'ID'),
                'is_filter'  => Yii::t('catalog', 'Is Filter'),
                'sort'       => Yii::t('catalog', 'Sort'),
                'status'     => Yii::t('catalog', 'Status'),
                'created_at' => Yii::t('catalog', 'Created At'),
                'updated_at' => Yii::t('catalog', 'Updated At'),
                'categories' => Yii::t('catalog', 'Categories'),
                'in_menu'    => Yii::t('catalog', 'In menu'),
            ];
        }
    
        /**
         * @param array $batch
         *
         * @return mixed
         */
        public abstract function insertCategories(array $batch);
        
        /**
         * ActiveQuery to get categories for exact model
         *
         * @return ActiveQuery
         */
        public abstract function getCategories();
        
        /**
         * ActiveQuery to get options for exact model
         *
         * @return ActiveQuery
         */
        public abstract function getOptions();
    }