Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1466

Přidáno uživatelem Ondřej Fibich před více než 12 roky(ů)

Upravy:
- odtraneni nepouzivanych funkci

Zobrazit rozdíly:

freenetis/branches/network/application/models/iface.php
}
/**
* Gets ifaces of segment
*
* @param integer $segment_id
* @return Mysql_Result
*/
public function get_ifaces_of_segment($segment_id)
{
return $this->db->query("
SELECT i.id, i.mac, d.id AS device_id, d.name AS device_name,
m.id AS member_id, m.name AS member_name
FROM ifaces i
JOIN devices d ON d.id = i.device_id
JOIN users u ON d.user_id = u.id
JOIN members m ON u.member_id = m.id
WHERE i.segment_id = ?
", $segment_id);
}
/**
* Function gets count of specified mac address. Used for testing existence of that mac.
*
* @param $mac searched mac address
......
self::TYPE_WIRELESS
));
}
/**
* Returns all ifaces of device with IP address as gateway
*
* @author Michal Kliment
* @param integer $device_id
* @return Mysql_Result object
*/
public function get_all_ifaces_of_device_with_gw_ips ($device_id)
{
return $this->db->query("
SELECT i.*, l.name AS link_name, l.medium, l.bitrate, l.duplex
FROM
(
SELECT i.*, ip.id AS ip_address_id
FROM ifaces i
LEFT JOIN ip_addresses ip ON ip.iface_id = i.id AND ip.gateway = 1
WHERE i.device_id = ? AND ip.id IS NOT NULL
GROUP BY ip_address_id
) AS i
JOIN links l ON i.link_id = l.id
", array($device_id));
}
/**
* Gets all ifaces by member and segment
*
* @param integer $member_id
* @param integer $segment_id
* @return Mysql_Result
*/
public function get_all_by_member_segment($member_id, $segment_id)
{
return $this->db->query("
SELECT i.* FROM ifaces i
JOIN devices d ON i.device_id = d.id
JOIN users u ON d.user_id = u.id
WHERE u.member_id = ? AND i.segment_id = ?
", array ($member_id, $segment_id));
}
/**
* Check if ...
*
* @return boolean
*/
public function has_gw_ip_address ()
{
$result = $this->db->query("
SELECT COUNT(*) AS count
FROM
(
SELECT * FROM ip_addresses ip
WHERE ip.gateway = 1
) AS gip
LEFT JOIN ifaces i1 ON gip.iface_id = i1.id
LEFT JOIN vlan_ifaces vi ON gip.vlan_iface_id = vi.id
LEFT JOIN ifaces i2 ON vi.iface_id = i2.id
WHERE IFNULL(i1.id,i2.id) = ?
", array($this->id));
return ($result && $result->current()) ? (bool) $result->current()->count : FALSE;
}
/**
* Gets all ifaces of device without parent
*
* @param integer $device_id
* @return Mysql_Result
*/
public function get_all_ifaces_of_device_without_parent($device_id)
{
return $this->db->query("
SELECT * FROM ifaces i
WHERE i.device_id = ? AND i.id NOT IN
(
SELECT orig_id FROM
(
SELECT i.id AS orig_id, s.* FROM ifaces i
JOIN segments s ON i.segment_id = s.id
WHERE i.device_id = ?
) s
JOIN
(
SELECT i.* FROM ifaces i
LEFT JOIN vlan_ifaces vi ON vi.iface_id = i.id
LEFT JOIN ip_addresses ip1 ON ip1.iface_id = i.id AND ip1.gateway = 1
LEFT JOIN ip_addresses ip2 ON ip2.vlan_iface_id = vi.id AND ip2.gateway = 1
WHERE IFNULL(ip1.id,ip2.id) IS NOT NULL
) i ON i.segment_id = s.id
WHERE i.device_id <> ?
)
", array($device_id, $device_id, $device_id));
}
/**
* Gets array of ifaces with device for dripdown
*
* @author Ondřej fibich
......
}
/**
* Return wireless iface belongs to iface
*
* @author Michal Kliment
* @param type $iface_id
* @return boolean
*/
public function get_wireless_iface ($iface_id)
{
$result = $this->db->query("
SELECT wi.*, ws.*
FROM ifaces i
LEFT JOIN wireless_ifaces wi ON wi.iface_id = i.id
LEFT JOIN segments s ON i.segment_id = s.id
LEFT JOIN wireless_segments ws ON ws.segment_id = s.id
WHERE i.id = ? AND i.type = ?
", $iface_id, Iface_Model::TYPE_WIRELESS);
if ($result && $result->current())
return $result->current();
else
return false;
}
/**
* Gets count of ports of device
*
* @param integer $device_id
* @return integer
*/
public function count_ports_of_device($device_id)
{
return $this->db->where('device_id', $device_id)->count_records('ports');
}
/**
* Gets count off all ports
*
* @return integer
*/
public function count_all_ports()
{
return $this->db->count_records('ports');
}
/**
* Gets all ports
*
* @param integer $limit_from
* @param integer $limit_results
* @param string $order_by
* @param string $order_by_direction
* @return Mysql_Result
*/
public function get_all_ports(
$limit_from = 0, $limit_results = 50,
$order_by = 'ports.id', $order_by_direction = 'ASC')
{
// order by direction check
if (strtolower($order_by_direction) != 'desc')
{
$order_by_direction = 'asc';
}
// query
return $this->db->query("
SELECT devices.name as device_name,segments.name as segment_name,
IFNULL(ports_vlans.vlan_count,0) AS vlan_count, ports.id, ports.name,
ports.port_nr
FROM ports
LEFT JOIN devices ON devices.id = ports.device_id
LEFT JOIN segments ON segments.id = ports.segment_id
LEFT JOIN (
SELECT COUNT(*) as vlan_count,port_id
FROM ports_vlans
GROUP BY port_id
) ports_vlans ON ports_vlans.port_id=ports.id
ORDER BY " . $this->db->escape_column($order_by) . " $order_by_direction
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
");
}
/**
* Gets ports of device
*
* @param integer $device_id
* @return integer
*/
public function get_ports_of_device($device_id)
{
return $this->db->query("
SELECT
i.id AS port_id, i.name AS port_name,
d.name as device_name, i.link_id, l.name as link_name,
IFNULL(pv.vlan_count, 0) AS vlan_count, i.id, i.name,
i.number AS port_nr, l.bitrate, i.port_mode AS mode
FROM ifaces i
LEFT JOIN devices d ON d.id = i.device_id
LEFT JOIN links l ON l.id = i.link_id
LEFT JOIN (
SELECT COUNT(*) as vlan_count, iface_id
FROM ifaces_vlans
GROUP BY iface_id
) pv ON pv.iface_id = i.id
WHERE device_id = ? AND i.type = ?
ORDER BY port_nr ASC
", $device_id, Iface_Model::TYPE_PORT);
}
/**
* Tries to find best suitable interface for connecting of a new device of user.
*
* @author Ondrej Fibich
......
d2.user_id IN (" . implode(',', $usearch) . ") AND
X(ap2.gps) IS NOT NULL AND Y(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(" . $gps['x'] . " - X(ap2.gps), 2) +
POW(" . $gps['y'] . " - Y(ap2.gps), 2))
POW(" . $gps['y'] . " - Y(ap2.gps), 2)) ASC,
d2.user_id DESC
LIMIT 1
) UNION (
SELECT i2.id AS iface_id, d2.id AS device_id, 1 AS priority
......
WHERE i2.type IN(" . implode(',', $can_connect) . ") AND
X(ap2.gps) IS NOT NULL AND Y(ap2.gps) IS NOT NULL
ORDER BY SQRT(POW(" . $gps['x'] . " - X(ap2.gps), 2) +
POW(" . $gps['y'] . " - Y(ap2.gps), 2))
POW(" . $gps['y'] . " - Y(ap2.gps), 2)) ASC,
d2.user_id ASC
LIMIT 1
)
) i

Také k dispozici: Unified diff