bcast-bridge/web/include/db_Vlan.class.php
2006-12-11 21:36:44 +01:00

87 lines
1.8 KiB
PHP

<?php
class Vlan {
private $inDB = false;
public $id;
public $trunkid;
public $flags;
public $vlannum;
public $bandwidth;
public $mac = "00:00:00:00:00:00";
private function fromRow($row) {
$retval = new Vlan();
if ($row) {
$retval->inDB = true;
$retval->id = (int)$row['id'];
$retval->trunkid = (int)$row['trunkid'];
$retval->flags = (int)$row['flags'];
$retval->vlannum = (int)$row['vlannum'];
$retval->bandwidth = (int)$row['bandwidth'];
$retval->mac = (string)$row['mac'];
}
return $retval;
}
private function toSql() {
return "trunkid = '{$this->trunkid}',
flags = '{$this->flags}',
vlannum = '{$this->vlannum}',
bandwidth = '{$this->bandwidth}',
mac = '".mysql_real_escape_string($this->mac)."'";
}
function load($id) {
$dbh = Database::getInstance();
$sql = "SELECT id, trunkid, flags, vlannum, bandwidth, mac
FROM vlan
WHERE id = '{$id}'";
$dbh->query($sql);
return self::fromRow($dbh->fetch_assoc());
}
function save() {
$dbh = Database::getInstance();
if ($this->inDB) {
$sql = "UPDATE vlan SET ".$this->toSql()."
WHERE id = '{$this->id}'";
$dbh->query($sql);
} else {
$sql = "INSERT vlan SET ".$this->toSql();
$dbh->query($sql);
$this->iNDB = true;
$this->id = $dbh->insert_id();
}
}
function delete($id) {
$dbh = Database::getInstance();
$sql = "DELETE FROM vlan
WHERE id = '{$id}'";
$dbh->query($sql);
}
function getAll($trunkid = false) {
$dbh = Database::getInstance();
$sql = "SELECT id, trunkid, flags, vlannum, bandwidth, mac
FROM vlan
".($trunkid ? "WHERE trunkid = '{$trunkid}'" : "")."
ORDER BY vlannum";
$dbh->query($sql);
$retval = array();
while ($row = $dbh->fetch_assoc())
$retval[$row['id']] = self::fromRow($row);
return $retval;
}
}
?>