1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace roaresearch\yii2\formgenerator\models; |
4
|
|
|
|
5
|
|
|
use yii\db\ActiveQuery; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Model class for table `{{%formgenerator_field_rule_property}}` |
9
|
|
|
* |
10
|
|
|
* @property int $rule_id |
11
|
|
|
* @property string $property |
12
|
|
|
* @property string $value |
13
|
|
|
* @property int $created_by |
14
|
|
|
* @property string $created_at |
15
|
|
|
* @property int $updated_by |
16
|
|
|
* @property string $updated_at |
17
|
|
|
* |
18
|
|
|
* @property FieldRule $rule |
19
|
|
|
*/ |
20
|
|
|
class FieldRuleProperty extends \roaresearch\yii2\rmdb\models\Entity |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string full class name of the model used in the relation |
24
|
|
|
* `getRules()`. |
25
|
|
|
*/ |
26
|
|
|
protected $ruleClass = FieldRule::class; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritdoc |
30
|
|
|
*/ |
31
|
9 |
|
public static function tableName() |
32
|
|
|
{ |
33
|
9 |
|
return '{{%formgenerator_field_rule_property}}'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @inheritdoc |
38
|
|
|
*/ |
39
|
7 |
|
protected function attributeTypecast(): array |
40
|
|
|
{ |
41
|
7 |
|
return parent::attributeTypecast() + ['rule_id' => 'integer']; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
2 |
|
public function rules() |
48
|
|
|
{ |
49
|
|
|
return [ |
50
|
2 |
|
[['rule_id', 'property', 'value'], 'required'], |
51
|
|
|
[['rule_id'], 'integer'], |
52
|
|
|
[ |
53
|
|
|
['rule_id'], |
54
|
|
|
'exist', |
55
|
|
|
'skipOnError' => true, |
56
|
|
|
'targetClass' => FieldRule::class, |
57
|
|
|
'targetAttribute' => ['rule_id' => 'id'], |
58
|
|
|
], |
59
|
|
|
[['property', 'value'], 'trim'], |
60
|
|
|
[['property', 'value'], 'string'], |
61
|
|
|
[ |
62
|
|
|
['property'], |
63
|
|
|
'unique', |
64
|
|
|
'targetAttribute' => ['rule_id', 'property'], |
65
|
|
|
'message' => 'Property already in use for this rule.', |
66
|
|
|
], |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
2 |
|
public function attributeLabels() |
74
|
|
|
{ |
75
|
2 |
|
return array_merge([ |
76
|
2 |
|
'rule_id' => 'Rule ID', |
77
|
|
|
'property' => 'Property', |
78
|
|
|
'value' => 'Value', |
79
|
2 |
|
], parent::attributeLabels()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return ActiveQuery |
84
|
|
|
*/ |
85
|
7 |
|
public function getRule(): ActiveQuery |
86
|
|
|
{ |
87
|
7 |
|
return $this->hasOne($this->ruleClass, ['id' => 'rule_id']); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|