<?php

namespace app\models\mikrotik\capsman;

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

    public $id;
    public $interface;
    public $mac_address;
    public $uptime;
    public $rx_signal;

    public function rules() {
        return [
            ['id', 'string'],
            ['interface', 'string'],
            ['mac_address', 'string'],
            ['uptime', 'string'],
            ['rx_signal', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/caps-man/registration-table/getall');
        $responses = $connect->getConnection()->sendSync($getRequest);
        $return = array();
        foreach ($responses as $response) {
            if ($response->getProperty('.id') != null) {
                $c = new Table();
                $c->id = $response->getProperty('id');
                $c->interface = $response->getProperty('interface');
                $c->mac_address = $response->getProperty('mac-address');
                $c->uptime = $response->getProperty('uptime');
                $c->rx_signal = $response->getProperty('rx-signal');
                $return[] = $c;
            }
        }
        return $return;
    }

}
