d1f8bd40
Alexey Boroda
first commit
|
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
<?php
namespace thread\modules\location\models;
use Yii;
use yii\behaviors\AttributeBehavior;
use yii\helpers\{
ArrayHelper, Inflector
};
//
use thread\app\base\models\ActiveRecord;
use thread\modules\location\Location as LocationModule;
/**
* Class Currency
*
* @package thread\modules\location\models
* @author FilamentV <vortex.filament@gmail.com>
* @copyright (c), Thread
*/
class Currency extends ActiveRecord
{
/**
*
* @return string
*/
public static function getDb()
{
return LocationModule::getDb();
}
/**
*
* @return string
*/
public static function tableName()
{
return '{{%location_currency}}';
}
/**
* @inheritdoc
* @return array
*/
public function behaviors()
{
return ArrayHelper::merge(
parent::behaviors(),
[
[
'class' => AttributeBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'alias',
ActiveRecord::EVENT_BEFORE_UPDATE => 'alias',
],
'value' => function ($event) {
return Inflector::slug($this->alias);
},
],
]
);
}
/**
*
* @return array
*/
public function rules()
{
return [
[['alias', 'code1', 'code2'], 'required'],
[['created_at', 'updated_at'], 'integer'],
[['published', 'deleted'], 'in', 'range' => array_keys(static::statusKeyRange())],
[['code1', 'code2'], 'string', 'max' => 4],
[['alias', 'default_title'], 'string', 'max' => 255],
[['currency_symbol'], 'string', 'max' => 100],
[['course'], 'number', 'numberPattern' => '/^\s*[-+]?[0-9]*[.,]?[0-9]+([eE][-+]?[0-9]+)?\s*$/'],
[['alias'], 'unique']
];
}
/**
*
* @return array
*/
public function scenarios()
{
return [
'published' => ['published'],
'deleted' => ['deleted'],
'backend' => ['alias', 'code1', 'course', 'code2', 'published', 'currency_symbol', 'deleted', 'default_title'],
];
}
/**
*
* @return array
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'alias' => Yii::t('app', 'Alias'),
'code1' => Yii::t('location', 'code1'),
'code2' => Yii::t('location', 'code2'),
'created_at' => Yii::t('app', 'Create time'),
'updated_at' => Yii::t('app', 'Update time'),
'published' => Yii::t('app', 'Published'),
'deleted' => Yii::t('app', 'Deleted'),
'course' => Yii::t('location', 'Course'),
'currency_symbol' => Yii::t('location', '(Html code) to display symbol'),
'title' => Yii::t('app', 'Title'),
'default_title' => Yii::t('app', 'Default Title'),
];
}
/**
* @return string
*/
public function getTitle()
{
return (isset($this->lang->title)) ? $this->lang->title : "{{$this->default_title}}";
}
/**
* @return \yii\db\ActiveQuery
*/
public function getLang()
{
return $this->hasOne(CurrencyLang::class, ['rid' => 'id']);
}
}
|