<?php

namespace app\common\model;

class ArticleModel extends BaseModel
{
    //设置表名
    protected $name = 'article';

    //自动完成
    protected $autoWriteTimestamp = true;

    //常量
    const STATUS = [1 => '已发布', 2 => '待修改'];
    const TYPE   = [1 => '文章详情', 2 => '链接'];

    const STATUS_PUBLISH = 1;
    const STATUS_MODIFY  = 2;
    const TYPE_ARTICLE   = 1;
    const TYPE_LINK      = 2;

    //允许修改
    const EDIT_ALLOW = ['cate_id','title','header_image','author','summary','type','content','url','priority','status','volume'];

    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS[$data['status']];
    }

    public function getTypeTextAttr($value, $data)
    {
        return self::TYPE[$data['type']];
    }

    // 关联ArticleCate
    public function Cate()
    {
        return $this->hasOne(ArticleCateModel::class, "id", "cate_id");
    }

}