<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "log_cc".
 *
 * @property integer $id
 * @property string $operatore
 * @property string $azione
 * @property string $telefono
 * @property string $info
 * @property string $data_azione
 */
class LogCC extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'log_cc';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['operatore', 'azione', 'data_azione'], 'required'],
            [['info'], 'string'],
            [['data_azione'], 'safe'],
            [['operatore', 'telefono'], 'string', 'max' => 32],
            [['azione'], 'string', 'max' => 256]
        ];
    }

    public static function log($operatore, $azione, $telefono = null , $info = null) {
        $log = new LogCC();
        $log->operatore = $operatore;
        $log->azione = $azione;
        $log->telefono = $telefono;
        $log->info = json_encode($info);
        $log->data_azione = date('Y-m-d H:i:s');

        $log->save();
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'operatore' => 'Operatore',
            'azione' => 'Azione',
            'telefono' => 'Telefono',
            'info' => 'Info',
            'data_azione' => 'Data Azione',
        ];
    }
}
