From 6f43cbec00da9575c8d0c54c5dce0068083b49d0 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Mon, 29 Mar 2010 16:48:08 -0400 Subject: [PATCH] Shout: Add recording management code --- shout/lib/Driver/Sql.php | 62 ++++++++++++++++++++++++++++++++++ shout/lib/Forms/RecordingForm.php | 69 ++++++++++++++++++++++++++++++++++++++ shout/templates/recordings/add.inc | 2 ++ 3 files changed, 133 insertions(+) create mode 100644 shout/lib/Forms/RecordingForm.php create mode 100644 shout/templates/recordings/add.inc diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index bf23fe4ef..1a3169517 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -506,6 +506,68 @@ class Shout_Driver_Sql extends Shout_Driver return true; } + public function getRecordings($account) + { + $sql = 'SELECT id, filename FROM recordings ' . + 'WHERE account_id = (SELECT id FROM accounts WHERE code = ?);'; + $args = array($account); + $msg = 'SQL query in Shout_Driver_Sql#getRecordings(): ' . $sql; + Horde::logMessage($msg, 'DEBUG'); + $result = $this->_db->query($sql, $args); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + if ($row instanceof PEAR_Error) { + throw new Shout_Exception($row); + } + + $recordings = array(); + while ($row && !($row instanceof PEAR_Error)) { + $id = $row['id']; + $recordings[$id] = $row; + + /* Advance to the new row in the result set. */ + $row = $result->fetchRow(DB_FETCHMODE_ASSOC); + } + + $result->free(); + return $recordings; + } + + public function addRecording($account, $name) + { + $sql = 'INSERT INTO recordings (filename, account_id) ' . + 'VALUES (?,(SELECT id FROM accounts WHERE code = ?))'; + $args = array($name, $account); + + $msg = 'SQL query in Shout_Driver_Sql#addRecording(): ' . $sql; + Horde::logMessage($msg, 'DEBUG'); + $result = $this->_write_db->query($sql, $args); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + return true; + } + + public function deleteRecording($account, $name) + { + $sql = 'DELETE FROM recordings WHERE filename = ? AND account_id = ' . + '(SELECT id FROM accounts WHERE code = ?)'; + $vars = array($name, $account); + + $msg = 'SQL query in Shout_Driver_Sql#deleteRecording(): ' . $sql; + Horde::logMessage($msg, 'DEBUG'); + $result = $this->_write_db->query($sql, $args); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + return true; + } + /** * Attempts to open a persistent connection to the SQL server. * diff --git a/shout/lib/Forms/RecordingForm.php b/shout/lib/Forms/RecordingForm.php new file mode 100644 index 000000000..50b58e162 --- /dev/null +++ b/shout/lib/Forms/RecordingForm.php @@ -0,0 +1,69 @@ +account; + $title = sprintf(_("$formtitle")); + parent::__construct($vars, $title); + + $this->addHidden('', 'action', 'text', true); + $this->addVariable(_("Name"), 'name', 'text', true); + //$this->addVariable(_("Description"), 'description', 'text', true); + //$this->addVariable(_("Text"), 'text', 'text', true); + return true; + } + + public function execute() + { + $shout = $GLOBALS['registry']->getApiInstance('shout', 'application'); + + $action = $this->_vars->get('action'); + $account = $this->_vars->get('account'); + $name = $this->_vars->get('name'); + + $shout->storage->addRecording($account, $name); + } + +} + +class ConferenceDeleteForm extends Horde_Form +{ + function __construct(&$vars) + { + $devid = $vars->get('devid'); + $account = $vars->get('account'); + + $title = _("FIXME Delete Recording %s - Account: %s"); + $title = sprintf($title, $devid, $_SESSION['shout']['accounts'][$account]['name']); + parent::__construct($vars, $title); + + $this->addHidden('', 'account', 'text', true); + $this->addHidden('', 'devid', 'text', true); + $this->addHidden('', 'action', 'text', true); + $this->setButtons(array(_("Delete"), _("Cancel"))); + } + + function execute() + { + throw new Shout_Exception('FIXME'); + $shout = $GLOBALS['registry']->getApiInstance('shout', 'application'); + $account = $this->_vars->get('account'); + $devid = $this->_vars->get('devid'); + $shout->devices->deleteDevice($account, $devid); + } +} \ No newline at end of file diff --git a/shout/templates/recordings/add.inc b/shout/templates/recordings/add.inc new file mode 100644 index 000000000..2f57c39d0 --- /dev/null +++ b/shout/templates/recordings/add.inc @@ -0,0 +1,2 @@ +renderActive($RENDERER, $vars, Horde::applicationUrl('recordings.php'), 'post'); -- 2.11.0