inDB = true; $retval->id = (int)$row['id']; $retval->bridgeid = (int)$row['bridgeid']; $retval->flags = (int)$row['flags']; $retval->name = (string)$row['name']; $retval->fullname = (string)$row['fullname']; } return $retval; } private function toSql() { return "bridgeid = '{$this->bridgeid}', flags = '{$this->flags}', name = '".mysql_real_escape_string($this->name)."'"; } function load($id) { $dbh = Database::getInstance(); $sql = "SELECT t.id, t.bridgeid, t.flags, t.name, CONCAT(b.name, ': ', t.name) AS fullname FROM trunk t, bridge b WHERE id = '{$id}' AND b.id = t.bridgeid"; $dbh->query($sql); return self::fromRow($dbh->fetch_assoc()); } function save() { $dbh = Database::getInstance(); if ($this->inDB) { $sql = "UPDATE trunk SET ".$this->toSql()." WHERE id = '{$this->id}'"; $dbh->query($sql); } else { $sql = "INSERT trunk SET ".$this->toSql(); $dbh->query($sql); $this->iNDB = true; $this->id = $dbh->insert_id(); } } function delete($id) { $dbh = Database::getInstance(); $sql = "DELETE FROM trunk WHERE id = '{$id}'"; $dbh->query($sql); $vlans = Vlan::getAll($id); foreach ($vlans as $vlan) Vlan::delete($vlan->id); } function getAll($bridgeid = false) { $dbh = Database::getInstance(); $sql = "SELECT t.id, t.bridgeid, t.flags, t.name, CONCAT(b.name, ': ', t.name) AS fullname FROM trunk t, bridge b WHERE ".($bridgeid ? "bridgeid = '{$bridgeid}'" : "1")." AND b.id = t.bridgeid ORDER BY b.name, t.name"; $dbh->query($sql); $retval = array(); while ($row = $dbh->fetch_assoc()) $retval[$row['id']] = self::fromRow($row); return $retval; } } ?>