diff --git a/application/controllers/system/TestUDF.php b/application/controllers/system/TestUDF.php
index 08ad72e1b..40ed5a04b 100644
--- a/application/controllers/system/TestUDF.php
+++ b/application/controllers/system/TestUDF.php
@@ -10,6 +10,9 @@ class TestUDF extends VileSci_Controller
// Loads the widget library
$this->load->library('WidgetLib');
+
+ //
+ $this->load->model('person/Person_model', 'PersonModel');
}
/**
@@ -17,7 +20,11 @@ class TestUDF extends VileSci_Controller
*/
public function index()
{
- $data = array();
+ $person = $this->PersonModel->load(1);
+
+ $data = array(
+ 'udfs' => $this->PersonModel->getUDFs()
+ );
$this->load->view('system/testudf', $data);
}
diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php
index 04ec7c67a..bf16a777f 100644
--- a/application/core/DB_Model.php
+++ b/application/core/DB_Model.php
@@ -17,6 +17,8 @@ class DB_Model extends FHC_Model
protected $hasSequence; // False if this table has a composite primary key that is not using a sequence
// True if this table has a primary key that uses a sequence
+ protected $UDFs; //
+
function __construct($dbTable = null, $pk = null, $hasSequence = true)
{
parent::__construct();
@@ -24,6 +26,7 @@ class DB_Model extends FHC_Model
$this->pk = $pk;
$this->hasSequence = $hasSequence;
$this->load->database();
+ $this->UDFs = array();
}
/** ---------------------------------------------------------------
@@ -704,6 +707,27 @@ class DB_Model extends FHC_Model
return $result;
}
+ /**
+ *
+ */
+ public function getUDFs()
+ {
+ return $this->UDFs;
+ }
+
+ /**
+ *
+ */
+ public function getUDF($udf)
+ {
+ if (isset($this->UDFs[$udf]))
+ {
+ return $this->UDFs[$udf];
+ }
+
+ return null;
+ }
+
/**
* Checks if the caller is entitled to perform this operation with this right
*/
@@ -799,6 +823,7 @@ class DB_Model extends FHC_Model
foreach($jsonValues as $key => $value)
{
$tmpResult->{$key} = $value;
+ $this->UDFs[$key] = $value; //
}
}
unset($tmpResult->{$toBeConverted->name});
diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php
index cd139adb7..6a0b8cdb8 100644
--- a/application/libraries/WidgetLib.php
+++ b/application/libraries/WidgetLib.php
@@ -218,10 +218,14 @@ class WidgetLib
*/
public function UDFWidget($args, $htmlArgs = array())
{
- if (!empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME])
- && !empty($args[UDFWidgetTpl::TABLE_ARG_NAME])
- && !empty($args[UDFWidgetTpl::FIELD_ARG_NAME]))
+ if (!empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]) && !empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
{
+ //
+ if (empty($args[UDFWidgetTpl::FIELD_ARG_NAME]) && !isset($htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK]))
+ {
+ $htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK] = true;
+ }
+
return $this->widget(
UDFWidgetTpl::WIDGET_NAME,
$args,
@@ -238,10 +242,6 @@ class WidgetLib
{
show_error(UDFWidgetTpl::TABLE_ARG_NAME.' parameter is missing!');
}
- if (empty($args[UDFWidgetTpl::FIELD_ARG_NAME]))
- {
- show_error(UDFWidgetTpl::FIELD_ARG_NAME.' parameter is missing!');
- }
}
}
@@ -646,6 +646,8 @@ class Widget extends Partial
const HTML_NAME = 'name'; // HTML name attribute
const HTML_ID = 'id'; // HTML id attribute
+ const EXTERNAL_BLOCK = 'externalBlock'; //
+
/**
* It gets also the htmlArgs array as parameter, it will be used to set the HTML properties
*/
@@ -736,6 +738,30 @@ class Widget extends Partial
}
}
}
+
+ /**
+ *
+ */
+ public static function printStartBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK])
+ && $htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK] === true)
+ {
+ echo '
';
+ }
+ }
+
+ /**
+ *
+ */
+ public static function printEndBlock($htmlArgs)
+ {
+ if (isset($htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK])
+ && $htmlArgs[Widget::HTML_ARG_NAME][Widget::EXTERNAL_BLOCK] === true)
+ {
+ echo '
';
+ }
+ }
}
/**
@@ -1159,6 +1185,7 @@ abstract class UDFWidgetTpl extends Widget
const SCHEMA_ARG_NAME = 'schema';
const TABLE_ARG_NAME = 'table';
const FIELD_ARG_NAME = 'field';
+ const UDFS_ARG_NAME = 'udfs';
const TITLE = 'description';
const LABEL = 'title';
diff --git a/application/views/system/testudf.php b/application/views/system/testudf.php
index dca677e4f..1791e4190 100644
--- a/application/views/system/testudf.php
+++ b/application/views/system/testudf.php
@@ -2,20 +2,12 @@
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'schuhgroesse',
- DropdownWidget::SELECTED_ELEMENT => array(42, 44)
- ),
- array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName', 'size' => '9')
- );
- ?>
-
+
+
+
+
+
@@ -24,99 +16,8 @@
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'headSize'
- ),
- array('id' => 'headSizeID', 'name' => 'headSizeName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'bellySize'
- ),
- array('id' => 'bellySizeID', 'name' => 'bellySizeName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'nickname'
- ),
- array('id' => 'nicknameID', 'name' => 'nicknameName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'age'
- ),
- array('id' => 'ageID', 'name' => 'ageName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'agree'
- ),
- array('id' => 'agreeID', 'name' => 'agreeName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'disagree'
- ),
- array('id' => 'disagreeID', 'name' => 'disagreeName')
- );
- ?>
-
-
-
-
-
- widgetlib->UDFWidget(
- array(
- UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
- UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
- UDFWidgetTpl::FIELD_ARG_NAME => 'dunno'
- ),
- array('id' => 'dunnoID', 'name' => 'dunnoName')
+ UDFWidgetTpl::UDFS_ARG_NAME => $udfs
+ )
);
?>
diff --git a/application/views/widgets/checkbox.php b/application/views/widgets/checkbox.php
index b73ebb24a..8fb459850 100644
--- a/application/views/widgets/checkbox.php
+++ b/application/views/widgets/checkbox.php
@@ -1,3 +1,4 @@
+
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/application/views/widgets/dropdown.php b/application/views/widgets/dropdown.php
index c5b83603f..6494d180f 100644
--- a/application/views/widgets/dropdown.php
+++ b/application/views/widgets/dropdown.php
@@ -1,3 +1,4 @@
+
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/application/views/widgets/textarea.php b/application/views/widgets/textarea.php
index 44ee51953..920211b69 100644
--- a/application/views/widgets/textarea.php
+++ b/application/views/widgets/textarea.php
@@ -1,3 +1,4 @@
+
>
-
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/application/views/widgets/textfield.php b/application/views/widgets/textfield.php
index ac0d22547..ce01bd463 100644
--- a/application/views/widgets/textfield.php
+++ b/application/views/widgets/textfield.php
@@ -1,3 +1,4 @@
+
value=""
->
\ No newline at end of file
+>
+
\ No newline at end of file
diff --git a/application/widgets/UDFWidget.php b/application/widgets/UDFWidget.php
index 0f6fe934c..91aef73df 100644
--- a/application/widgets/UDFWidget.php
+++ b/application/widgets/UDFWidget.php
@@ -11,9 +11,13 @@ class UDFWidget extends UDFWidgetTpl
{
$schema = $widgetData[UDFWidgetTpl::SCHEMA_ARG_NAME];
$table = $widgetData[UDFWidgetTpl::TABLE_ARG_NAME];
- $field = $widgetData[UDFWidgetTpl::FIELD_ARG_NAME];
- $udfResults = $this->_loadUDF($schema, $table, $field);
+ if (isset($widgetData[UDFWidgetTpl::FIELD_ARG_NAME]))
+ {
+ $field = $widgetData[UDFWidgetTpl::FIELD_ARG_NAME];
+ }
+
+ $udfResults = $this->_loadUDF($schema, $table);
if (hasData($udfResults))
{
$udf = $udfResults->retval[0];
@@ -22,6 +26,7 @@ class UDFWidget extends UDFWidgetTpl
$jsonSchemas = json_decode($udf->jsons);
if (is_object($jsonSchemas) || is_array($jsonSchemas))
{
+ //
if (is_object($jsonSchemas))
{
$jsonSchemasArray = array($jsonSchemas);
@@ -31,38 +36,45 @@ class UDFWidget extends UDFWidgetTpl
$jsonSchemasArray = $jsonSchemas;
}
- $found = false;
+ $found = false; //
+ $this->_sortJsonSchemas($jsonSchemasArray); //
+
+ //
foreach($jsonSchemasArray as $jsonSchema)
{
- if (isset($jsonSchema->name) && $field === $jsonSchema->name)
+ //
+ if (!isset($jsonSchema->type))
{
- if (isset($jsonSchema->type))
- {
- $this->_setAttributesWithPhrases($jsonSchema);
-
- $this->_setValidationAttributes($jsonSchema);
-
- $this->_render($jsonSchema);
- }
- else
- {
- show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
- }
-
- $found = true;
+ show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
break;
}
- else
+ if (!isset($jsonSchema->name))
{
- if (!isset($jsonSchema->name))
+ show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table));
+ break;
+ }
+
+ //
+ if ((isset($field) && $field == $jsonSchema->name) || !isset($field))
+ {
+ $this->_setAttributesWithPhrases($jsonSchema);
+
+ $this->_setValidationAttributes($jsonSchema);
+
+ $this->_render($jsonSchema);
+
+ //
+ if (isset($field) && $field == $jsonSchema->name)
{
- show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table));
+ $found = true;
+ break;
}
}
}
- if (!$found)
+ //
+ if (isset($field) && !$found)
{
show_error(sprintf('%s.%s: No schema present for field: %s', $schema, $table, $field));
}
@@ -82,7 +94,33 @@ class UDFWidget extends UDFWidgetTpl
/**
*
*/
- private function _loadUDF($schema, $table, $field)
+ private function _sortJsonSchemas(&$jsonSchemasArray)
+ {
+ //
+ usort($jsonSchemasArray, function ($a, $b) {
+ //
+ if (!isset($a->sort))
+ {
+ $a->sort = 9999;
+ }
+ if (!isset($b->sort))
+ {
+ $b->sort = 9999;
+ }
+
+ if ($a->sort == $b->sort)
+ {
+ return 0;
+ }
+
+ return ($a->sort < $b->sort) ? -1 : 1;
+ });
+ }
+
+ /**
+ *
+ */
+ private function _loadUDF($schema, $table)
{
// Loads UDF model
$this->_ci->load->model('system/UDF_model', 'UDFModel');
@@ -154,6 +192,13 @@ class UDFWidget extends UDFWidgetTpl
*/
private function _renderDropdown($jsonSchema, $multiple = false)
{
+
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
+ {
+ $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
+ }
+
$dropdownWidgetUDF = new DropdownWidgetUDF($this->_name, $this->_args);
$parameters = array();
@@ -186,8 +231,15 @@ class UDFWidget extends UDFWidgetTpl
private function _renderTextarea($jsonSchema)
{
$textareaUDF = new TextareaWidgetUDF($this->_name, $this->_args);
-
- $textareaUDF->render(null);
+ $text = null;
+
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
+ {
+ $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
+ }
+
+ $textareaUDF->render($text);
}
/**
@@ -196,8 +248,15 @@ class UDFWidget extends UDFWidgetTpl
private function _renderTextfield($jsonSchema)
{
$textareaUDF = new TextfieldWidgetUDF($this->_name, $this->_args);
-
- $textareaUDF->render(null);
+ $text = null;
+
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
+ {
+ $text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
+ }
+
+ $textareaUDF->render($text);
}
/**
@@ -205,6 +264,12 @@ class UDFWidget extends UDFWidgetTpl
*/
private function _renderCheckbox($jsonSchema)
{
+ if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
+ && isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
+ {
+ $this->_args[CheckboxWidget::CHECKED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
+ }
+
//
if (!isset($this->_args[CheckboxWidget::CHECKED_ELEMENT]))
{