Make Server constructor take a row or an id

pull/1207/head
Isaac Connor 2015-12-02 10:04:47 -05:00
parent aa91e69a9b
commit a799a1ce79
1 changed files with 13 additions and 9 deletions

View File

@ -1,15 +1,19 @@
<?php
require_once( 'database.php' );
class Server {
public function __construct( $id ) {
if ( $id ) {
$s = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $id ) );
if ( $s ) {
foreach ($s as $k => $v) {
$this->{$k} = $v;
}
} else {
Error("Unable to load Server record for Id=" . $id );
public function __construct( $IdOrRow ) {
$row = NULL;
if ( is_integer( $IdOrRow ) or is_numeric( $IdOrRow ) ) {
$row = dbFetchOne( 'SELECT * FROM Servers WHERE Id=?', NULL, array( $IdOrRow ) );
if ( ! $row ) {
Error("Unable to load Server record for Id=" . $IdOrRow );
}
} elseif ( is_array( $IdOrRow ) ) {
$row = $IdOrRow;
}
if ( $row ) {
foreach ($row as $k => $v) {
$this->{$k} = $v;
}
} else {
$this->{'Name'} = '';