Passed
Push — master ( 242566...b40a52 )
by Razon
03:06
created

Article::optimisticLock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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