|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\models; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use yii\db\ActiveRecord; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* This is the model class for table "object_property_group". |
|
10
|
|
|
* |
|
11
|
|
|
* @property integer $id |
|
12
|
|
|
* @property integer $object_id |
|
13
|
|
|
* @property integer $object_model_id |
|
14
|
|
|
* @property integer $property_group_id |
|
15
|
|
|
*/ |
|
16
|
|
|
class ObjectPropertyGroup extends ActiveRecord |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @inheritdoc |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function tableName() |
|
22
|
|
|
{ |
|
23
|
|
|
return '{{%object_property_group}}'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritdoc |
|
28
|
|
|
*/ |
|
29
|
|
|
public function rules() |
|
30
|
|
|
{ |
|
31
|
|
|
return [ |
|
32
|
|
|
[['object_id', 'object_model_id', 'property_group_id'], 'required'], |
|
33
|
|
|
[['object_id', 'object_model_id', 'property_group_id'], 'integer'], |
|
34
|
|
|
[['object_id', 'object_model_id', 'property_group_id'], 'unique', 'targetAttribute' => ['object_id', 'object_model_id', 'property_group_id'], 'message' => 'Property group is already binded'], |
|
35
|
|
|
]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @inheritdoc |
|
40
|
|
|
*/ |
|
41
|
|
View Code Duplication |
public function attributeLabels() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
'id' => Yii::t('app', 'ID'), |
|
45
|
|
|
'object_id' => Yii::t('app', 'Object ID'), |
|
46
|
|
|
'object_model_id' => Yii::t('app', 'Object Model ID'), |
|
47
|
|
|
'property_group_id' => Yii::t('app', 'Property Group ID'), |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function getForModel($model) |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var BaseObject $object */ |
|
54
|
|
|
$object = BaseObject::getForClass(get_class($model)); |
|
55
|
|
|
return ObjectPropertyGroup::find() |
|
56
|
|
|
->joinWith('group') |
|
57
|
|
|
->where( |
|
58
|
|
|
[ |
|
59
|
|
|
static::tableName() . '.object_id' => $object->id, |
|
60
|
|
|
static::tableName() . '.object_model_id' => $model->id, |
|
61
|
|
|
] |
|
62
|
|
|
)->orderBy(PropertyGroup::tableName() . '.sort_order') |
|
63
|
|
|
->all(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return PropertyGroup|null |
|
|
|
|
|
|
68
|
|
|
*/ |
|
69
|
|
|
public function getGroup() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->hasOne(PropertyGroup::className(), ['id' => 'property_group_id']); |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
?> |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.