Completed
Push — master ( 630802...d9facf )
by Razon
02:13
created

Article   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 30
c 1
b 0
f 0
dl 0
loc 67
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A optimisticLock() 0 3 1
A behaviors() 0 6 1
A getMeta() 0 3 1
A tableName() 0 3 1
A attributeLabels() 0 15 1
1
<?php
2
namespace App\Model;
3
4
use App\Behavior\ArticleBehavior;
5
use App\Db\TimestampBehavior;
6
use App\Factory\ArticleMetaFactory;
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 $user_id User 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
 */
28
class Article extends ActiveRecord implements SoftDeleteInterface, StatusInterface
29
{
30
    use SoftDeleteTrait, StatusTrait;
31
32
    public $content;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public static function tableName()
38
    {
39
        return '{{%article}}';
40
    }
41
42
    public function behaviors()
43
    {
44
        return [
45
            TimestampBehavior::class,
46
            OptimisticLockBehavior::class,
47
            ArticleBehavior::class,
48
        ];
49
    }
50
    
51
    public function optimisticLock()
52
    {
53
        return 'version';
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function rules()
60
    {
61
        return [
62
            [['author', 'cover'], 'default', 'value' => ''],
63
            [['user_id', 'title', 'content', 'summary', 'status', 'release_time'], 'required'],
64
            [['user_id', 'release_time', 'status', 'is_deleted', 'create_time', 'update_time'], 'integer'],
65
            [['content'], 'string'],
66
            [['title', 'author'], 'string', 'max' => 255],
67
            [['cover'], UrlValidator::class],
68
        ];
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function attributeLabels()
75
    {
76
        return [
77
            'id' => Yii::t('app', 'ID'),
78
            'user_id' => Yii::t('app', 'User ID'),
79
            'cover' => Yii::t('app', 'Cover'),
80
            'title' => Yii::t('app', 'Title'),
81
            'summary' => Yii::t('app', 'Summary'),
82
            'content' => Yii::t('app', 'Content'),
83
            'author' => Yii::t('app', 'Author'),
84
            'release_time' => Yii::t('app', 'Release Time'),
85
            'status' => Yii::t('app', 'Status: 0.Inactive 1.Active'),
86
            'is_deleted' => Yii::t('app', 'Is Deleted'),
87
            'create_time' => Yii::t('app', 'Create Time'),
88
            'update_time' => Yii::t('app', 'Update Time'),
89
        ];
90
    }
91
92
    public function getMeta()
93
    {
94
        return $this->hasOne(ArticleMeta::class, ['article_id' => 'id']);
95
    }
96
}
97