From 8861e41b165d14221ba0660fa2fb410fb60f8459 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 8 Mar 2013 03:24:16 +0100 Subject: [PATCH] added sorting option --- include/dbhost.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/include/dbhost.php b/include/dbhost.php index 3369dfc..6c1126c 100755 --- a/include/dbhost.php +++ b/include/dbhost.php @@ -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; } } -?> \ No newline at end of file +?>