This repository has been archived by the owner on Feb 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBooks.php
executable file
·97 lines (89 loc) · 2.36 KB
/
Books.php
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
<?php
namespace app\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
* This is the model class for table "books".
*
* @property integer $id
* @property string $name
* @property integer $date_create
* @property integer $date_update
* @property string $preview
* @property string $date
* @property integer $author_id
*/
class Books extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'books';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name','preview','date','author_id'],'required'],
[['date_create', 'date_update', 'author_id'], 'integer'],
[['date'], 'date','format'=>'php:Y-m-d'],
[['name', 'preview'], 'string', 'max' => 255]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'date_create' => 'Дата добавления',
'date_update' => 'Date Update',
'preview' => 'Превью',
'date' => 'Дата выхода книги',
'author_id' => 'Автор',
'date_from'=>'Дата от',
'date_to'=>'Дата до',
];
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'date_create',
'updatedAtAttribute' => 'date_update',
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['date_create', 'date_update'],
ActiveRecord::EVENT_BEFORE_UPDATE => ['date_update'],
],
],
];
}
/**
* Return date_create in user-friendly format
* @return string
*/
public function getDateText(){
$date = date('d/m/Y', $this->date_create);
if($date == date('d/m/Y')) {
$date = 'Сегодня';
}
else if($date == date('d/m/Y',time() - (24 * 60 * 60))) {
$date = 'Вчера';
}
return $date;
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAuthor(){
return $this->hasOne(Authors::className(),['id'=>'author_id']);
}
}