mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-22 01:12:17 +00:00
- Bugfix UDF dropdown, wrong check for selected value
- UDF checkbox now is only one value, no multiple checkbox anymore - Added method saveUDFs to model UDF_model - Added new constants to resolve json schema parameters
This commit is contained in:
@@ -60,6 +60,64 @@ class UDF extends APIv1_Controller
|
||||
$this->response($result, REST_Controller::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function postUDF()
|
||||
{
|
||||
$udfs = $this->post();
|
||||
$validation = $this->_validate($udfs);
|
||||
|
||||
var_dump($udfs);exit;
|
||||
|
||||
if (isSuccess($validation))
|
||||
{
|
||||
$caller = null;
|
||||
if (isset($udfs['caller']))
|
||||
{
|
||||
$caller = $udfs['caller'];
|
||||
unset($udfs['caller']);
|
||||
}
|
||||
|
||||
$result = $this->UDFModel->saveUDFs($udfs);
|
||||
|
||||
if ($caller != null)
|
||||
{
|
||||
$res = 'ERR';
|
||||
if (isSuccess($result))
|
||||
{
|
||||
$res = 'OK';
|
||||
}
|
||||
|
||||
redirect($caller.'&res='.$res);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response($result, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->response($validation, REST_Controller::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function _validate($udfs)
|
||||
{
|
||||
$validation = error('person_id or prestudent_id is missing');
|
||||
|
||||
if((isset($udfs['person_id']) && !(is_null($udfs['person_id'])) && ($udfs['person_id'] != ''))
|
||||
|| (isset($udfs['prestudent_id']) && !(is_null($udfs['prestudent_id'])) && ($udfs['prestudent_id'] != '')))
|
||||
{
|
||||
$validation = success(true);
|
||||
}
|
||||
|
||||
return $validation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode to json the column jsons for every result set
|
||||
*/
|
||||
|
||||
@@ -1066,9 +1066,6 @@ class TextfieldWidgetUDF extends TextfieldWidget
|
||||
*/
|
||||
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_ELEMENTS_ARRAY_NAME = 'ELEMENTS_ARRAY';
|
||||
// Name of the property that will be used to store the value attribute of the option tag
|
||||
const VALUE_FIELD = 'value';
|
||||
// Name of the property that will be used to store the value between the option tags
|
||||
@@ -1090,31 +1087,19 @@ class CheckboxWidget extends Widget
|
||||
$this->_args[CheckboxWidget::CHECKED_ELEMENT] = Widget::HTML_DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function setValuesArray($values)
|
||||
protected function setValue($value)
|
||||
{
|
||||
if (isError($values))
|
||||
$tmpValue = $value;
|
||||
if (is_array($value) && count($value) > 0)
|
||||
{
|
||||
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_ELEMENTS_ARRAY_NAME] = $values->retval;
|
||||
$tmpValue = array_values($value)[0];
|
||||
}
|
||||
|
||||
$this->_args[CheckboxWidget::VALUE_FIELD] = $tmpValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1136,45 +1121,60 @@ class CheckboxWidgetUDF extends CheckboxWidget
|
||||
*/
|
||||
public function render($parameters)
|
||||
{
|
||||
$tmpElements = array();
|
||||
|
||||
//
|
||||
foreach($parameters as $parameter)
|
||||
if ($parameters != null)
|
||||
{
|
||||
//
|
||||
if ((is_array($parameter) && count($parameter) == 2)
|
||||
|| (is_string($parameter) || is_numeric($parameter))
|
||||
|| (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
|
||||
{
|
||||
$element = new stdClass(); //
|
||||
//
|
||||
if (is_array($parameter) && count($parameter) == 2)
|
||||
{
|
||||
$element->{PARENT::VALUE_FIELD} = $parameter[0]; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
|
||||
}
|
||||
//
|
||||
else if (is_string($parameter) || is_numeric($parameter))
|
||||
{
|
||||
$element->{PARENT::VALUE_FIELD} = $parameter; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
|
||||
}
|
||||
//
|
||||
else if (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
|
||||
{
|
||||
$element->{PARENT::VALUE_FIELD} = $parameter->{PARENT::VALUE_FIELD}; //
|
||||
$element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
|
||||
}
|
||||
|
||||
array_push($tmpElements, $element); //
|
||||
}
|
||||
$this->setValue($parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setValue('');
|
||||
}
|
||||
|
||||
$this->setValuesArray(success($tmpElements));
|
||||
|
||||
$this->loadCheckboxView();
|
||||
|
||||
echo $this->content();
|
||||
|
||||
// $tmpElements = array();
|
||||
|
||||
//
|
||||
// foreach($parameters as $parameter)
|
||||
// {
|
||||
// //
|
||||
// if ((is_array($parameter) && count($parameter) == 2)
|
||||
// || (is_string($parameter) || is_numeric($parameter))
|
||||
// || (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD})
|
||||
// && isset($parameter->{PARENT::DESCRIPTION_FIELD})))
|
||||
// {
|
||||
// $element = new stdClass(); //
|
||||
// //
|
||||
// if (is_array($parameter) && count($parameter) == 2)
|
||||
// {
|
||||
// $element->{PARENT::VALUE_FIELD} = $parameter[0]; //
|
||||
// $element->{PARENT::DESCRIPTION_FIELD} = $parameter[1]; //
|
||||
// }
|
||||
// //
|
||||
// else if (is_string($parameter) || is_numeric($parameter))
|
||||
// {
|
||||
// $element->{PARENT::VALUE_FIELD} = $parameter; //
|
||||
// $element->{PARENT::DESCRIPTION_FIELD} = $parameter; //
|
||||
// }
|
||||
// //
|
||||
// else if (is_object($parameter) && isset($parameter->{PARENT::VALUE_FIELD})
|
||||
// && isset($parameter->{PARENT::DESCRIPTION_FIELD}))
|
||||
// {
|
||||
// $element->{PARENT::VALUE_FIELD} = $parameter->{PARENT::VALUE_FIELD}; //
|
||||
// $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; //
|
||||
// }
|
||||
//
|
||||
// array_push($tmpElements, $element); //
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $this->setValuesArray(success($tmpElements));
|
||||
//
|
||||
// $this->loadCheckboxView();
|
||||
//
|
||||
// echo $this->content();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,4 +39,53 @@ class UDF_model extends DB_Model
|
||||
return error('You are allowed to run only query for reading data');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function saveUDFs($udfs)
|
||||
{
|
||||
$result = error('No way man!');
|
||||
$resultPerson = success('person');
|
||||
$resultPrestudent = success('prestudent');
|
||||
|
||||
//
|
||||
if (isset($udfs['person_id']))
|
||||
{
|
||||
// Load model Person_model
|
||||
$this->load->model('person/Person_model', 'PersonModel');
|
||||
|
||||
$person_id = $udfs['person_id'];
|
||||
unset($udfs['person_id']);
|
||||
|
||||
$resultPerson = $this->PersonModel->update($person_id, $udfs);
|
||||
}
|
||||
|
||||
//
|
||||
if (isset($udfs['prestudent_id']))
|
||||
{
|
||||
// Load model Prestudent_model
|
||||
$this->load->model('crm/Prestudent_model', 'PrestudentModel');
|
||||
|
||||
$prestudent_id = $udfs['prestudent_id'];
|
||||
unset($udfs['prestudent_id']);
|
||||
|
||||
$resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs);
|
||||
}
|
||||
|
||||
if (isSuccess($resultPerson) && isSuccess($resultPrestudent))
|
||||
{
|
||||
$result = success(array($resultPerson->retval, $resultPrestudent->retval));
|
||||
}
|
||||
else if(isError($resultPerson))
|
||||
{
|
||||
$result = $resultPerson;
|
||||
}
|
||||
else if(isError($resultPrestudent))
|
||||
{
|
||||
$result = $resultPrestudent;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -9,34 +9,22 @@
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<fieldset
|
||||
<input
|
||||
type="checkbox"
|
||||
<?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}, UDFWidgetTpl::REQUIRED); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::REGEX); ?>
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, UDFWidgetTpl::TITLE); ?>
|
||||
>
|
||||
<?php
|
||||
$elements = ${CheckboxWidget::WIDGET_DATA_ELEMENTS_ARRAY_NAME};
|
||||
$checkedElement = ${CheckboxWidget::CHECKED_ELEMENT};
|
||||
|
||||
foreach($elements as $element)
|
||||
$checked = '';
|
||||
if (${CheckboxWidget::VALUE_FIELD} == ${CheckboxWidget::CHECKED_ELEMENT})
|
||||
{
|
||||
$checked = '';
|
||||
|
||||
if ($element->{CheckboxWidget::VALUE_FIELD} == $checkedElement)
|
||||
{
|
||||
$checked = 'checked';
|
||||
}
|
||||
?>
|
||||
<input
|
||||
type="checkbox"
|
||||
<?php Widget::printAttribute(${Widget::HTML_ARG_NAME}, Widget::HTML_NAME); ?>
|
||||
value="<?php echo $element->{CheckboxWidget::VALUE_FIELD}; ?>"
|
||||
<?php echo $checked; ?>
|
||||
>
|
||||
<?php echo $element->{CheckboxWidget::DESCRIPTION_FIELD}; ?>
|
||||
<?php
|
||||
$checked = 'checked';
|
||||
}
|
||||
?>
|
||||
</fieldset>
|
||||
<?php echo $checked; ?>
|
||||
value="<?php echo ${CheckboxWidget::VALUE_FIELD}; ?>"
|
||||
>
|
||||
<?php echo ${CheckboxWidget::VALUE_FIELD}; ?>
|
||||
<?php Widget::printEndBlock(${Widget::HTML_ARG_NAME}); ?>
|
||||
@@ -32,7 +32,7 @@
|
||||
{
|
||||
foreach($selectedElements as $selectedElement)
|
||||
{
|
||||
if ($element->{DropdownWidget::ID_FIELD} === $selectedElement)
|
||||
if ($element->{DropdownWidget::ID_FIELD} == $selectedElement)
|
||||
{
|
||||
$selected = 'selected';
|
||||
}
|
||||
@@ -40,7 +40,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($element->{DropdownWidget::ID_FIELD} === $selectedElements)
|
||||
if ($element->{DropdownWidget::ID_FIELD} == $selectedElements)
|
||||
{
|
||||
$selected = 'selected';
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
*/
|
||||
class UDFWidget extends UDFWidgetTpl
|
||||
{
|
||||
const NAME = 'name';
|
||||
const TYPE = 'type';
|
||||
const LIST_VALUES = 'listValues';
|
||||
const REGEX_LANGUAGE = 'js';
|
||||
|
||||
public function display($widgetData)
|
||||
@@ -44,19 +47,19 @@ class UDFWidget extends UDFWidgetTpl
|
||||
foreach($jsonSchemasArray as $jsonSchema)
|
||||
{
|
||||
//
|
||||
if (!isset($jsonSchema->type))
|
||||
if (!isset($jsonSchema->{UDFWidget::TYPE}))
|
||||
{
|
||||
show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
|
||||
break;
|
||||
}
|
||||
if (!isset($jsonSchema->name))
|
||||
if (!isset($jsonSchema->{UDFWidget::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))
|
||||
if ((isset($field) && $field == $jsonSchema->{UDFWidget::NAME}) || !isset($field))
|
||||
{
|
||||
$this->_setAttributesWithPhrases($jsonSchema);
|
||||
|
||||
@@ -67,7 +70,7 @@ class UDFWidget extends UDFWidgetTpl
|
||||
$this->_render($jsonSchema);
|
||||
|
||||
//
|
||||
if (isset($field) && $field == $jsonSchema->name)
|
||||
if (isset($field) && $field == $jsonSchema->{UDFWidget::NAME})
|
||||
{
|
||||
$found = true;
|
||||
break;
|
||||
@@ -98,8 +101,8 @@ class UDFWidget extends UDFWidgetTpl
|
||||
*/
|
||||
private function _setNameAndId($jsonSchema)
|
||||
{
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $jsonSchema->name;
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $jsonSchema->name;
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_ID] = $jsonSchema->{UDFWidget::NAME};
|
||||
$this->_args[Widget::HTML_ARG_NAME][Widget::HTML_NAME] = $jsonSchema->{UDFWidget::NAME};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,27 +175,27 @@ class UDFWidget extends UDFWidgetTpl
|
||||
private function _render($jsonSchema)
|
||||
{
|
||||
// Type
|
||||
if ($jsonSchema->type == 'checkbox')
|
||||
if ($jsonSchema->{UDFWidget::TYPE} == 'checkbox')
|
||||
{
|
||||
$this->_renderCheckbox($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'textfield')
|
||||
else if ($jsonSchema->{UDFWidget::TYPE} == 'textfield')
|
||||
{
|
||||
$this->_renderTextfield($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'textarea')
|
||||
else if ($jsonSchema->{UDFWidget::TYPE} == 'textarea')
|
||||
{
|
||||
$this->_renderTextarea($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'date')
|
||||
else if ($jsonSchema->{UDFWidget::TYPE} == 'date')
|
||||
{
|
||||
|
||||
}
|
||||
else if ($jsonSchema->type == 'dropdown')
|
||||
else if ($jsonSchema->{UDFWidget::TYPE} == 'dropdown')
|
||||
{
|
||||
$this->_renderDropdown($jsonSchema);
|
||||
}
|
||||
else if ($jsonSchema->type == 'multipledropdown')
|
||||
else if ($jsonSchema->{UDFWidget::TYPE} == 'multipledropdown')
|
||||
{
|
||||
$this->_renderDropdown($jsonSchema, true);
|
||||
}
|
||||
@@ -205,23 +208,23 @@ class UDFWidget extends UDFWidgetTpl
|
||||
{
|
||||
|
||||
if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
|
||||
{
|
||||
$this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
|
||||
$this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
|
||||
}
|
||||
|
||||
$dropdownWidgetUDF = new DropdownWidgetUDF($this->_name, $this->_args);
|
||||
$parameters = array();
|
||||
|
||||
//
|
||||
if (isset($jsonSchema->listValues->enum))
|
||||
if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->enum))
|
||||
{
|
||||
$parameters = $jsonSchema->listValues->enum;
|
||||
$parameters = $jsonSchema->{UDFWidget::LIST_VALUES}->enum;
|
||||
}
|
||||
//
|
||||
else if (isset($jsonSchema->listValues->sql))
|
||||
else if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->sql))
|
||||
{
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->listValues->sql);
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->{UDFWidget::LIST_VALUES}->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
@@ -245,9 +248,9 @@ class UDFWidget extends UDFWidgetTpl
|
||||
$text = null;
|
||||
|
||||
if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
|
||||
{
|
||||
$text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
|
||||
$text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
|
||||
}
|
||||
|
||||
$textareaUDF->render($text);
|
||||
@@ -262,9 +265,9 @@ class UDFWidget extends UDFWidgetTpl
|
||||
$text = null;
|
||||
|
||||
if (isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME])
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name]))
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
|
||||
{
|
||||
$text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
|
||||
$text = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
|
||||
}
|
||||
|
||||
$textareaUDF->render($text);
|
||||
@@ -276,32 +279,33 @@ 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]))
|
||||
&& isset($this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]))
|
||||
{
|
||||
$this->_args[CheckboxWidget::CHECKED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->name];
|
||||
$this->_args[CheckboxWidget::CHECKED_ELEMENT] = $this->_args[UDFWidgetTpl::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}];
|
||||
}
|
||||
|
||||
//
|
||||
if (!isset($this->_args[CheckboxWidget::CHECKED_ELEMENT]))
|
||||
{
|
||||
$this->_args[CheckboxWidget::CHECKED_ELEMENT] = $jsonSchema->defaultValue;
|
||||
$this->_args[CheckboxWidget::CHECKED_ELEMENT] = $jsonSchema->{UDFWidgetTpl::DEFAULT_VALUE};
|
||||
}
|
||||
|
||||
$checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args);
|
||||
$parameters = array();
|
||||
|
||||
//
|
||||
if (isset($jsonSchema->listValues->enum))
|
||||
if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->enum))
|
||||
{
|
||||
$parameters = $jsonSchema->listValues->enum;
|
||||
$parameters = $jsonSchema->{UDFWidget::LIST_VALUES}->enum;
|
||||
}
|
||||
//
|
||||
else if (isset($jsonSchema->listValues->sql))
|
||||
else if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->sql))
|
||||
{
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->listValues->sql);
|
||||
$queryResult = $this->UDFModel->execQuery($jsonSchema->{UDFWidget::LIST_VALUES}->sql);
|
||||
if (hasData($queryResult))
|
||||
{
|
||||
$parameters = $queryResult->retval;
|
||||
{
|
||||
$tmpResult = (array)$queryResult->retval[0];
|
||||
$parameters = $tmpResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user