From 11d3d7d7c0ee560aab1a972f82f461ff69fb9b10 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 20 Apr 2017 18:28:20 +0200 Subject: [PATCH] 1st release --- application/config/fhcomplete.php | 1 + application/config/udfmasterschema.json | 71 ++++++++++++++++ application/controllers/system/TestUDF.php | 28 +++++++ application/libraries/WidgetLib.php | 43 ++++++++++ application/models/system/UDF_model.php | 15 ++++ application/views/system/testudf.php | 24 ++++++ application/widgets/UDF_widget.php | 96 ++++++++++++++++++++++ 7 files changed, 278 insertions(+) create mode 100644 application/config/udfmasterschema.json create mode 100644 application/controllers/system/TestUDF.php create mode 100644 application/models/system/UDF_model.php create mode 100644 application/views/system/testudf.php create mode 100644 application/widgets/UDF_widget.php diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index f51185a2d..976a5f433 100755 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -208,6 +208,7 @@ $config['fhc_acl'] = array 'system.tbl_webservicelog' => 'basis/webservicelog', 'system.tbl_webservicerecht' => 'basis/webservicerecht', 'system.tbl_webservicetyp' => 'basis/webservicetyp', + 'system.tbl_udf' => 'system/udf', 'testtool.tbl_ablauf' => 'basis/ablauf', 'testtool.tbl_antwort' => 'basis/antwort', 'testtool.tbl_frage' => 'basis/frage', diff --git a/application/config/udfmasterschema.json b/application/config/udfmasterschema.json new file mode 100644 index 000000000..fa06dc80d --- /dev/null +++ b/application/config/udfmasterschema.json @@ -0,0 +1,71 @@ +{ + "title": "UDF", + "type": "object", + "tableswhitelist": { + "type": "string", + "enum": ["tbl_person", "tbl_prestudent", "tbl_mitarbeiter", "tbl_lehrveranstaltung", "tbl_lehreinheit"] + }, + "properties": { + "name": { + "type": "string" + }, + "description": { + "type": "array", + }, + "placeholder": { + "type": "array", + }, + "title": { + "type": "array", + }, + "type": { + "type": "string", + "enum": ["checkbox", "textfield", "textarea", "date", "dropdown", "multipledropdown"] + }, + "sort": { + "type": "integer" + }, + "defaultValue": { + "type": "string" + }, + "validation": { + "type": "object", + "properties": { + "required": { + "type": "boolean" + }, + "min-length": { + "type": "integer" + }, + "max-length": { + "type": "integer" + }, + "min-value": { + "type": "integer" + }, + "min-value": { + "type": "integer" + }, + "regex": { + "type": "object", + "properties": { + "language": "string", + "expression": "string" + } + } + } + }, + "listValues": { + "type": "object", + "properties": { + "sql": { + "type": "string" + }, + "enum": { + "type": "array" + } + } + } + }, + "required": ["type", "name"] +} \ No newline at end of file diff --git a/application/controllers/system/TestUDF.php b/application/controllers/system/TestUDF.php new file mode 100644 index 000000000..ee1f60dbb --- /dev/null +++ b/application/controllers/system/TestUDF.php @@ -0,0 +1,28 @@ +load->library('WidgetLib'); + } + + /** + * + */ + public function index() + { + $data = array ( + 'schema' => 'public', + 'table' => 'tbl_person', + 'field' => 'schuhgroesse' + ); + + $this->load->view('system/testudf', $data); + } +} \ No newline at end of file diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php index 52fbd0071..7117deedb 100644 --- a/application/libraries/WidgetLib.php +++ b/application/libraries/WidgetLib.php @@ -213,6 +213,38 @@ class WidgetLib return new $class($class, $data, $htmlArgs); } + /** + * + */ + public function UDFWidget($args, $htmlArgs = array()) + { + if (!empty($args[UDF_widget_tpl::SCHEMA_ARG_NAME]) + && !empty($args[UDF_widget_tpl::TABLE_ARG_NAME]) + && !empty($args[UDF_widget_tpl::FIELD_ARG_NAME])) + { + return $this->widget( + UDF_widget_tpl::WIDGET_NAME, + $args, + $htmlArgs + ); + } + else + { + if (empty($args[UDF_widget_tpl::SCHEMA_ARG_NAME])) + { + show_error(UDF_widget_tpl::SCHEMA_ARG_NAME.' parameter is missing!'); + } + if (empty($args[UDF_widget_tpl::TABLE_ARG_NAME])) + { + show_error(UDF_widget_tpl::TABLE_ARG_NAME.' parameter is missing!'); + } + if (empty($args[UDF_widget_tpl::FIELD_ARG_NAME])) + { + show_error(UDF_widget_tpl::FIELD_ARG_NAME.' parameter is missing!'); + } + } + } + /** * Enable cache for all partials with TTL, default TTL is 60 * @param int $ttl @@ -794,4 +826,15 @@ class DropdownWidget extends Widget array_unshift($this->elementsArray->retval, $element); } +} + +/** + * + */ +abstract class UDF_widget_tpl extends Widget +{ + const WIDGET_NAME = 'UDF_widget'; + const SCHEMA_ARG_NAME = 'schema'; + const TABLE_ARG_NAME = 'table'; + const FIELD_ARG_NAME = 'field'; } \ No newline at end of file diff --git a/application/models/system/UDF_model.php b/application/models/system/UDF_model.php new file mode 100644 index 000000000..85bfec8bd --- /dev/null +++ b/application/models/system/UDF_model.php @@ -0,0 +1,15 @@ +dbTable = 'system.tbl_udf'; + $this->pk = array('schema', 'table'); + $this->hasSequence = false; + } +} \ No newline at end of file diff --git a/application/views/system/testudf.php b/application/views/system/testudf.php new file mode 100644 index 000000000..c6635aa1c --- /dev/null +++ b/application/views/system/testudf.php @@ -0,0 +1,24 @@ +load->view("templates/header", array("title" => "UDF")); ?> + + + +
+ UDFWidget: +
+ +
+ widgetlib->UDFWidget( + array( + UDF_widget_tpl::SCHEMA_ARG_NAME => $schema, + UDF_widget_tpl::TABLE_ARG_NAME => $table, + UDF_widget_tpl::FIELD_ARG_NAME => $field + ), + array('name' => 'schuhgroesse', 'id' => 'schuhgroesseUDF') + ); + ?> +
+ + + +load->view("templates/footer"); ?> \ No newline at end of file diff --git a/application/widgets/UDF_widget.php b/application/widgets/UDF_widget.php new file mode 100644 index 000000000..ebe0110f8 --- /dev/null +++ b/application/widgets/UDF_widget.php @@ -0,0 +1,96 @@ +_ci->load->model('system/UDF_model', 'UDFModel'); + + $udfResults = $this->_ci->UDFModel->loadWhere( + array( + 'schema' => $schema, + 'table' => $table + ) + ); + + if (isError($udfResults)) + { + if (is_object($udfResults) && isset($udfResults->retval)) + { + show_error($udfResults->retval); + } + else if (is_string($udfResults)) + { + show_error($udfResults); + } + else + { + show_error('UDF_widget: generic error occurred'); + } + } + else if (!hasData($udfResults)) + { + show_error(sprintf('%s.%s does not contain UDF', $schema, $table)); + } + else + { + $udf = $udfResults->retval[0]; + if (isset($udf->jsons)) + { + $jsonSchema = json_decode($udf->jsons); + if (is_object($jsonSchema)) + { + if (isset($jsonSchema->type)) + { + var_dump($jsonSchema); + + if ($jsonSchema->type == 'checkbox') + { + + } + else if ($jsonSchema->type == 'textfield') + { + + } + else if ($jsonSchema->type == 'textarea') + { + + } + else if ($jsonSchema->type == 'date') + { + + } + else if ($jsonSchema->type == 'dropdown') + { + $dropdownWidget = new DropdownWidget(); + } + else if ($jsonSchema->type == 'multipledropdown') + { + + } + } + else + { + show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table)); + } + } + else + { + show_error(sprintf('%s.%s: Not a valid json schema', $schema, $table)); + } + } + else + { + show_error(sprintf('%s.%s: Does not contain "jsons" field', $schema, $table)); + } + } + } +} \ No newline at end of file