<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "messages".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $notes
 * @property string $date
 */
class Messages extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'messages';
    }

    public $cnt;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'notes', 'date'], 'required'],
            [['user_id'], 'integer'],
            [['date','cnt'], 'safe'],
            [['notes'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'user_id' => Yii::t('app', 'User ID'),
            'notes' => Yii::t('app', 'Notes ID'),
            'date' => Yii::t('app', 'Date ID'),
        ];
    }
    public function CreateMessage($insert)
    {
        $model = new Messages();
        $model->setAttributes([
            'user_id' => $insert['user_id'],
            'notes' => $insert['notes'],
            'date' => date("Y-m-d H:i:s"),
        ]);
        $model->save(false);
        return true;

    }
}
