<?php
    /**
     * Created by PhpStorm.
     * User: stes
     * Date: 20.09.17
     * Time: 18:52
     */
    
    namespace common\models;
    
    use artbox\core\behaviors\BitMaskBehavior;
    use artbox\core\behaviors\GalleryBehavior;
    use artbox\core\behaviors\LanguageBehavior;
    use artbox\core\behaviors\ManyToManyBehavior;
    use artbox\core\models\Image;
    use yii\behaviors\TimestampBehavior;

    class Product extends \artbox\catalog\models\Product
    {
        public $imgIds;
        public function behaviors()
        {
            return [
                'language'       => [
                    'class' => LanguageBehavior::className(),
                ],
                'timestamp'      => [
                    'class' => TimestampBehavior::className(),
                ],
                [
                    'class' => ManyToManyBehavior::className(),
                ],
                [
                    'class'  => BitMaskBehavior::className(),
                    'fields' => [
                        'top'       => 0,
                        'new'       => 1,
                        'akcia'     => 2,
                        'exclusive' => 3,
                    ],
                ],
                [
                    'class' => GalleryBehavior::className(),
                ],
            ];
        }
        public function getImages()
        {
            $ids = [];
            $gallery = $this->gallery;
            if (!empty($gallery)) {
                $ids = array_filter(json_decode($gallery));
            }
            if (!empty($this->image_id)) {
                $ids[] = $this->image_id;
            }
            $this->imgIds = $ids;
            return $this->hasMany(Image::className(), [ 'id' => 'imgIds' ]);
        }
    }