- Changed controller system/FAS_UDF, less busy now

- Method execReadOnlyQuery of DB_Model less strict check against SQL statements
- Added new public method setup to DB_Model to setup the model after initialization
- Added new constants to UDFLib
- Added new private method _printEndUDFBlock and _printEndUDFBlock to UDFLib
- Added new public methods setUDFUniqueId, getSession, getSessionElement, setSession, setSessionElement, saveUDFs and isAllowed to UDFLib
- Removed model system/FAS_UDF_model
- View views/system/fas_udf now uses the view templates/FHC-Header
- Added new parameter udfs to view templates/FHC-Header
- Added new properties to UDFWidget
- Added new private methods _initUDFWidget, _checkParameters and _startUDFWidget to UDFWidget
This commit is contained in:
Paolo
2019-12-17 13:35:41 +01:00
parent fc2d26e96d
commit 719f2d7314
10 changed files with 686 additions and 451 deletions
+12 -12
View File
@@ -12,7 +12,7 @@ class DropdownWidgetUDF extends DropdownWidget
{
// Array that will contains the elements to be displayed in the dropdown
$tmpNewElements = array();
// Loops through the given parameters
foreach($parameters as $parameter)
{
@@ -29,27 +29,27 @@ class DropdownWidgetUDF extends DropdownWidget
// If the single element is an array of two element
if (is_array($parameter) && count($parameter) == 2)
{
$newElement->{DropdownWidget::ID_FIELD} = $parameter[0]; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter[1]; //
$newElement->{DropdownWidget::ID_FIELD} = $parameter[0]; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter[1]; //
}
// If the single element is a string or a number
else if (is_string($parameter) || is_numeric($parameter))
{
$newElement->{DropdownWidget::ID_FIELD} = $parameter; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter; //
$newElement->{DropdownWidget::ID_FIELD} = $parameter; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter; //
}
// If the single element is an object with two properties: id and description
else if (is_object($parameter) && isset($parameter->{DropdownWidget::ID_FIELD})
&& isset($parameter->{DropdownWidget::DESCRIPTION_FIELD}))
{
$newElement->{DropdownWidget::ID_FIELD} = $parameter->{DropdownWidget::ID_FIELD}; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter->{DropdownWidget::DESCRIPTION_FIELD}; //
$newElement->{DropdownWidget::ID_FIELD} = $parameter->{DropdownWidget::ID_FIELD}; //
$newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter->{DropdownWidget::DESCRIPTION_FIELD}; //
}
array_push($tmpNewElements, $newElement); // Add $newElement into $tmpNewElements
}
}
// Set the list of elements
$this->setElementsArray(
success($tmpNewElements),
@@ -57,9 +57,9 @@ class DropdownWidgetUDF extends DropdownWidget
$this->htmlParameters[HTMLWidget::PLACEHOLDER],
'No data found for this UDF'
);
$this->loadDropDownView();
echo $this->content();
}
}
}
+146 -5
View File
@@ -6,14 +6,155 @@
*/
class UDFWidget extends HTMLWidget
{
private $_requiredPermissions; //
private $_schema;
private $_table;
private $_primaryKeyName;
private $_primaryKeyValue;
/**
* Initialize the UDFWidget and starts the execution of the logic
*/
public function __construct($name, $args = array())
{
parent::__construct($name, $args); // calls the parent's constructor
$this->load->library('UDFLib'); // Loads the UDFLib that contains all the used logic
$this->udflib->setUDFUniqueIdByParams($args);
$this->_initUDFWidget($args); // checks parameters and initialize properties
// Let's start if it's allowed
// NOTE: If it is NOT allowed then no data are loaded
if ($this->udflib->isAllowed($this->_requiredPermissions))
{
$this->_startUDFWidget($args[UDFLib::UDF_UNIQUE_ID]);
}
}
/**
* Called by the WidgetLib, it renders the HTML of the UDF
*/
public function display($widgetData)
{
// _ci is the instance of Code Igniter and the library UDFLib was previously loaded,
// so now is it possibile to call the method displayUDFWidget of UDFLib
// to render the HTML of this UDF
$this->_ci->udflib->displayUDFWidget($widgetData);
// Let's start if it's allowed
// NOTE: If it is NOT allowed then no data are loaded
if ($this->_ci->udflib->isAllowed($this->_requiredPermissions))
{
$this->_ci->udflib->displayUDFWidget($widgetData);
}
}
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Checks parameters and initialize all the properties of this UDFWidget
*/
private function _initUDFWidget($args)
{
$this->_checkParameters($args);
// If here then everything is ok
// Initialize class properties
$this->_requiredPermissions = null;
$this->_schema = null;
$this->_table = null;
$this->_primaryKeyName = null;
$this->_primaryKeyValue = null;
// Retrieved the required permissions parameter if present
if (isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER]))
{
$this->_requiredPermissions = $args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER];
}
// Retrieved the
if (isset($args[UDFLib::SCHEMA_ARG_NAME]))
{
$this->_schema = $args[UDFLib::SCHEMA_ARG_NAME];
}
// Retrieved the
if (isset($args[UDFLib::TABLE_ARG_NAME]))
{
$this->_table = $args[UDFLib::TABLE_ARG_NAME];
}
// Retrieved the
if (isset($args[UDFLib::PRIMARY_KEY_NAME]))
{
$this->_primaryKeyName = $args[UDFLib::PRIMARY_KEY_NAME];
}
// Retrieved the
if (isset($args[UDFLib::PRIMARY_KEY_VALUE]))
{
$this->_primaryKeyValue = $args[UDFLib::PRIMARY_KEY_VALUE];
}
}
/**
* Checks the required parameters used to call this UDFWidget
*/
private function _checkParameters($args)
{
if (!is_array($args) || (is_array($args) && count($args) == 0))
{
show_error('Second parameter of the widget call must be a NOT empty associative array');
}
else
{
if (!isset($args[UDFLib::UDF_UNIQUE_ID]))
{
show_error('The parameter "'.UDFLib::UDF_UNIQUE_ID.'" must be specified');
}
if (!isset($args[UDFLib::REQUIRED_PERMISSIONS_PARAMETER]))
{
show_error('The parameter "'.UDFLib::REQUIRED_PERMISSIONS_PARAMETER.'" must be specified');
}
if (!isset($args[UDFLib::SCHEMA_ARG_NAME]))
{
show_error('The parameter "'.UDFLib::SCHEMA_ARG_NAME.'" must be specified');
}
if (!isset($args[UDFLib::TABLE_ARG_NAME]))
{
show_error('The parameter "'.UDFLib::TABLE_ARG_NAME.'" must be specified');
}
if (!isset($args[UDFLib::PRIMARY_KEY_NAME]))
{
show_error('The parameter "'.UDFLib::PRIMARY_KEY_NAME.'" must be specified');
}
if (!isset($args[UDFLib::PRIMARY_KEY_VALUE]))
{
show_error('The parameter "'.UDFLib::PRIMARY_KEY_VALUE.'" must be specified');
}
}
}
/**
* Contains all the logic used to load all the data needed to the UDFWidget
*/
private function _startUDFWidget($udfUniqueId)
{
// Stores an array that contains all the data useful for
$this->udflib->setSession(
array(
UDFLib::UDF_UNIQUE_ID => $udfUniqueId, // table unique id
UDFLib::REQUIRED_PERMISSIONS_PARAMETER => $this->_requiredPermissions, //
UDFLib::SCHEMA_ARG_NAME => $this->_schema, //
UDFLib::TABLE_ARG_NAME => $this->_table, //
UDFLib::PRIMARY_KEY_NAME => $this->_primaryKeyName, //
UDFLib::PRIMARY_KEY_VALUE => $this->_primaryKeyValue //
)
);
}
}