-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
120 lines (112 loc) · 3.19 KB
/
Application.php
File metadata and controls
120 lines (112 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "application".
*
* @property int $id
* @property int $clientId
* @property int $term
* @property float $amount
* @property string $currency
* @property bool $active
* @property int $created_by
* @property string $created_time
* @property int|null $modified_by
* @property string|null $modified_time
*
* @property Client $client
*/
class Application extends \app\db\ActiveRecord
{
public $allowedCurrency = [
'EUR',
];
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'application';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['clientId', 'term', 'amount', 'currency'], 'required'],
[['clientId', 'term', 'created_by', 'modified_by'], 'default', 'value' => null],
[['clientId', 'created_by', 'modified_by'], 'integer'],
[['term'], 'integer', 'min' => 10, 'max' => 30],
[['amount'], 'number', 'min' => 100, 'max' => 5000],
[['active'], 'boolean'],
[['created_time', 'modified_time'], 'safe'],
[['currency'], 'string', 'max' => 3],
[['currency'], 'checkCurrency'],
[['clientId'], 'exist', 'skipOnError' => true, 'targetClass' => Client::className(), 'targetAttribute' => ['clientId' => 'id']],
];
}
public function checkCurrency($attribute)
{
if (!in_array($this->{$attribute}, $this->allowedCurrency)) {
$this->addError(
$attribute,
Yii::t(
'app',
'Invalid {attribute}, allowed values: {allowedCurrency}',
[
'attribute' => $attribute,
'allowedCurrency' => implode(', ', $this->allowedCurrency)
]
)
);
}
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'clientId' => Yii::t('app', 'Client ID'),
'term' => Yii::t('app', 'Term'),
'amount' => Yii::t('app', 'Amount'),
'currency' => Yii::t('app', 'Currency'),
'active' => Yii::t('app', 'Active'),
'created_by' => Yii::t('app', 'Created By'),
'created_time' => Yii::t('app', 'Created Time'),
'modified_by' => Yii::t('app', 'Modified By'),
'modified_time' => Yii::t('app', 'Modified Time'),
];
}
/**
* {@inheritdoc}
*/
public function fields()
{
return [
'id',
'clientId' => function() {
return (int) $this->clientId;
},
'term' => function() {
return (int) $this->term;
},
'amount' => function() {
return $this->amount + 0;
},
'currency',
];
}
/**
* Gets query for [[Client]].
*
* @return \yii\db\ActiveQuery
*/
public function getClient()
{
return $this->hasOne(Client::className(), ['id' => 'clientId']);
}
}