added sorting option

This commit is contained in:
Steffen Vogel 2013-03-08 03:24:16 +01:00
parent 7e2f040a38
commit 8861e41b16

View file

@ -14,7 +14,7 @@ class DBHost extends Host implements DBObject {
$sql = 'SELECT * FROM ' . $config['db']['tbl']['hosts'] . ' WHERE id = ' . (int) $id;
$result = $this->db->query($sql, 1);
if ($result->count() == 1) {
$host = $result->first();
$this->id = $host['id'];
@ -24,22 +24,22 @@ class DBHost extends Host implements DBObject {
throw new CustomException('Host with id ' . $id . ' not found!');
}
}
public function __destruct() {
//$this->update();
}
public function update() {
$config = Registry::get('config');
$sql = 'UPDATE ' . $config['db']['tbl']['hosts'] . '
SET
hostname = \'' . $this->db->escape($this->toPunycode()) . '\',
zone = \'' . $this->db->escape($this->zone->name) . '\',
password = \'' . $this->db->escape($this->password) . '\',
password = \'' . $this->db->escape(sha1($this->password)) . '\',
generated = \'' .$this->db->escape( $this->generated) . '\'
WHERE id = ' . (int) $this->id;
$this->db->execute($sql);
}
@ -75,18 +75,18 @@ class DBHost extends Host implements DBObject {
public function getRecordsFromDB() {
return DBRecord::get($this->db, array('host' => $this));
}
public function getUrisFromDB() {
return DBRUri::get($this->db, array('host' => $this));
}
public static function get(Database $db, $filter = false) {
public static function get(Database $db, $filter = false, $order = array()) {
$config = Registry::get('config');
$sql = 'SELECT id
FROM ' . $config['db']['tbl']['hosts'] . '
WHERE true';
if (!empty($filter['id']))
$sql .= ' && id = ' . (int) $filter['id'];
if (!empty($filter['host']) && is_string($filter['host']))
@ -97,17 +97,23 @@ class DBHost extends Host implements DBObject {
$sql .= ' && zone = \'' . $db->escape($filter['zone']->name) . '\'';
if (!empty($filter['generated']))
$sql .= ' && generated = ' . ($filter['generated']) ? '1' : '0';
$sql .= ' ORDER BY id ASC';
$sql .= ' ORDER BY';
foreach ($order as $column => $dir) {
$sql .= ' ' . $column . ' ' . $dir . ',';
}
$sql .= ' id ASC';
$result = $db->query($sql);
$hosts = array();
foreach ($result as $host) {
$hosts[] = new self($host['id'], $db);
}
return $hosts;
}
/*
* Output
*/
@ -115,9 +121,9 @@ class DBHost extends Host implements DBObject {
$xmlRecord = parent::toXml($doc);
$xmlRecord->setAttribute('id', $this->id);
return $xmlRecord;
}
}
?>
?>