コード例 #1
0
ファイル: Objects.php プロジェクト: Aplay/Fastreview_site
    /**
     * @param $attribute
     * @param null $default
     * @return bool|float|int|null|string
     */
    public function attribute($attribute, $default = null)
    {
        if ($this->getIsNewRecord()) {
            return null;
        }

        //@TODO переделать на получение в 1 запрос
        $models = EavProductVariant::model()->with('attribute')->findAll(
            'product_id = :product AND attribute_id = :attribute',
            array(
                ':product' => $this->id,
                ':attribute' => $attribute->id,
            )
        );

        if (null === $models || empty($models)) {
            return null;
        }
        $ret = array();
        if(count($models)==1){
        	return $models[0]->value($default);
        }
        foreach ($models as $model) {
        	$ret[] = $model->value($default);
        }
        return $ret;
    }