<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "gift_group_t".
 *
 * @property integer $id
 * @property string $name
 * @property integer $is_free
 * @property integer $is_damage
 * @property string $min_money
 * @property string $max_money
 * @property string $gift_ids
 * @property string $group_ids
 * @property string $created_at
 * @property string $updated_at
 */
class GiftGroupT extends \common\models\Base
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'gift_group_t';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['is_free','is_damage'], 'integer'],
            [['min_money', 'max_money'], 'number'],
            [['created_at', 'updated_at'], 'safe'],
            [['name'], 'string', 'max' => 50],
            [['gift_ids','group_ids'], 'string', 'max' => 200],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'is_free' => 'Is Free',
            'is_damage' => 'Is Damage',
            'min_money' => 'Min Money',
            'max_money' => 'Max Money',
            'gift_ids' => 'Gift Ids',
            'group_ids' => 'Group Ids',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getGifts()
    {
        $data = null;
        $ids = explode(',',$this->gift_ids);
        foreach($ids as $id) {
            $gift = GiftType3T::findOne(['id'=>$id]);
            if(isset($gift))
                $data[] = $gift;
        }
        return $data;
    }

    public function getGroups()
    {
        $data = array();
        $ids = explode(',',$this->group_ids);
        foreach($ids as $id) {
            $group = GroupT::findOne(['id'=>$id]);
            if(isset($group))
                $data[] = $group;
        }
        return $data;
    }
}
