File: /home/safarimaris/home/safarimaris/common/models/Feature.php
<?php
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "Feature".
*
* @property integer $id
* @property string $name
* @property integer $ordinal
*
* @property ProductFeature[] $productFeatures
* @property Product[] $products
*/
class Feature extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'feature';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name'], 'required'],
[['name'], 'string', 'max' => 255],
[['ordinal'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('model', 'ID'),
'name' => Yii::t('model', 'Name'),
'ordinal' => Yii::t('model', 'Ordinal number'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProductFeatures()
{
return $this->hasMany(ProductFeature::className(), ['tagId' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getProducts()
{
return $this->hasMany(Product::className(), ['id' => 'productId'])->viaTable('product_feature', ['tagId' => 'id']);
}
public static function getActiveList($active)
{
$tags = ArrayHelper::map(\common\models\Feature::find()->orderBy('name')->all(), 'id', 'name');
$return = [];
foreach ($tags as $k => $item) {
$return[$k] = [
'name' => $item,
'active' => in_array($k, (array)$active) ? 'checked="checked"' : '',
];
}
$return['isCompatriot'] = [
'name' => Yii::t('app', 'Is Compatriot'),
'active' => in_array('isCompatriot', (array)$active) ? 'checked="checked"' : '',
];
return $return;
}
}