From: Ben Klang Date: Sat, 3 Apr 2010 01:50:49 +0000 (-0400) Subject: Shout: Allow selecting numbers by account X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=10a236df6c041291de6bf9843ed98b69a092811a;p=horde.git Shout: Allow selecting numbers by account --- diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index 6bf50e948..dc6d3e755 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -120,6 +120,7 @@ class Shout_Driver_Sql extends Shout_Driver throw new Shout_Exception($row); } + $menus = array(); while ($row && !($row instanceof PEAR_Error)) { $menu = $row['name']; $menus[$menu] = array( @@ -590,17 +591,29 @@ class Shout_Driver_Sql extends Shout_Driver return true; } - public function getNumbers() + public function getNumbers($account = null) { - $sql = 'SELECT numbers.id AS id, numbers.did AS number, ' . - 'accounts.code AS accountcode, menus.name AS menuName ' . - 'FROM numbers ' . - 'INNER JOIN accounts ON numbers.account_id = accounts.id ' . - 'INNER JOIN menus ON numbers.menu_id = menus.id'; + if (!empty($account)) { + $sql = 'SELECT numbers.id AS id, numbers.did AS number, ' . + 'accounts.code AS accountcode, menus.name AS menuName ' . + 'FROM numbers ' . + 'INNER JOIN accounts ON numbers.account_id = accounts.id ' . + 'INNER JOIN menus ON numbers.menu_id = menus.id ' . + 'WHERE accounts.code = ?'; + $values = array($account); + + } else { + $sql = 'SELECT numbers.id AS id, numbers.did AS number, ' . + 'accounts.code AS accountcode, menus.name AS menuName ' . + 'FROM numbers ' . + 'INNER JOIN accounts ON numbers.account_id = accounts.id ' . + 'INNER JOIN menus ON numbers.menu_id = menus.id'; + $values = array(); + } $msg = 'SQL query in Shout_Driver_Sql#getNumbers(): ' . $sql; Horde::logMessage($msg, 'DEBUG'); - $result = $this->_db->query($sql, $args); + $result = $this->_db->query($sql, $values); if ($result instanceof PEAR_Error) { throw new Shout_Exception($result); }