Catch exceptions, get rid of last bit of PEAR_Error checks
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 13 Jan 2011 17:23:35 +0000 (12:23 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 13 Jan 2011 17:23:35 +0000 (12:23 -0500)
hermes/lib/Admin.php
hermes/lib/Driver/sql.php
hermes/lib/Form/JobType/Add.php [new file with mode: 0644]
hermes/lib/Form/JobType/Edit/Step1.php [new file with mode: 0644]
hermes/lib/Table.php

index 9be88af..c42b9b5 100644 (file)
@@ -135,16 +135,18 @@ class EditClientStep1Form extends Horde_Form {
     {
         parent::Horde_Form($vars, 'editclientstep1form');
 
-        $clients = Hermes::listClients();
-        if (is_a($clients, 'PEAR_Error')) {
+        try {
+            $clients = Hermes::listClients();
+            if (count($clients)) {
+                $subtype = 'enum';
+                $type_params = array($clients);
+            } else {
+                $subtype = 'invalid';
+                $type_params = array(_("There are no clients to edit"));
+            }
+        } catch (Hermes_Exception $e) {
             $subtype = 'invalid';
             $type_params = array($clients->getMessage());
-        } elseif (count($clients)) {
-            $subtype = 'enum';
-            $type_params = array($clients);
-        } else {
-            $subtype = 'invalid';
-            $type_params = array(_("There are no clients to edit"));
         }
 
         $this->addVariable(_("Client Name"), 'client', $subtype, true, false, null, $type_params);
index 08d5924..803a4d1 100644 (file)
@@ -533,8 +533,6 @@ class Hermes_Driver_Sql extends Hermes_Driver
         }
 
         $deliverables = array();
-        //$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
-        //while (!empty($row) && !is_a($row, 'PEAR_Error')) {
         foreach ($rows as $row) {
             $deliverable = array('id'          => $row['deliverable_id'],
                                  'client_id'   => $row['client_id'],
diff --git a/hermes/lib/Form/JobType/Add.php b/hermes/lib/Form/JobType/Add.php
new file mode 100644 (file)
index 0000000..008176f
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ *
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+class Hermes_Form_JobType_Add extends Horde_Form
+{
+    public function __construct(&$vars)
+    {
+        parent::Horde_Form($vars, 'addjobtypeform');
+        $this->addVariable(_("Job Type"), 'name', 'text', true);
+        $var = &$this->addVariable(_("Enabled?"), 'enabled', 'boolean', false);
+        $var->setDefault(true);
+        $var = &$this->addVariable(_("Billable?"), 'billable', 'boolean', false);
+        $var->setDefault(true);
+        $this->addVariable(_("Hourly Rate"), 'rate', 'number', false);
+    }
+
+}
\ No newline at end of file
diff --git a/hermes/lib/Form/JobType/Edit/Step1.php b/hermes/lib/Form/JobType/Edit/Step1.php
new file mode 100644 (file)
index 0000000..7fd0ba7
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file LICENSE for license information (BSD). If you
+ * did not receive this file, see http://www.horde.org/licenses/bsdl.php.
+ *
+ * @package Hermes
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ */
+class Hermes_Form_JobType_Edit_Step1 extends Horde_Form
+{
+    public function __construct(&$vars)
+    {
+        parent::Horde_Form($vars, 'editjobtypestep1form');
+
+        $values = array();
+        try {
+            $jobtypes = $GLOBALS['injector']->getInstance('Hermes_Driver')->listJobTypes();
+            foreach ($jobtypes as $id => $jobtype) {
+                $values[$id] = $jobtype['name'];
+                if (empty($jobtype['enabled'])) {
+                    $values[$id] .= _(" (DISABLED)");
+                }
+            }
+        } catch (Hermes_Exception $e) {}
+
+        if ($values) {
+            $subtype = 'enum';
+            $type_params = array($values);
+        } else {
+            $subtype = 'invalid';
+            $type_params = array(_("There are no job types to edit"));
+        }
+
+        $this->addVariable(_("JobType Name"), 'jobtype', $subtype, true, false, null, $type_params);
+    }
+
+}
\ No newline at end of file
index c8e9c2d..0ce71a5 100644 (file)
@@ -23,6 +23,11 @@ class Hermes_Table extends Horde_Core_Ui_Widget
      */
     protected $_formVars = array();
 
+    /**
+     *
+     * @return array
+     * @throws Hermes_Exception
+     */
     public function getMetaData()
     {
         if (is_null($this->_metaData)) {
@@ -30,9 +35,7 @@ class Hermes_Table extends Horde_Core_Ui_Widget
             $args = array($name, $this->_config['params']);
             $this->_metaData = $GLOBALS['registry']->callByPackage(
                 $app, 'getTableMetaData', $args);
-            if (is_a($this->_metaData, 'PEAR_Error')) {
-                return $this->_metaData;
-            }
+
 
             // We need to make vars for the columns.
             foreach ($this->_metaData['sections'] as $secname => $section) {
@@ -79,14 +82,12 @@ class Hermes_Table extends Horde_Core_Ui_Widget
      * Returns the largest column count of any section, taking into account
      * 'colspan' attributes.
      *
-     * @return mixed number of columns or PEAR_Error
+     * @return integer number of columns
+     * @throws Hermes_Exception
      */
     public function getColumnCount()
     {
         $res = $this->getMetaData();
-        if (is_a($res, 'PEAR_Error')) {
-            return $res;
-        }
         $colcount = 0;
         foreach ($this->_metaData['sections'] as $section) {
             $sec_colcount = 0;
@@ -112,9 +113,10 @@ class Hermes_Table extends Horde_Core_Ui_Widget
     {
         global $notification;
 
-        $result = $this->getMetaData();
-        if (is_a($result, 'PEAR_Error')) {
-            $notification->push($result, 'horde.error');
+        try {
+            $result = $this->getMetaData();
+        } catch (Hermes_Exception $e) {
+            $notification->push($e->getMessage(), 'horde.error');
             return false;
         }
 
@@ -163,9 +165,10 @@ class Hermes_Table extends Horde_Core_Ui_Widget
         $html .= '</tr></thead>';
 
         // Display data.
-        $data = $this->_getData();
-        if (is_a($data, 'PEAR_Error')) {
-            $notification->push($data, 'horde.error');
+        try {
+            $data = $this->_getData();
+        } catch (Hermes_Exception $e) {
+            $notification->push($e, 'horde.error');
             $data = array();
         }