Shout: Add recording management code
authorBen Klang <ben@alkaloid.net>
Mon, 29 Mar 2010 20:48:08 +0000 (16:48 -0400)
committerBen Klang <ben@alkaloid.net>
Mon, 29 Mar 2010 20:48:41 +0000 (16:48 -0400)
shout/lib/Driver/Sql.php
shout/lib/Forms/RecordingForm.php [new file with mode: 0644]
shout/templates/recordings/add.inc [new file with mode: 0644]

index bf23fe4..1a31695 100644 (file)
@@ -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 (file)
index 0000000..50b58e1
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Copyright 2010 Alkaloid Networks LLC (http://projects.alkaloid.net)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see
+ * http://www.opensource.org/licenses/bsd-license.php.
+ *
+ * @package Shout
+ */
+
+class RecordingDetailsForm extends Horde_Form {
+
+    function __construct(&$vars)
+    {
+
+        $formtitle = "Create Recording";
+
+        $curaccount = $_SESSION['shout']['curaccount'];
+        $accountname = $vars->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 (file)
index 0000000..2f57c39
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+$Form->renderActive($RENDERER, $vars, Horde::applicationUrl('recordings.php'), 'post');