ProductOptionCompl.php 3.9 KB
<?php
    
    namespace artbox\catalog\models;

    use artbox\core\models\Language;
    use yii\db\ActiveQuery;

    /**
     * This is the model class for table "product_option_compl".
     *
     * @property integer                        $product_option_group_compl_id
     *
     * @property ProductOptionGroupCompl        $productOptionGroupCompl
     * @property ProductOptionComplLang[]       $productOptionComplLangs
     * @property Language[]                     $languages
     * @property ProductOptionComplToCategory[] $productOptionComplToCategories
     * @property Category[]                     $categories
     * @property ProductToProductOptionCompl[]  $productToProductOptionCompls
     * @property Product[]                      $products
     */
    class ProductOptionCompl extends Option
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'product_option_compl';
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProductOptionGroupCompl()
        {
            return $this->hasOne(ProductOptionGroupCompl::className(), [ 'id' => 'product_option_group_compl_id' ])
                        ->inverseOf('productOptionCompls');
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProductOptionComplLangs()
        {
            return $this->hasMany(ProductOptionComplLang::className(), [ 'product_option_compl_id' => 'id' ])
                        ->inverseOf('productOptionCompl');
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getLanguages()
        {
            return $this->hasMany(Language::className(), [ 'id' => 'language_id' ])
                        ->viaTable('product_option_compl_lang', [ 'product_option_compl_id' => 'id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProductOptionComplToCategories()
        {
            return $this->hasMany(ProductOptionComplToCategory::className(), [ 'product_option_compl_id' => 'id' ])
                        ->inverseOf('productOptionCompl');
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getCategories()
        {
            return $this->hasMany(Category::className(), [ 'id' => 'category_id' ])
                        ->viaTable('product_option_compl_to_category', [ 'product_option_compl_id' => 'id' ]);
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProductToProductOptionCompls()
        {
            return $this->hasMany(ProductToProductOptionCompl::className(), [ 'product_option_compl_id' => 'id' ])
                        ->inverseOf('productOptionCompl');
        }
        
        /**
         * @return \yii\db\ActiveQuery
         */
        public function getProducts()
        {
            return $this->hasMany(Product::className(), [ 'id' => 'product_id' ])
                        ->viaTable('product_to_product_option_compl', [ 'product_option_compl_id' => 'id' ]);
        }
        /**
         * Get exact Option Group id value
         *
         * @return int|null
         */
        public function getGroupId()
        {
            return $this->product_option_group_compl_id;
        }
        /**
         * Set Option Group link to Option model
         *
         * @param int $id
         *
         * @return void
         */
        public function setGroupId(int $id)
        {
            $this->product_option_group_compl_id = $id;
        }
        /**
         * Get Group query
         *
         * @return \yii\db\ActiveQuery
         */
        public function getGroup(): ActiveQuery
        {
            return $this->getProductOptionGroupCompl()
                        ->inverseOf('options');
        }
    }