<?php

namespace app\models\mikrotik\ppp;

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 $name;
    public $service;
    public $caller_id;
    public $address;
    public $uptime;
    public $encoding;

    public function rules() {
        return [
            ['id', 'string'],
            ['name', 'string'],
            ['service', 'string'],
            ['caller_id', 'string'],
            ['address', 'string'],
            ['uptime', 'string'],
            ['encoding', 'string'],
        ];
    }

    public function getAll() {
        $connect = MikrotikConnect::Instance();
        $getRequest = new RouterOS\Request('/ppp/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->name = $response->getProperty('name');
                $c->service = $response->getProperty('service');
                $c->caller_id = $response->getProperty('caller-id');
                $c->address = $response->getProperty('address');
                $c->uptime = $response->getProperty('uptime');
                $c->encoding = $response->getProperty('encoding');
                $return[] = $c;
            }
        }
        return $return;
    }

}
