<?php

namespace app\models\mikrotik\system;

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 Active extends Model {

    public $id;
    public $when;
    public $name;
    public $address;
    public $via;
    public $group;
    public $radius;

    public function rules() {
        return [
            ['id', 'string'],
            ['when', 'string'],
            ['name', 'string'],
            ['address', 'string'],
            ['via', 'string'],
            ['group', 'string'],
            ['radius', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/user/active/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Active();
                $c->id = $response->getProperty('.id');
                $c->when = $response->getProperty('when');
                $c->name = $response->getProperty('name');
                $c->address = $response->getProperty('address');
                $c->via = $response->getProperty('via');
                $c->group = $response->getProperty('group');
                $c->radius = $response->getProperty('radius');
                $return[] = $c;
            }
        }
        return $return;
    }

}
