mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-19 16:02:15 +00:00
7th release
This commit is contained in:
@@ -17,12 +17,7 @@ class TestUDF extends VileSci_Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = array (
|
||||
'schema' => 'public',
|
||||
'table' => 'tbl_person',
|
||||
'field' => 'schuhgroesse',
|
||||
'selected' => array(1, 2)
|
||||
);
|
||||
$data = array();
|
||||
|
||||
$this->load->view('system/testudf', $data);
|
||||
}
|
||||
|
||||
@@ -853,12 +853,12 @@ class DropdownWidget extends Widget
|
||||
protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
|
||||
{
|
||||
$element = new stdClass();
|
||||
$element->id = $id;
|
||||
$element->description = $stdDescription;
|
||||
$element->{DropdownWidget::ID_FIELD} = $id;
|
||||
$element->{DropdownWidget::DESCRIPTION_FIELD} = $stdDescription;
|
||||
|
||||
if (!hasData($elements))
|
||||
{
|
||||
$element->description = $noDataDescription;
|
||||
$element->{DropdownWidget::DESCRIPTION_FIELD} = $noDataDescription;
|
||||
}
|
||||
|
||||
array_unshift($elements->retval, $element);
|
||||
@@ -888,13 +888,35 @@ class DropdownWidgetUDF extends DropdownWidget
|
||||
$tmpElements = array();
|
||||
|
||||
//
|
||||
foreach($parameters as $key => $val)
|
||||
foreach($parameters as $parameter)
|
||||
{
|
||||
$element = new stdClass();
|
||||
$element->id = $key;
|
||||
$element->description = $val;
|
||||
|
||||
array_push($tmpElements, $element);
|
||||
//
|
||||
if ((is_array($parameter) && count($parameter) == 2)
|
||||
|| (is_string($parameter) || is_numeric($parameter))
|
||||
|| (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
|
||||
{
|
||||
$element = new stdClass(); //
|
||||
//
|
||||
if (is_array($parameter) && count($parameter) == 2)
|
||||
{
|
||||
$element->{PARENT::ID_FIELD} = $parameter[0]; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
|
||||
}
|
||||
//
|
||||
else if (is_string($parameter) || is_numeric($parameter))
|
||||
{
|
||||
$element->{PARENT::ID_FIELD} = $parameter; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
|
||||
}
|
||||
//
|
||||
else if (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
|
||||
{
|
||||
$element->{PARENT::ID_FIELD} = $parameter->{PARENT::ID_FIELD}; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
|
||||
}
|
||||
|
||||
array_push($tmpElements, $element); //
|
||||
}
|
||||
}
|
||||
|
||||
$this->setElementsArray(
|
||||
@@ -924,7 +946,7 @@ class TextareaWidget extends Widget
|
||||
*/
|
||||
protected function setText($text)
|
||||
{
|
||||
$this->_args[DropdownWidget::TEXT] = $text;
|
||||
$this->_args[TextareaWidget::TEXT] = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -946,7 +968,14 @@ class TextareaWidgetUDF extends TextareaWidget
|
||||
*/
|
||||
public function render($parameters)
|
||||
{
|
||||
$this->setText($parameters);
|
||||
if ($parameters != null)
|
||||
{
|
||||
$this->setText($parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setText('');
|
||||
}
|
||||
|
||||
$this->loadTextareaView();
|
||||
|
||||
@@ -954,6 +983,147 @@ class TextareaWidgetUDF extends TextareaWidget
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It exends the Widget class to represent an HTML textarea
|
||||
*/
|
||||
class TextfieldWidget extends Widget
|
||||
{
|
||||
const VALUE = 'text'; //
|
||||
const SIZE = 'size'; //
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function setValue($value)
|
||||
{
|
||||
$this->_args[TextfieldWidget::VALUE] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function loadTextfieldView()
|
||||
{
|
||||
$this->view('widgets/textfield', $this->_args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class TextfieldWidgetUDF extends TextfieldWidget
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render($parameters)
|
||||
{
|
||||
if ($parameters != null)
|
||||
{
|
||||
$this->setValue($parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setValue('');
|
||||
}
|
||||
|
||||
$this->loadTextfieldView();
|
||||
|
||||
echo $this->content();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* It exends the Widget class to represent an HTML dropdown
|
||||
*/
|
||||
class CheckboxWidget extends Widget
|
||||
{
|
||||
// The name of the element of the data array given to the view
|
||||
// this element is an array of elements to be place inside the dropdown
|
||||
const WIDGET_DATA_VALUES_ARRAY_NAME = 'VALUES_ARRAY';
|
||||
// The name of the element of the data array given to the view
|
||||
// this element is used to tell what element of the dropdown is selected
|
||||
const CHECKED_VALUE = 'checkedValue';
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($name, $args, $htmlArgs = array())
|
||||
{
|
||||
parent::__construct($name, $args, $htmlArgs);
|
||||
|
||||
//
|
||||
if (!isset($this->_args[CheckboxWidget::CHECKED_VALUE]))
|
||||
{
|
||||
$this->_args[CheckboxWidget::CHECKED_VALUE] = Widget::HTML_DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function setValuesArray($values)
|
||||
{
|
||||
if (isError($values))
|
||||
{
|
||||
if (is_object($values) && isset($values->retval))
|
||||
{
|
||||
show_error($values->retval);
|
||||
}
|
||||
else if (is_string($values))
|
||||
{
|
||||
show_error($values);
|
||||
}
|
||||
else
|
||||
{
|
||||
show_error('Generic error occurred');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_args[CheckboxWidget::WIDGET_DATA_VALUES_ARRAY_NAME] = $values->retval;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function loadCheckboxView()
|
||||
{
|
||||
$this->view('widgets/checkbox', $this->_args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class CheckboxWidgetUDF extends CheckboxWidget
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function render($parameters)
|
||||
{
|
||||
$tmpValues = array();
|
||||
|
||||
//
|
||||
foreach($parameters as $parameter)
|
||||
{
|
||||
//
|
||||
if (is_string($parameter) || is_numeric($parameter))
|
||||
{
|
||||
array_push($tmpValues, $parameter); //
|
||||
}
|
||||
}
|
||||
|
||||
$this->setValuesArray(success($tmpValues));
|
||||
|
||||
$this->loadCheckboxView();
|
||||
|
||||
echo $this->content();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -12,4 +12,31 @@ class UDF_model extends DB_Model
|
||||
$this->pk = array('schema', 'table');
|
||||
$this->hasSequence = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function execQuery($query, $parametersArray = null)
|
||||
{
|
||||
//
|
||||
if (
|
||||
(
|
||||
substr($query, 0, 6) == 'SELECT'
|
||||
|| substr($query, 0, 4) == 'WITH'
|
||||
)
|
||||
&&
|
||||
(
|
||||
!stripos($query, 'INSERT')
|
||||
&& !stripos($query, 'UPDATE')
|
||||
&& !stripos($query, 'DELETE')
|
||||
)
|
||||
)
|
||||
{
|
||||
return parent::execQuery($query, $parametersArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error('You are allowed to run only query for reading data');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,87 @@
|
||||
<?php
|
||||
echo $this->widgetlib->UDFWidget(
|
||||
array(
|
||||
UDFWidgetTpl::SCHEMA_ARG_NAME => $schema,
|
||||
UDFWidgetTpl::TABLE_ARG_NAME => $table,
|
||||
UDFWidgetTpl::FIELD_ARG_NAME => $field,
|
||||
DropdownWidget::SELECTED_ELEMENT => $selected
|
||||
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' => '6')
|
||||
array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName', 'size' => '9')
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
|
||||
<div>
|
||||
<?php
|
||||
echo $this->widgetlib->UDFWidget(
|
||||
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>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
|
||||
{
|
||||
?>
|
||||
<label for="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_ID]; ?>">
|
||||
<?php echo ${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]; ?>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<fieldset
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_ID); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REQUIRED); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REGEX); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
|
||||
>
|
||||
<?php
|
||||
$values = ${CheckboxWidget::WIDGET_DATA_VALUES_ARRAY_NAME};
|
||||
$checkedValue = ${CheckboxWidget::CHECKED_VALUE};
|
||||
|
||||
foreach($values as $value)
|
||||
{
|
||||
$checked = '';
|
||||
|
||||
if ($value == $checkedValue)
|
||||
{
|
||||
$checked = 'checked';
|
||||
}
|
||||
?>
|
||||
<input
|
||||
type="checkbox"
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_NAME); ?>
|
||||
value="<?php echo $value; ?>"
|
||||
<?php echo $checked; ?>
|
||||
>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
@@ -8,17 +8,15 @@
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
<textarea
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_ID); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_NAME); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, TextareaWidget::ROWS); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, TextareaWidget::COLS); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REQUIRED); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::MAX_VALUE); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::MIN_VALUE); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::PLACEHOLDER); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REGEX); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
|
||||
>
|
||||
<?php echo ${TextareaWidget::TEXT}; ?>
|
||||
<?php echo ${TextareaWidget::TEXT}; ?>
|
||||
</textarea>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]))
|
||||
{
|
||||
?>
|
||||
<label for="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_ID]; ?>">
|
||||
<?php echo ${Widget::HTML_ARG_NAME}[UDFWidgetTpl::LABEL]; ?>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<input
|
||||
type="text"
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_ID); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_NAME); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, TextfieldWidget::SIZE); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REQUIRED); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::PLACEHOLDER); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REGEX); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
|
||||
value="<?php echo ${TextfieldWidget::VALUE}; ?>"
|
||||
>
|
||||
@@ -125,11 +125,11 @@ class UDFWidget extends UDFWidgetTpl
|
||||
// Type
|
||||
if ($jsonSchema->type == 'checkbox')
|
||||
{
|
||||
|
||||
$this->_renderCheckbox($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'textfield')
|
||||
{
|
||||
|
||||
$this->_renderTextfield($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'textarea')
|
||||
{
|
||||
@@ -155,16 +155,21 @@ class UDFWidget extends UDFWidgetTpl
|
||||
private function _renderDropdown($jsonSchema, $multiple = false)
|
||||
{
|
||||
$dropdownWidgetUDF = new DropdownWidgetUDF($this->_name, $this->_args);
|
||||
|
||||
$parameters = array();
|
||||
|
||||
//
|
||||
if (isset($jsonSchema->listValues->enum))
|
||||
{
|
||||
$parameters = $jsonSchema->listValues->enum;
|
||||
}
|
||||
//
|
||||
else if (isset($jsonSchema->listValues->sql))
|
||||
{
|
||||
$parameters = $jsonSchema->listValues->sql;
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->listValues->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
}
|
||||
}
|
||||
|
||||
if ($multiple)
|
||||
@@ -180,15 +185,45 @@ class UDFWidget extends UDFWidgetTpl
|
||||
*/
|
||||
private function _renderTextarea($jsonSchema)
|
||||
{
|
||||
$textareaUDF = new TextareaUDF($this->_name, $this->_args);
|
||||
$textareaUDF = new TextareaWidgetUDF($this->_name, $this->_args);
|
||||
|
||||
$text = '';
|
||||
if (isset($jsonSchema->defaultValue))
|
||||
$textareaUDF->render(null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _renderTextfield($jsonSchema)
|
||||
{
|
||||
$textareaUDF = new TextfieldWidgetUDF($this->_name, $this->_args);
|
||||
|
||||
$textareaUDF->render(null);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _renderCheckbox($jsonSchema)
|
||||
{
|
||||
$checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args);
|
||||
$parameters = array();
|
||||
|
||||
//
|
||||
if (isset($jsonSchema->listValues->enum))
|
||||
{
|
||||
$text = $jsonSchema->defaultValue;
|
||||
$parameters = $jsonSchema->listValues->enum;
|
||||
}
|
||||
//
|
||||
else if (isset($jsonSchema->listValues->sql))
|
||||
{
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->listValues->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
}
|
||||
}
|
||||
|
||||
$textareaUDF->render($text);
|
||||
$checkboxWidgetUDF->render($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user