<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/26/026
 * Time: 14:56
 */

namespace common\models;

//use yii\db\ActiveRecord;
//use yii\behaviors\TimestampBehavior;
class UserNode extends Common
{

//        public function behaviors()
//        {
//            return [
//                [
//                    'class' => TimestampBehavior::className(),
//                    'attributes' => [
//                        # 创建之前
//                        ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
//                        # 修改之前
//                        ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
//                    ],
//                    #设置默认值
//                    'value' => $_SERVER['REQUEST_TIME']
//                ]
//            ];
//        }

        public function rules()
        {
            return [
                ['controller','required','message'=>'控制器不能为空'],
                ['action','required','message'=>'控制器方法不能为空'],
                ['describe','string','max'=>200]
            ];
        }

        public function FindById($id)
        {
            return self::findOne($id);
        }

        public function MultipleCondition()
        {
            return self::find()->andFilterWhere(['controller'=>$this->controller])
                               ->andFilterWhere(['action'=>$this->action])
                               ->one();
        }

        public function getList($input)
        {
            $query = self::find();
            if(!empty($input['page']))
            {
                $query->offset = ($input['page'] -1) * $input['limit'];
                $query->limit =  $input['limit'];
            }
            $row['count'] = $query->count();
            $row['data']  = $query->orderBy('controller,create_at')->asArray()->all();
            return $row;
        }

        public function Check($input)
        {
            $this->load($input,'');
            if(!$this->validate())
            {
                return $this->errors;
            }
            return $this;
        }



}