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_Model extends ORM
{
protected $has_many = array('vlan_ifaces');
protected $has_and_belongs_to_many = array('ports');
/**
* Get count of vlans
*
* @return integer
*/
public function count_all_vlans()
{
return $this->db->count_records('vlans');
}
/**
*
* @param integer $limit_from
* @param integer $limit_results
* @param string $order_by
* @param integer $order_by_direction
* @return unknown_type
*/
public function get_all_vlans($limit_from = 0, $limit_results = 50,
$order_by = 'vlans.id', $order_by_direction = 'ASC')
{
// order by check
if (!$this->has_column($order_by))
{
$order_by = 'vlans.id';
}
// order by direction check
$order_by_direction = strtolower($order_by_direction);
if ($order_by_direction != 'desc')
{
$order_by_direction = 'asc';
}
// query
return $this->db->query("
SELECT IFNULL(vlan_ifaces.vlan_ifaces_count,0) AS vlan_ifaces_count,
IFNULL(ports_vlans.ports_count,0) AS ports_count, vlans.*
FROM vlans
LEFT JOIN (
SELECT COUNT(*) as vlan_ifaces_count,vlan_id
FROM vlan_ifaces
GROUP BY vlan_id
) vlan_ifaces ON vlan_ifaces.vlan_id = vlans.id
LEFT JOIN (
SELECT COUNT(*) as ports_count,vlan_id
FROM ports_vlans
GROUP BY vlan_id
) ports_vlans ON ports_vlans.vlan_id=vlans.id
ORDER BY $order_by $order_by_direction
LIMIT " . intval($limit_from) . ", " . intval($limit_results) ."
");
}
/**
* Override default ORM function select_list due to
* need of ordering by another column than are key and value
*
* @author Michal Kliment
* @return array
*/
public function select_list($key = NULL, $val = NULL, $order_val = TRUE)
{
$arr_vlans = array();
$vlans = $this->orderby('tag_802_1q')
->find_all();
foreach ($vlans as $vlan)
$arr_vlans[$vlan->id] = $vlan->tag_802_1q." - ".$vlan->name;
return $arr_vlans;
}
}
(76-76/81)