1st preview

This commit is contained in:
Paolo
2017-05-09 18:14:18 +02:00
parent a5aea17fa6
commit e143aa8815
9 changed files with 178 additions and 145 deletions
+8 -1
View File
@@ -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);
}
+25
View File
@@ -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});
+34 -7
View File
@@ -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 '<div>';
}
}
/**
*
*/
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 '</div>';
}
}
}
/**
@@ -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';
+7 -106
View File
@@ -2,20 +2,12 @@
<body>
<div>
<?php
echo $this->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')
);
?>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<div>
@@ -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')
);
?>
</div>
<br/>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::FIELD_ARG_NAME => 'bellySize'
),
array('id' => 'bellySizeID', 'name' => 'bellySizeName')
);
?>
</div>
<br/>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::FIELD_ARG_NAME => 'nickname'
),
array('id' => 'nicknameID', 'name' => 'nicknameName')
);
?>
</div>
<br/>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::FIELD_ARG_NAME => 'age'
),
array('id' => 'ageID', 'name' => 'ageName')
);
?>
</div>
<br/>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::FIELD_ARG_NAME => 'agree'
),
array('id' => 'agreeID', 'name' => 'agreeName')
);
?>
</div>
<br/>
<div>
<?php
echo $this->widgetlib->UDFWidget(
array(
UDFWidgetTpl::SCHEMA_ARG_NAME => 'public',
UDFWidgetTpl::TABLE_ARG_NAME => 'tbl_person',
UDFWidgetTpl::FIELD_ARG_NAME => 'disagree'
),
array('id' => 'disagreeID', 'name' => 'disagreeName')
);
?>
</div>
<br/>
<div>
<?php
echo $this->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
)
);
?>
</div>
+3 -1
View File
@@ -1,3 +1,4 @@
<?php Widget::printStartBlock(${Widget::HTML_ARG_NAME}); ?>
<?php
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
{
@@ -37,4 +38,5 @@
<?php
}
?>
</fieldset>
</fieldset>
<?php Widget::printEndBlock(${Widget::HTML_ARG_NAME}); ?>
+3 -1
View File
@@ -1,3 +1,4 @@
<?php Widget::printStartBlock(${Widget::HTML_ARG_NAME}); ?>
<?php
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
{
@@ -51,4 +52,5 @@
<?php
}
?>
</select>
</select>
<?php Widget::printEndBlock(${Widget::HTML_ARG_NAME}); ?>
+3 -1
View File
@@ -1,3 +1,4 @@
<?php Widget::printStartBlock(${Widget::HTML_ARG_NAME}); ?>
<?php
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
{
@@ -19,4 +20,5 @@
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
>
<?php echo ${TextareaWidget::TEXT}; ?>
</textarea>
</textarea>
<?php Widget::printEndBlock(${Widget::HTML_ARG_NAME}); ?>
+3 -1
View File
@@ -1,3 +1,4 @@
<?php Widget::printStartBlock(${Widget::HTML_ARG_NAME}); ?>
<?php
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
{
@@ -18,4 +19,5 @@
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REGEX); ?>
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
value="<?php echo ${TextfieldWidget::VALUE}; ?>"
>
>
<?php Widget::printEndBlock(${Widget::HTML_ARG_NAME}); ?>
+92 -27
View File
@@ -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]))
{