Passed
Push — master ( a90c1b...36c150 )
by Razon
02:16
created

Article::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace App\Model;
3
4
use App\Behavior\ArticleBehavior;
5
use App\Behavior\CreatorBehavior;
6
use App\Behavior\TimestampBehavior;
7
use App\Validator\UrlValidator;
8
use Yii;
9
use yii\behaviors\OptimisticLockBehavior;
10
11
/**
12
 * This is the model class for table "{{%article}}".
13
 *
14
 * @property int $id
15
 * @property int $creator Creator ID
16
 * @property string $title Title
17
 * @property string $summary Description
18
 * @property string $author Author
19
 * @property string $cover Cover
20
 * @property int $release_time Release Time
21
 * @property int $status Status: 0.Inactive 1.Active
22
 * @property int $is_deleted Is Deleted
23
 * @property int $create_time Create Time
24
 * @property int $update_time Update Time
25
 *
26
 * @property ArticleMeta $meta
27
 * @property ArticleCategory $category
28
 */
29
class Article extends ActiveRecord implements SoftDeleteInterface, StatusInterface
30
{
31
    use SoftDeleteTrait, StatusTrait;
32
33
    public $content;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public static function tableName()
39
    {
40
        return '{{%article}}';
41
    }
42
43
    public function behaviors()
44
    {
45
        return [
46
            TimestampBehavior::class,
47
            OptimisticLockBehavior::class,
48
            CreatorBehavior::class,
49
            ArticleBehavior::class,
50
        ];
51
    }
52
    
53
    public function optimisticLock()
54
    {
55
        return 'version';
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function rules()
62
    {
63
        return [
64
            [['author', 'cover'], 'default', 'value' => ''],
65
            [['title', 'content', 'summary', 'status', 'release_time', 'category_id'], 'required'],
66
            [['release_time', 'status', 'is_deleted', 'create_time', 'update_time', 'category_id'], 'integer'],
67
            [['content'], 'string'],
68
            [['title', 'author'], 'string', 'max' => 255],
69
            [['cover'], UrlValidator::class],
70
            ['category_id', 'exist', 'targetClass' => ArticleCategory::class, 'targetAttribute' => 'id'],
71
        ];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function attributeLabels()
78
    {
79
        return [
80
            'id' => Yii::t('app', 'ID'),
81
            'creator' => Yii::t('app', 'Creator'),
82
            'cover' => Yii::t('app', 'Cover'),
83
            'title' => Yii::t('app', 'Title'),
84
            'summary' => Yii::t('app', 'Summary'),
85
            'content' => Yii::t('app', 'Content'),
86
            'author' => Yii::t('app', 'Author'),
87
            'release_time' => Yii::t('app', 'Release Time'),
88
            'status' => Yii::t('app', 'Status: 0.Inactive 1.Active'),
89
            'is_deleted' => Yii::t('app', 'Is Deleted'),
90
            'create_time' => Yii::t('app', 'Create Time'),
91
            'update_time' => Yii::t('app', 'Update Time'),
92
        ];
93
    }
94
95
    public function getMeta()
96
    {
97
        return $this->hasOne(ArticleMeta::class, ['article_id' => 'id']);
98
    }
99
100
    public function getCategory()
101
    {
102
        return $this->hasOne(ArticleCategory::class, ['id' => 'category_id']);
103
    }
104
}
105