<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%ARTICLE_CATEGORY}}".
 *
 * @property string $ID
 * @property string $CATE_NAME 分类名
 * @property int $SORT
 * @property int $STATUS 状态
 * @property int $CREATED_AT 创建时间
 */
class ArticleCategory extends \common\components\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%ARTICLE_CATEGORY}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['CATE_NAME', 'CREATED_AT'], 'required'],
            [['SORT', 'STATUS', 'CREATED_AT'], 'integer'],
            [['ID'], 'string', 'max' => 32],
            [['CATE_NAME'], 'string', 'max' => 20],
            [['CATE_NAME'], 'unique'],
            [['ID'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'ID' => 'ID',
            'CATE_NAME' => '分类名',
            'STATUS' => '状态',
            'SORT' => 'Sort',
            'CREATED_AT' => '创建时间',
        ];
    }

    /**
     * 获取全部分类
     * @return array|\yii\db\ActiveRecord[]
     */
    public static function getAllCategory(){
        return ArticleCategory::find()->where('STATUS=1')->indexBy('ID')->orderBy('SORT ASC')->asArray()->all();
    }
}
