Area.php
3.9 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
namespace common\modules\map\models;
use Yii;
use thread\app\base\models\ActiveRecord;
use thread\app\base\module\abstracts\Module;
use common\modules\map\Map as MainModule;
/**
* Class Area
*
* @property integer id
* @property string type_map
* @property string image_link
* @property integer position
* @property integer created_at
* @property integer updated_at
* @property boolean published
* @property \yii\db\ActiveQuery $lang
* @property null|string $imageLink
* @property boolean deleted
* @author Alla Kuzmenko
* @package common\modules\map\models
*/
class Area extends ActiveRecord
{
/**
*
*/
const moduleName = 'map';
/**
* @return null|object|string
*/
public static function getDb()
{
return MainModule::getDb();
}
/**
* @return string
*/
public static function tableName()
{
return '{{%map_area}}';
}
/**
* @return array
*/
public function rules()
{
return [
[['type_map'], 'required'],
[['image_link', 'image_link2'], 'string', 'max' => 1024],
[['type_map'], 'in', 'range' => array_keys(MainModule::typeRange())],
[['published', 'deleted'], 'in', 'range' => array_keys(static::statusKeyRange())],
[['position'], 'default', 'value' => 0],
[['published'], 'default', 'value' => self::STATUS_KEY_ON]
];
}
/**
* @return array
*/
public function scenarios()
{
return [
'published' => ['published'],
'deleted' => ['deleted'],
'backend' => [
'image_link',
'image_link2',
'type_map',
'position',
'published',
'deleted',
],
];
}
/**
* @return array
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'image_link' => Yii::t('app', 'Image link'),
'image_link2' => Yii::t('app', 'Image link'),
'type_map' => Yii::t('map', 'Type'),
'position' => Yii::t('app', 'Position'),
'created_at' => Yii::t('app', 'Create time'),
'updated_at' => Yii::t('app', 'Update time'),
'published' => Yii::t('app', 'Published'),
'deleted' => Yii::t('app', 'Deleted'),
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getLang()
{
return $this->hasOne(AreaLang::class, ['rid' => 'id']);
}
/**
* @return Module|null the module instance, `null` if the module does not exist.
*/
/**
* @return null|\yii\base\Module
*/
public static function getModule()
{
return Yii::$app->getModule(self::moduleName);
}
/**
* @return null|string
*/
public function getImageLink()
{
$module = $this->getModule();
$path = $module->getItemUploadPath();
$url = $module->getItemUploadUrl();
return (!empty($this->image_link) && is_file($path . '/' . $this->image_link))
? $url . '/' . $this->image_link
: null;
}
/**
* @return null|string
*/
public function getImageLink2()
{
$module = $this->getModule();
$path = $module->getItemUploadPath();
$url = $module->getItemUploadUrl();
return (!empty($this->image_link2) && is_file($path . '/' . $this->image_link2))
? $url . $this->image_link2
: null;
}
/**
* @return null|string
*/
public function getImageLink2Path()
{
$module = $this->getModule();
$path = $module->getItemUploadPath();
$url = $module->getItemUploadUrl();
return (!empty($this->image_link2) && is_file($path . '/' . $this->image_link2))
? $path . $this->image_link2
: null;
}
}