mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 16:32:20 +00:00
3rd release
This commit is contained in:
@@ -20,7 +20,8 @@ class TestUDF extends VileSci_Controller
|
||||
$data = array (
|
||||
'schema' => 'public',
|
||||
'table' => 'tbl_person',
|
||||
'field' => 'schuhgroesse'
|
||||
'field' => 'schuhgroesse',
|
||||
'selected' => array(1, 2)
|
||||
);
|
||||
|
||||
$this->load->view('system/testudf', $data);
|
||||
|
||||
@@ -218,29 +218,29 @@ class WidgetLib
|
||||
*/
|
||||
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]))
|
||||
if (!empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME])
|
||||
&& !empty($args[UDFWidgetTpl::TABLE_ARG_NAME])
|
||||
&& !empty($args[UDFWidgetTpl::FIELD_ARG_NAME]))
|
||||
{
|
||||
return $this->widget(
|
||||
UDF_widget_tpl::WIDGET_NAME,
|
||||
UDFWidgetTpl::WIDGET_NAME,
|
||||
$args,
|
||||
$htmlArgs
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (empty($args[UDF_widget_tpl::SCHEMA_ARG_NAME]))
|
||||
if (empty($args[UDFWidgetTpl::SCHEMA_ARG_NAME]))
|
||||
{
|
||||
show_error(UDF_widget_tpl::SCHEMA_ARG_NAME.' parameter is missing!');
|
||||
show_error(UDFWidgetTpl::SCHEMA_ARG_NAME.' parameter is missing!');
|
||||
}
|
||||
if (empty($args[UDF_widget_tpl::TABLE_ARG_NAME]))
|
||||
if (empty($args[UDFWidgetTpl::TABLE_ARG_NAME]))
|
||||
{
|
||||
show_error(UDF_widget_tpl::TABLE_ARG_NAME.' parameter is missing!');
|
||||
show_error(UDFWidgetTpl::TABLE_ARG_NAME.' parameter is missing!');
|
||||
}
|
||||
if (empty($args[UDF_widget_tpl::FIELD_ARG_NAME]))
|
||||
if (empty($args[UDFWidgetTpl::FIELD_ARG_NAME]))
|
||||
{
|
||||
show_error(UDF_widget_tpl::FIELD_ARG_NAME.' parameter is missing!');
|
||||
show_error(UDFWidgetTpl::FIELD_ARG_NAME.' parameter is missing!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -692,38 +692,64 @@ class Widget extends Partial
|
||||
*/
|
||||
private function _setHtmlProperties($htmlArgs)
|
||||
{
|
||||
if (isset($htmlArgs) && is_array($htmlArgs))
|
||||
// If $htmlArgs wasn't already stored in $this->_args
|
||||
if (!isset($this->_args[Widget::HTML_ARG_NAME]))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME] = array();
|
||||
|
||||
// Avoids that the elements of a same HTML page have the same name or id
|
||||
// Avoids that elements in a HTML page have the same name or id
|
||||
$randomIdentifier = uniqid(rand(0, 1000));
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
|
||||
|
||||
if (isset($htmlArgs[Widget::HTML_ID]) && trim($htmlArgs[Widget::HTML_ID]) != '')
|
||||
foreach($htmlArgs as $argName => $argValue)
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $htmlArgs[Widget::HTML_ID];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $randomIdentifier;
|
||||
}
|
||||
|
||||
if (isset($htmlArgs[Widget::HTML_NAME]) && trim($htmlArgs[Widget::HTML_NAME]) != '')
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $htmlArgs[Widget::HTML_NAME];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $randomIdentifier;
|
||||
$this->_args[Widget::HTML_ARG_NAME][$argName] = $argValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true)
|
||||
{
|
||||
if ($attribute != null)
|
||||
{
|
||||
if (isset($htmlArgs[$attribute]))
|
||||
{
|
||||
if ($isValuePresent === true)
|
||||
{
|
||||
$value = $htmlArgs[$attribute];
|
||||
|
||||
if (is_bool($value))
|
||||
{
|
||||
$value = $value ? 'true' : 'false';
|
||||
}
|
||||
|
||||
echo sprintf('%s="%s"', $attribute, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $attribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract class WidgetTpl extends Widget
|
||||
{
|
||||
abstract public function render($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* It exends the Widget class to represent an HTML dropdown
|
||||
*/
|
||||
class DropdownWidget extends Widget
|
||||
class DropdownWidget extends WidgetTpl
|
||||
{
|
||||
// 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
|
||||
@@ -731,59 +757,58 @@ class DropdownWidget extends Widget
|
||||
// Name of the property that will be used to store the value attribute of the option tag
|
||||
const ID_FIELD = 'id';
|
||||
// Name of the property that will be used to store the value between the option tags
|
||||
const DESCRIPTION_FIELD = 'description'; //
|
||||
const DESCRIPTION_FIELD = 'description';
|
||||
// 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 SELECTED_ELEMENT = 'selectedElement'; //
|
||||
const SELECTED_ELEMENT = 'selectedElement';
|
||||
|
||||
private $elementsArray; // Array of elements to be place inside the dropdown
|
||||
const SIZE = 'size'; //
|
||||
const MULTIPLE = 'multiple'; //
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function displayElements($elements, $widgetData)
|
||||
public function __construct($name, $args, $htmlArgs = array())
|
||||
{
|
||||
$this->setElementsArray(success($this->convert($elements)), true);
|
||||
$this->loadDropDownView($widgetData);
|
||||
parent::__construct($name, $args, $htmlArgs);
|
||||
|
||||
echo $this->content();
|
||||
}
|
||||
|
||||
/**
|
||||
//
|
||||
if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT]))
|
||||
{
|
||||
$this->_args[DropdownWidget::SELECTED_ELEMENT] = Widget::HTML_DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static function convert($elements)
|
||||
public function render($parameters)
|
||||
{
|
||||
$returnArray = array();
|
||||
$tmpElements = array();
|
||||
|
||||
foreach($elements as $key => $val)
|
||||
//
|
||||
foreach($parameters['elements'] as $key => $val)
|
||||
{
|
||||
$element = new stdClass();
|
||||
$element->id = $key;
|
||||
$element->description = $val;
|
||||
|
||||
array_push($returnArray, $element);
|
||||
array_push($tmpElements, $element);
|
||||
}
|
||||
|
||||
return $returnArray;
|
||||
$this->setElementsArray(
|
||||
success($tmpElements),
|
||||
true,
|
||||
'Select a value...',
|
||||
'No data found for this UDF'
|
||||
);
|
||||
|
||||
$this->loadDropDownView();
|
||||
|
||||
echo $this->content();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the dropdown view with all the elements to be displayed
|
||||
*/
|
||||
protected function loadDropDownView($widgetData)
|
||||
{
|
||||
$widgetData[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $this->elementsArray->retval;
|
||||
|
||||
if (!isset($widgetData[DropdownWidget::SELECTED_ELEMENT]))
|
||||
{
|
||||
$widgetData[DropdownWidget::SELECTED_ELEMENT] = Widget::HTML_DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
$this->view('widgets/dropdown', $widgetData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Add the correct select to the model used to load a list of elemets for this dropdown
|
||||
* @param model $model the model used to load elements
|
||||
* @param string $idName the name of the field that will used to be the value of the option tag
|
||||
@@ -801,7 +826,7 @@ class DropdownWidget extends Widget
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the array used to populate the dropdown
|
||||
* @param array $elements list used to populate this dropdown
|
||||
@@ -811,9 +836,11 @@ class DropdownWidget extends Widget
|
||||
* @param string $id value of the attribute value of the empty element
|
||||
*/
|
||||
protected function setElementsArray(
|
||||
$elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = '' , $id = Widget::HTML_DEFAULT_VALUE
|
||||
$elements, $emptyElement = false, $stdDescription = '' , $noDataDescription = 'No data found' , $id = Widget::HTML_DEFAULT_VALUE
|
||||
)
|
||||
{
|
||||
$tmpElements = array();
|
||||
|
||||
if (isError($elements))
|
||||
{
|
||||
if (is_object($elements) && isset($elements->retval))
|
||||
@@ -831,40 +858,85 @@ class DropdownWidget extends Widget
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->elementsArray = $elements;
|
||||
|
||||
if ($emptyElement === true)
|
||||
{
|
||||
$this->addElementAtBeginning($stdDescription, $noDataDescription, $id);
|
||||
$tmpElements = $this->addElementAtBeginning(
|
||||
$elements,
|
||||
$stdDescription,
|
||||
$noDataDescription,
|
||||
$id
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tmpElements = $elements->retval;
|
||||
}
|
||||
|
||||
$this->_args[DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME] = $tmpElements;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an element to the beginning of the array
|
||||
*/
|
||||
protected function addElementAtBeginning($stdDescription, $noDataDescription, $id)
|
||||
protected function addElementAtBeginning($elements, $stdDescription, $noDataDescription, $id)
|
||||
{
|
||||
$element = new stdClass();
|
||||
$element->id = $id;
|
||||
$element->description = $stdDescription;
|
||||
|
||||
if (!hasData($this->elementsArray))
|
||||
if (!hasData($elements))
|
||||
{
|
||||
$element->description = $noDataDescription;
|
||||
}
|
||||
|
||||
array_unshift($this->elementsArray->retval, $element);
|
||||
array_unshift($elements->retval, $element);
|
||||
|
||||
return $elements->retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the dropdown view with all the elements to be displayed
|
||||
*/
|
||||
protected function loadDropDownView()
|
||||
{
|
||||
$this->view('widgets/dropdown', $this->_args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract class UDF_widget_tpl extends Widget
|
||||
class MultipleDropdownWidget extends DropdownWidget
|
||||
{
|
||||
const WIDGET_NAME = 'UDF_widget';
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct($name, $args, $htmlArgs = array())
|
||||
{
|
||||
parent::__construct($name, $args, $htmlArgs);
|
||||
|
||||
//
|
||||
$this->_args[Widget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = 'multiple';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
abstract class UDFWidgetTpl extends Widget
|
||||
{
|
||||
const WIDGET_NAME = 'UDFWidget';
|
||||
const SCHEMA_ARG_NAME = 'schema';
|
||||
const TABLE_ARG_NAME = 'table';
|
||||
const FIELD_ARG_NAME = 'field';
|
||||
|
||||
const TITLE = 'title';
|
||||
const DESCRIPTION = 'description';
|
||||
const PLACEHOLDER = 'placeholder';
|
||||
const DEFAULT_VALUE = 'defaultValue';
|
||||
const REGEX = 'regex';
|
||||
const REQUIRED = 'required';
|
||||
const MAX_VALUE = 'max_value';
|
||||
const MIN_VALUE = 'min_value';
|
||||
}
|
||||
@@ -10,11 +10,12 @@
|
||||
<?php
|
||||
echo $this->widgetlib->UDFWidget(
|
||||
array(
|
||||
UDF_widget_tpl::SCHEMA_ARG_NAME => $schema,
|
||||
UDF_widget_tpl::TABLE_ARG_NAME => $table,
|
||||
UDF_widget_tpl::FIELD_ARG_NAME => $field
|
||||
UDFWidgetTpl::SCHEMA_ARG_NAME => $schema,
|
||||
UDFWidgetTpl::TABLE_ARG_NAME => $table,
|
||||
UDFWidgetTpl::FIELD_ARG_NAME => $field,
|
||||
DropdownWidget::SELECTED_ELEMENT => $selected
|
||||
),
|
||||
array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName')
|
||||
array('id' => 'schuhgroesseID', 'name' => 'schuhgroesseName', 'size' => '6')
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
|
||||
@@ -1,14 +1,54 @@
|
||||
<select id="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_ID]; ?>" name="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_NAME]; ?>">
|
||||
<?php foreach(${DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME} as $element): ?>
|
||||
<?php
|
||||
<?php
|
||||
if (isset(${Widget::HTML_ARG_NAME}[UDFWidgetTpl::DESCRIPTION]))
|
||||
{
|
||||
?>
|
||||
<label for="<?php echo ${Widget::HTML_ARG_NAME}[Widget::HTML_ID]; ?>">
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::DESCRIPTION); ?>
|
||||
</label>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<select
|
||||
<?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}, DropdownWidget::SIZE); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, DropdownWidget::MULTIPLE, false); ?>
|
||||
<?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::REGEX); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
|
||||
>
|
||||
<?php
|
||||
$elements = ${DropdownWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME};
|
||||
$selectedElements = ${DropdownWidget::SELECTED_ELEMENT};
|
||||
|
||||
foreach($elements as $element)
|
||||
{
|
||||
$selected = '';
|
||||
if ($element->{DropdownWidget::ID_FIELD} === ${DropdownWidget::SELECTED_ELEMENT})
|
||||
|
||||
if (is_array($selectedElements))
|
||||
{
|
||||
$selected = 'selected';
|
||||
foreach($selectedElements as $selectedElement)
|
||||
{
|
||||
if ($element->{DropdownWidget::ID_FIELD} === $selectedElement)
|
||||
{
|
||||
$selected = 'selected';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
else
|
||||
{
|
||||
if ($element->{DropdownWidget::ID_FIELD} === $selectedElements)
|
||||
{
|
||||
$selected = 'selected';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<option value="<?php echo $element->{DropdownWidget::ID_FIELD}; ?>" <?php echo $selected; ?>>
|
||||
<?php echo $element->{DropdownWidget::DESCRIPTION_FIELD}; ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
@@ -17,6 +17,6 @@ class Studiengang_widget extends DropdownWidget
|
||||
'No studiengaenge found'
|
||||
);
|
||||
|
||||
$this->loadDropDownView($widgetData);
|
||||
$this->loadDropDownView();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class UDFWidget extends UDFWidgetTpl
|
||||
{
|
||||
public function display($widgetData)
|
||||
{
|
||||
$schema = $widgetData[UDFWidgetTpl::SCHEMA_ARG_NAME];
|
||||
$table = $widgetData[UDFWidgetTpl::TABLE_ARG_NAME];
|
||||
$field = $widgetData[UDFWidgetTpl::FIELD_ARG_NAME];
|
||||
|
||||
// Loads UDF model
|
||||
$this->_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('UDFWidget: 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))
|
||||
{
|
||||
$this->_render($jsonSchema);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _render($jsonSchema)
|
||||
{
|
||||
// var_dump($jsonSchema);
|
||||
|
||||
// Description, title and placeholder
|
||||
if (isset($jsonSchema->title) || isset($jsonSchema->description) || isset($jsonSchema->placeholder))
|
||||
{
|
||||
$this->_ci->load->library('PhrasesLib');
|
||||
|
||||
if (isset($jsonSchema->title))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::TITLE] = $this->_ci->phraseslib->getPhrases('core', 'German', $jsonSchema->title);
|
||||
}
|
||||
|
||||
if (isset($jsonSchema->description))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::DESCRIPTION] = $this->_ci->phraseslib->getPhrases('core', 'German', $jsonSchema->description);
|
||||
}
|
||||
|
||||
if (isset($jsonSchema->placeholder))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::PLACEHOLDER] = $this->_ci->phraseslib->getPhrases('core', 'German', $jsonSchema->placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
// Validation
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = null;
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REQUIRED] = null;
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = null;
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = null;
|
||||
|
||||
if (isset($jsonSchema->validation))
|
||||
{
|
||||
if (isset($jsonSchema->validation->regex) && is_array($jsonSchema->validation->regex))
|
||||
{
|
||||
foreach($jsonSchema->validation->regex as $regex)
|
||||
{
|
||||
if ($regex->language === 'js')
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REGEX] = $regex->expression;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($jsonSchema->validation->required))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::REQUIRED] = $jsonSchema->validation->required;
|
||||
}
|
||||
|
||||
if (isset($jsonSchema->validation->{'max-value'}))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MAX_VALUE] = $jsonSchema->validation->{'max-value'};
|
||||
}
|
||||
|
||||
if (isset($jsonSchema->validation->{'min-value'}))
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][UDFWidgetTpl::MIN_VALUE] = $jsonSchema->validation->{'min-value'};
|
||||
}
|
||||
}
|
||||
|
||||
// var_dump($this->_args);
|
||||
|
||||
// Type
|
||||
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($this->_name, $this->_args);
|
||||
$dropdownWidget->render(array('elements' => $jsonSchema->listValues->enum));
|
||||
}
|
||||
else if ($jsonSchema->type == 'multipledropdown')
|
||||
{
|
||||
$multipleDropdownWidget = new MultipleDropdownWidget($this->_name, $this->_args);
|
||||
$multipleDropdownWidget->render(array('elements' => $jsonSchema->listValues->enum));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class UDF_widget extends UDF_widget_tpl
|
||||
{
|
||||
public function display($widgetData)
|
||||
{
|
||||
$schema = $widgetData[UDF_widget_tpl::SCHEMA_ARG_NAME];
|
||||
$table = $widgetData[UDF_widget_tpl::TABLE_ARG_NAME];
|
||||
$field = $widgetData[UDF_widget_tpl::FIELD_ARG_NAME];
|
||||
|
||||
// Loads UDF model
|
||||
$this->_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($this->_name, $this->_args);
|
||||
$dropdownWidget->displayElements($jsonSchema->listValues->enum, $this->_args);
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user