<?php

class NetworkScanResult extends PhonalisaRecord
{

    public $mac;
    public $ipv4;
    public $vendor;
    public $supported;
    public $knownDevice;
    public $created;

    public static function myAttributes()
    {
        return array(
            "mac" => "mac",
            "ipv4" => "ipv4",
            "vendor" => "vendor",
            "supported" => "supported",
            "knownDevice" => "knownDevice",
            "created" => "created"
        );
    }

    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public function rules()
    {
        return array(
            array("mac, ipv4, vendor, supported, knownDevice, created", "safe"), //FIXME ? 
            array('mac, ipv4, vendor, supported, knownDevice, created', 'safe', 'on' => 'search')
        );
    }

    public function attributeLabels()
    {
        return array(
            "mac" => __("NETWORK_SCAN_MODEL_MAC"),
            "ipv4" => __("NETWORK_SCAN_MODEL_IPV4"),
            "vendor" => __("NETWORK_SCAN_MODEL_VENDOR"),
            "supported" => __("NETWORK_SCAN_MODEL_SUPPORTED"),
            "created" => __("NETWORK_SCAN_MODEL_CREATED")
        );
    }

    public function search($order = 'vendor')
    {
        $criteria = new CDbCriteria;
        $filter = $this->getFilter($criteria, $order);
        $filter['pagination'] = array("pageSize" => 100000); //FIXME: set pagination false will result in an empty table...

        if ($filter != null) {
            $dataprovider = new CPhonalisaDataProvider($this, $filter);
            if ($dataprovider->totalItemCount == 0) {
                $dataprovider->data = array($this);
            }
            return $dataprovider;
        }
    }
}
