eb7e82fb
Administrator
29.02.16
|
1
2
|
<?php
|
38a6e1dd
Yarik
test
|
3
|
namespace common\models;
|
eb7e82fb
Administrator
29.02.16
|
4
|
|
38a6e1dd
Yarik
test
|
5
|
use Yii;
|
eb7e82fb
Administrator
29.02.16
|
6
|
|
eb7e82fb
Administrator
29.02.16
|
7
|
/**
|
38a6e1dd
Yarik
test
|
8
9
10
11
12
13
14
15
16
17
18
|
* This is the model class for table "job".
* @property integer $job_id
* @property string $name
* @property string $link
* @property string $date_start
* @property string $date_end
* @property string $position
* @property integer $user_id
* @property integer $total_count
* @property integer $complete_count
* @property integer $current
|
eb7e82fb
Administrator
29.02.16
|
19
|
*/
|
38a6e1dd
Yarik
test
|
20
|
class Job extends \yii\db\ActiveRecord
|
eb7e82fb
Administrator
29.02.16
|
21
|
{
|
9fd076e8
Administrator
01.03.16
|
22
|
|
38a6e1dd
Yarik
test
|
23
24
25
26
27
28
29
|
/**
* @inheritdoc
*/
public static function tableName()
{
return 'job';
}
|
9fd076e8
Administrator
01.03.16
|
30
|
|
38a6e1dd
Yarik
test
|
31
32
33
34
35
36
|
/**
* @inheritdoc
*/
public function behaviors()
{
return [
|
9fd076e8
Administrator
01.03.16
|
37
|
|
38a6e1dd
Yarik
test
|
38
|
];
|
9fd076e8
Administrator
01.03.16
|
39
40
|
}
|
38a6e1dd
Yarik
test
|
41
42
43
|
public function beforeSave($insert)
{
$this->date_start = \Yii::$app->formatter->asDatetime($this->date_start, 'Y-MM-d HH:mm:ss');
|
9fd076e8
Administrator
01.03.16
|
44
|
|
38a6e1dd
Yarik
test
|
45
46
47
|
if($this->date_end) {
$this->date_end = \Yii::$app->formatter->asDatetime($this->date_end, 'Y-MM-d HH:mm:ss');
}
|
eb7e82fb
Administrator
29.02.16
|
48
|
|
38a6e1dd
Yarik
test
|
49
50
|
return parent::beforeSave($insert); // TODO: Change the autogenerated stub
}
|
eb7e82fb
Administrator
29.02.16
|
51
|
|
38a6e1dd
Yarik
test
|
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
|
/**
* @inheritdoc
*/
public function rules()
{
return [
[
[ 'name' ],
'required',
],
[
[
'date_start',
'date_end',
],
'safe',
],
[
[
'user_id',
'total_count',
'complete_count',
'current',
],
'integer',
],
[
[
'name',
'link',
'position',
],
'string',
'max' => 255,
],
|
4b85f536
Yarik
test
|
87
88
89
90
91
92
93
|
[
[
'link',
],
'match',
'pattern' => '/^(?:https?:\/\/)?(?:w{3}\.)?'.preg_quote($_SERVER['HTTP_HOST']).'\/company\/\w+\/\d+$/i',
],
|
38a6e1dd
Yarik
test
|
94
|
];
|
eb7e82fb
Administrator
29.02.16
|
95
96
|
}
|
38a6e1dd
Yarik
test
|
97
98
|
public function getExpTime()
{
|
4b85f536
Yarik
test
|
99
100
101
102
103
104
105
106
107
108
109
110
|
if(!empty($this->date_start) && !empty($this->date_end)) {
$result = '';
$start = new \DateTime($this->date_start);
$end = new \DateTime($this->date_end);
$interval = $end->diff($start);
if(!empty($interval->y)) {
if($interval->y) {
$result
}
}
} elseif(!empty($this->date_start)) {
|
38a6e1dd
Yarik
test
|
111
|
} else {
|
4b85f536
Yarik
test
|
112
|
return false;
|
38a6e1dd
Yarik
test
|
113
|
}
|
4b85f536
Yarik
test
|
114
115
116
117
118
119
120
121
122
123
|
// if($this->date_end && $this->date_start) {
// $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start));
// return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end))));
// } elseif($this->date_start) {
// $now = new \DateTime();
// $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start)));
// return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime()));
// } else {
// return 'неизвестна дата начала';
// }
|
38a6e1dd
Yarik
test
|
124
|
}
|
eb7e82fb
Administrator
29.02.16
|
125
|
|
38a6e1dd
Yarik
test
|
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'job_id' => Yii::t('app', 'Job ID'),
'name' => Yii::t('app', 'Name'),
'link' => Yii::t('app', 'Link'),
'date_start' => Yii::t('app', 'Date Start'),
'date_end' => Yii::t('app', 'Date End'),
'position' => Yii::t('app', 'Position'),
'user_id' => Yii::t('app', 'User ID'),
'total_count' => Yii::t('app', 'Total Count'),
'complete_count' => Yii::t('app', 'Complete Count'),
'current' => Yii::t('app', 'Current'),
];
}
|
eb7e82fb
Administrator
29.02.16
|
144
|
}
|