<?php

namespace app\models\mikrotik\log;

use yii\base\Model;
use Yii;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

use PEAR2\Net\RouterOS;
use app\models\mikrotik\MikrotikConnect;

class Log extends Model {

    public $time;
    public $topics;
    public $message;

    public function rules() {
        return [
            ['time', 'string'],
            ['topics', 'string'],
            ['message', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/log/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Log();
                $c->time = $response->getProperty('time');
                $c->topics = $response->getProperty('topics');
                $c->message = $response->getProperty('message');
                $return[] = $c;
            }
        }
        return $return;
    }

}
