1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\romrelease\models; |
4
|
|
|
|
5
|
|
|
use yii\helpers\Url; |
6
|
|
|
use yii\web\UploadedFile; |
7
|
|
|
use yii\behaviors\TimestampBehavior; |
8
|
|
|
use zacksleo\yii2\romrelease\Module; |
9
|
|
|
use zacksleo\yii2\romrelease\behaviors\UploadBehavior; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This is the model class for table "{{%app_release}}". |
13
|
|
|
* |
14
|
|
|
* @property integer $id |
15
|
|
|
* @property integer $version |
16
|
|
|
* @property integer $version_code |
17
|
|
|
* @property integer $is_forced |
18
|
|
|
* @property string $url |
19
|
|
|
* @property string $md5 |
20
|
|
|
* @property integer $status |
21
|
|
|
* @property string $description |
22
|
|
|
* @property integer $created_at |
23
|
|
|
* @property integer $updated_at |
24
|
|
|
* @property UploadedFile $releaseFile |
25
|
|
|
*/ |
26
|
|
|
class RomRelease extends \yii\db\ActiveRecord |
27
|
|
|
{ |
28
|
|
|
public $file; |
29
|
|
|
const STATUS_PUBLISHED = 1; |
30
|
|
|
const STATUS_UNPUBLISHED = 0; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
9 |
|
public static function tableName() |
36
|
|
|
{ |
37
|
9 |
|
return '{{%rom_release}}'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
5 |
|
public function rules() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
5 |
|
[['version', 'description'], 'required'], |
47
|
|
|
[['is_forced', 'status'], 'integer'], |
48
|
|
|
[['is_forced', 'status'], 'default', 'value' => 1], |
49
|
|
|
[['description', 'version'], 'string', 'max' => 255], |
50
|
|
|
['md5', 'string', 'max' => 255, 'on' => ['save']], |
51
|
|
|
['version_code', 'safe'], |
52
|
|
|
[['url'], 'file', |
53
|
|
|
//'extensions' => 'apk', |
54
|
|
|
'skipOnEmpty' => true, |
55
|
|
|
'tooBig' => 'app文件大小不超过120M', |
56
|
|
|
'maxFiles' => 1, |
57
|
|
|
'maxSize' => 120 * 1024 * 1024, |
58
|
|
|
'on' => ['insert', 'update'] |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritdoc |
65
|
|
|
*/ |
66
|
2 |
|
public function attributeLabels() |
67
|
|
|
{ |
68
|
|
|
return [ |
69
|
2 |
|
'id' => Module::t('romrelease', 'ID'), |
70
|
2 |
|
'version' => Module::t('romrelease', 'version'), |
71
|
2 |
|
'version_code' => Module::t('romrelease', 'version code'), |
72
|
2 |
|
'is_forced' => Module::t('romrelease', 'is forced'), |
73
|
2 |
|
'url' => Module::t('romrelease', 'url'), |
74
|
2 |
|
'md5' => Module::t('romrelease', 'MD5'), |
75
|
2 |
|
'status' => Module::t('romrelease', 'status'), |
76
|
2 |
|
'description' => Module::t('romrelease', 'description'), |
77
|
2 |
|
'created_at' => Module::t('romrelease', 'created at'), |
78
|
2 |
|
'updated_at' => Module::t('romrelease', 'updated at'), |
79
|
2 |
|
'file' => Module::t('romrelease', 'File'), |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
11 |
|
public function behaviors() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
11 |
|
'timestamp' => [ |
90
|
11 |
|
'class' => TimestampBehavior::className(), |
91
|
|
|
], |
92
|
|
|
[ |
93
|
11 |
|
'class' => UploadBehavior::className(), |
94
|
11 |
|
'attribute' => 'url', |
95
|
|
|
'scenarios' => ['insert', 'update'], |
96
|
11 |
|
'path' => '@frontend/web/uploads/apps', |
97
|
11 |
|
'url' => '@web/uploads/apps', |
98
|
|
|
], |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
public function fields() |
103
|
|
|
{ |
104
|
1 |
|
$fields = parent::fields(); |
105
|
1 |
|
$fields['url'] = function () { |
106
|
1 |
|
$path = str_replace('api/uploads/', '', $this->getUploadUrl('url')); |
|
|
|
|
107
|
1 |
|
if (isset($_ENV['API_HOST'])) { |
108
|
|
|
$url = $_ENV['API_HOST'] . 'files/' . $path; |
109
|
|
|
} else { |
110
|
1 |
|
$url = Url::to(['file/view', 'path' => $path], true); |
111
|
|
|
} |
112
|
1 |
|
return $url; |
113
|
|
|
}; |
114
|
1 |
|
unset($fields['id'], $fields['created_at'], $fields['status'], $fields['updated_at']); |
115
|
1 |
|
return $fields; |
116
|
|
|
} |
117
|
|
|
|
118
|
1 |
|
public static function getStatusList() |
119
|
|
|
{ |
120
|
|
|
return [ |
121
|
1 |
|
self::STATUS_UNPUBLISHED => Module::t('romrelease', 'unpublished'), |
122
|
1 |
|
self::STATUS_PUBLISHED => Module::t('romrelease', 'published'), |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: