From da8503879a08e1b5c1c8263cfa1302c7646112e4 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Thu, 28 Jan 2016 18:53:56 +0100
Subject: [PATCH] HelperFormElement, KeyValueStringParser, AbstractBuildFormd,
 Constants, Database: All Exceptions supplied with an error code

---
 qfq/AbstractBuildForm.php           | 6 +++---
 qfq/Constants.php                   | 7 +++++++
 qfq/Database.php                    | 4 ++--
 qfq/helper/HelperFormElement.php    | 2 +-
 qfq/helper/KeyValueStringParser.php | 2 +-
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/qfq/AbstractBuildForm.php b/qfq/AbstractBuildForm.php
index b8628d2bd..d575fabca 100644
--- a/qfq/AbstractBuildForm.php
+++ b/qfq/AbstractBuildForm.php
@@ -371,7 +371,7 @@ abstract class AbstractBuildForm {
             default:
                 $this->store->setVar(SYSTEM_FORM_ELEMENT, $formElement['name'] . ' / ' . $formElement['id'], STORE_SYSTEM);
                 $this->store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'mode', STORE_SYSTEM);
-                throw new UserException("Unexpected mode '" . $formElement['mode'] . "'");
+                throw new UserException("Unknown mode '" . $formElement['mode'] . "'", ERROR_UNKNOWN_MODE);
                 break;
         }
         return $attribute;
@@ -934,7 +934,7 @@ abstract class AbstractBuildForm {
      */
     public function buildDateJQW(array $formElement, $htmlFormElementId, $value) {
         // TODO: implement
-        throw new UserException("Not implemented yet: buildDateJQW()");
+        throw new UserException("Not implemented yet: buildDateJQW()", ERROR_NOT_IMPLEMENTED);
     }
 
     /**
@@ -945,7 +945,7 @@ abstract class AbstractBuildForm {
      */
     public function buildGridJQW(array $formElement, $htmlFormElementId, $value) {
         // TODO: implement
-        throw new UserException("Not implemented yet: buildGridJQW()");
+        throw new UserException("Not implemented yet: buildGridJQW()", ERROR_NOT_IMPLEMENTED);
     }
 
     /**
diff --git a/qfq/Constants.php b/qfq/Constants.php
index fb21ce951..a3b65d774 100644
--- a/qfq/Constants.php
+++ b/qfq/Constants.php
@@ -88,6 +88,13 @@ const ERROR_UNKNOWN_FORM_RENDER = 1028;
 const ERROR_NAME_LABEL_EMPTY = 1029;
 const ERROR_MISSING_COLUMN_ID = 1030;
 const ERROR_DEBUG = 1031;
+const ERROR_UNKNOWN_MODE = 1032;
+const ERROR_NOT_IMPLEMENTED = 1033;
+const ERROR_RESERVED_KEY_NAME = 1034;
+const ERROR_VALUE_HAS_NO_KEY = 1035;
+const ERROR_DB_EXECUTE = 1036;
+const ERROR_COLUMN_NOT_FOUND_IN_TABLE = 1037;
+
 
 // DB Errors
 //const ERROR_DB_QUERY_SIMPLE = 2000;
diff --git a/qfq/Database.php b/qfq/Database.php
index 72a089daf..ef4916ce6 100644
--- a/qfq/Database.php
+++ b/qfq/Database.php
@@ -145,7 +145,7 @@ class Database {
                 return $row;
             }
         }
-        throw new DbException("Column name '$columnName' not found in table '$table'.");
+        throw new DbException("Column name '$columnName' not found in table '$table'.", ERROR_COLUMN_NOT_FOUND_IN_TABLE);
     }
 
     /**
@@ -232,7 +232,7 @@ class Database {
 
         $this->stmt = $this->pdo->prepare($sql);
         if (false === $this->stmt->execute($parameterArray)) {
-            throw new DbException($this->stmt->errorInfo()[2]);
+            throw new DbException($this->stmt->errorInfo()[2], ERROR_DB_EXECUTE);
         }
 
         $count = $this->stmt->rowCount();
diff --git a/qfq/helper/HelperFormElement.php b/qfq/helper/HelperFormElement.php
index a9b5907f8..bb262a6dd 100644
--- a/qfq/helper/HelperFormElement.php
+++ b/qfq/helper/HelperFormElement.php
@@ -40,7 +40,7 @@ class HelperFormElement {
                         $store = Store::getInstance();
                         $store->setVar(SYSTEM_FORM_ELEMENT, $element['name'] . ' / ' . $element['id'], STORE_SYSTEM);
                         $store->setVar(SYSTEM_FORM_ELEMENT_COLUMN, 'parameter', STORE_SYSTEM);
-                        throw new UserException("Found reserved keyname '$checkKey'");
+                        throw new UserException("Found reserved keyname '$checkKey'", ERROR_RESERVED_KEY_NAME);
                     }
                 }
                 $elements[$key] = array_merge($element, $arr);
diff --git a/qfq/helper/KeyValueStringParser.php b/qfq/helper/KeyValueStringParser.php
index 870ec2237..8e0a9adf9 100644
--- a/qfq/helper/KeyValueStringParser.php
+++ b/qfq/helper/KeyValueStringParser.php
@@ -113,7 +113,7 @@ class KeyValueStringParser {
 
             if ($key === '') {
                 // ":", ":1"
-                throw new UserException("Value has no key: '$keyValuePairString'");
+                throw new UserException("Value has no key: '$keyValuePairString'", ERROR_VALUE_HAS_NO_KEY);
             }
 
             if (count($keyValueArray) === 2) {
-- 
GitLab