Projekt

Obecné

Profil

<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/

/**
* @package Model
*/
class Vlan_iface_Model extends ORM
{
protected $belongs_to = array('iface','vlan');
protected $has_many = array('ip_addresses');

/**
* Function counts all records.
*
* @return integer
*/
public function count_all_vlan_ifaces()
{
return $this->db->count_records('vlan_ifaces');
}

/**
* Returns all VLAN interfaces which belong to device
*
* @author Michal Kliment
* @param integer $device_id
* @return unknown_type
*/
public function get_all_vlan_ifaces_by_device_id ($device_id)
{
return $this->db->query("
SELECT vi.*, vi.id AS vlan_iface_id, vi.name AS vlan_iface_name,
v.id AS vlan_id, v.name AS vlan_name,
v.tag_802_1q, i.id AS iface_id, i.name AS iface_name
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
WHERE i.device_id = ?
ORDER BY tag_802_1q
", array($device_id));
}

/**
* Returns all VLAN interface of device
*
* @author Michal Kliment
* @param int $device_id
* @return MySQL iterator object
*/
public function get_all_vlan_ifaces_with_ip_addresses_by_device_id ($device_id)
{
return $this->db->query("
SELECT
vi.*,
vi.id AS vlan_iface_id,
vi.name AS vlan_iface_name,
v.id AS vlan_id,
v.name AS vlan_name,
v.tag_802_1q,
i.id AS iface_id,
i.name AS iface_name,
ip.id AS ip_address_id,
ip.ip_address,
32-log2((~INET_ATON(s.netmask) & 0xffffffff) + 1) AS subnet_range
FROM vlan_ifaces vi
LEFT JOIN vlans v ON vi.vlan_id = v.id
LEFT JOIN ifaces i ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip ON vi.id = ip.vlan_iface_id
LEFT JOIN subnets s ON ip.subnet_id = s.id
WHERE i.device_id = ?
ORDER BY tag_802_1q
", array ($device_id));
}
/**
* Returns all vlan ifaces of iface
*
* @author Michal Kliment
* @param integer $iface_id
* @return MySQL_Iterator
*/
public function get_all_vlan_ifaces_of_iface ($iface_id)
{
return $this->db->query("
SELECT id, name
FROM vlan_ifaces
WHERE iface_id = ?
ORDER BY id ASC
", array($iface_id));
}
}
(79-79/84)