eb7e82fb
Administrator
29.02.16
|
1
2
3
4
5
6
7
8
9
|
<?php
namespace common\models;
use Yii;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression;
|
fa284ab0
Yarik
test
|
10
|
use yii\helpers\ArrayHelper;
|
eb7e82fb
Administrator
29.02.16
|
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
/**
* This is the model class for table "vacancy".
* @property integer $vacancy_id
* @property integer $user_id
* @property string $name
* @property string $link
* @property string $date_add
* @property integer $user_add_id
* @property integer $view_count
* @property string $user_name
* @property string $city
* @property string $description
* @property string $phone
* @property string $salary
* @property integer $salary_currency
* @property Employment[] $employments
* @property VacancyEmployment[] $vacancyEmployments
*/
class Vacancy extends \yii\db\ActiveRecord
{
|
a41edafc
Yarik
test
|
33
34
|
const STATUS_ACTIVE = 1;
const STATUS_CLOSED = 3;
|
fa284ab0
Yarik
test
|
35
|
|
eb7e82fb
Administrator
29.02.16
|
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
|
/**
* @inheritdoc
*/
public static function tableName()
{
return 'vacancy';
}
/**
* @inheritdoc
*/
public function behaviors()
{
return [
[
'class' => BlameableBehavior::className(),
'createdByAttribute' => 'user_id',
'updatedByAttribute' => false,
],
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'date_add',
'updatedAtAttribute' => false,
'value' => new Expression('NOW()'),
],
|
9fd076e8
Administrator
01.03.16
|
61
|
'slug' => [
|
fa284ab0
Yarik
test
|
62
63
|
'class' => 'common\behaviors\Slug',
'in_attribute' => 'name',
|
9fd076e8
Administrator
01.03.16
|
64
|
'out_attribute' => 'link',
|
fa284ab0
Yarik
test
|
65
66
|
'translit' => true,
],
|
eb7e82fb
Administrator
29.02.16
|
67
68
69
70
71
72
73
74
75
76
|
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[
|
fa284ab0
Yarik
test
|
77
78
79
80
81
82
|
[
'name',
'description',
'city',
'link',
],
|
eb7e82fb
Administrator
29.02.16
|
83
84
85
86
87
88
89
|
'required',
],
[
[ 'description' ],
'string',
],
[
|
fa284ab0
Yarik
test
|
90
91
92
93
|
[
'employmentInput',
'specializationInput',
],
|
eb7e82fb
Administrator
29.02.16
|
94
95
96
|
'safe',
],
[
|
fa284ab0
Yarik
test
|
97
98
99
100
101
|
[
'salary_currency',
'status',
],
'integer',
|
9fd076e8
Administrator
01.03.16
|
102
103
|
],
[
|
fa284ab0
Yarik
test
|
104
|
[ 'salary' ],
|
a41edafc
Yarik
test
|
105
106
107
108
|
'integer',
'min' => 0,
],
[
|
fa284ab0
Yarik
test
|
109
110
111
112
|
[
'employmentInput',
'specializationInput',
],
|
eb7e82fb
Administrator
29.02.16
|
113
|
'default',
|
fa284ab0
Yarik
test
|
114
|
'value' => [ ],
|
eb7e82fb
Administrator
29.02.16
|
115
116
117
118
119
120
121
|
],
[
[ 'view_count' ],
'default',
'value' => 0,
],
[
|
a41edafc
Yarik
test
|
122
123
124
125
126
|
[ 'status' ],
'default',
'value' => 1,
],
[
|
eb7e82fb
Administrator
29.02.16
|
127
128
129
130
131
132
133
134
135
136
|
[
'name',
'link',
'user_name',
'city',
],
'string',
'max' => 255,
],
[
|
fa284ab0
Yarik
test
|
137
|
[ 'phone' ],
|
eb7e82fb
Administrator
29.02.16
|
138
139
140
141
142
143
144
145
146
147
148
149
|
'match',
'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/',
],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
|
06ec2844
Administrator
28.03.16
|
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
'vacancy_id' => Yii::t('app', 'vacancy_id'),
'user_id' => Yii::t('app', 'user_id'),
'name' => Yii::t('app', 'name'),
'link' => Yii::t('app', 'link'),
'date_add' => Yii::t('app', 'date_add'),
'user_add_id' => Yii::t('app', 'user_add_id'),
'view_count' => Yii::t('app', 'view_count'),
'user_name' => Yii::t('app', 'user_name'),
'city' => Yii::t('app', 'city'),
'description' => Yii::t('app', 'description'),
'employmentInput' => Yii::t('app', 'employmentInput'),
'phone' => Yii::t('app', 'phone'),
'salary' => Yii::t('app', 'salary'),
'salary_currency' => Yii::t('app', 'salary_currency'),
|
eb7e82fb
Administrator
29.02.16
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getVacancyEmployments()
{
return $this->hasMany(VacancyEmployment::className(), [ 'vacancy_id' => 'vacancy_id' ]);
}
public function getEmployments()
{
return $this->hasMany(Employment::className(), [ 'employment_id' => 'employment_id' ])
->viaTable('vacancy_employment', [ 'vacancy_id' => 'vacancy_id' ]);
}
public function getEmploymentInput()
{
return $this->getEmployments()
->asArray()
->column();
}
public function setEmploymentInput($value)
{
$this->employmentInput = $value;
}
public function getRequirements()
{
return Fields::getData($this->vacancy_id, Vacancy::className(), 'requirements');
}
|
fa284ab0
Yarik
test
|
198
199
200
201
202
|
public function getVacancySpecializations()
{
return $this->hasMany(VacancySpecialization::className(), [ 'specialization_id' => 'specialization_id' ]);
}
|
eb7e82fb
Administrator
29.02.16
|
203
204
205
206
207
208
|
/**
* @return ActiveQuery
*/
public function getSpecializations()
{
return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ])
|
fa284ab0
Yarik
test
|
209
|
->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]);
|
eb7e82fb
Administrator
29.02.16
|
210
211
|
}
|
eb7e82fb
Administrator
29.02.16
|
212
213
214
215
216
|
public function getSalaryCurrency()
{
return $this->hasOne(Currency::className(), [ 'currency_id' => 'salary_currency' ]);
}
|
eb7e82fb
Administrator
29.02.16
|
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/**
* Return array of Vacancy's specialization IDs
* @return integer[]
*/
public function getSpecializationInput()
{
return $this->getSpecializations()
->asArray()
->indexBy('specialization_id')
->column();
}
/**
* Setter which allow to set Vacancy's specializations for further saving to the DB.
*
* @param integer[] $value
*/
public function setSpecializationInput($value)
{
$this->specializationInput = $value;
}
}
|