Merge branch 'master' into dbskel

This commit is contained in:
Paolo
2020-11-13 20:55:57 +01:00
172 changed files with 15744 additions and 6090 deletions
+10 -4
View File
@@ -93,6 +93,8 @@ class FilterWidgetLib
const OP_NOT_SET = 'nset';
// Filter options values
const OPT_MINUTES = 'minutes';
const OPT_HOURS = 'hours';
const OPT_DAYS = 'days';
const OPT_MONTHS = 'months';
@@ -884,8 +886,10 @@ class FilterWidgetLib
// It it's a date type
if (is_numeric($filterDefinition->condition)
&& isset($filterDefinition->option)
&& ($filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS))
&& ($filterDefinition->option == self::OPT_HOURS
|| $filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS
|| $filterDefinition->option == self::OPT_MINUTES))
{
$condition = '< (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
}
@@ -899,8 +903,10 @@ class FilterWidgetLib
// It it's a date type
if (is_numeric($filterDefinition->condition)
&& isset($filterDefinition->option)
&& ($filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS))
&& ($filterDefinition->option == self::OPT_HOURS
|| $filterDefinition->option == self::OPT_DAYS
|| $filterDefinition->option == self::OPT_MONTHS
|| $filterDefinition->option == self::OPT_MINUTES))
{
$condition = '> (NOW() - \''.$filterDefinition->condition.' '.$filterDefinition->option.'\'::interval)';
}
+370
View File
@@ -0,0 +1,370 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library that contains all the needed functionalities to operate with the Jobs Queue System
*/
class JobsQueueLib
{
// Job statuses
const STATUS_NEW = 'new';
const STATUS_RUNNING = 'running';
const STATUS_DONE = 'done';
const STATUS_FAILED = 'failed';
// Job object properties
const PROPERTY_JOBID = 'jobid';
const PROPERTY_CREATIONTIME = 'creationtime';
const PROPERTY_TYPE = 'type';
const PROPERTY_STATUS = 'status';
const PROPERTY_INPUT = 'input';
const PROPERTY_OUTPUT = 'output';
const PROPERTY_START_TIME = 'starttime';
const PROPERTY_END_TIME = 'endtime';
const PROPERTY_ERROR = 'error';
private $_ci; // CI instance
/**
* Constructor
*/
public function __construct($authenticate = true)
{
// Gets CI instance
$this->_ci =& get_instance();
// Loads all needed models
$this->_ci->load->model('system/JobsQueue_model', 'JobsQueueModel');
$this->_ci->load->model('system/JobTypes_model', 'JobTypesModel');
$this->_ci->load->model('system/JobStatuses_model', 'JobStatusesModel');
$this->_ci->load->model('system/JobTriggers_model', 'JobTriggersModel');
}
//------------------------------------------------------------------------------------------------------------------
// Public methods
/**
* To get all the most recently added jobs using the given job type
*/
public function getLastJobs($type)
{
$this->_ci->JobsQueueModel->resetQuery();
$this->_ci->JobsQueueModel->addOrder('creationtime', 'DESC');
return $this->_ci->JobsQueueModel->loadWhere(array('status' => self::STATUS_NEW, 'type' => $type));
}
/**
* To get all the jobs specified by the given parameters
*/
public function getJobsByTypeStatusInput($type, $status, $input)
{
$this->_ci->JobsQueueModel->resetQuery();
$this->_ci->JobsQueueModel->addOrder('creationtime', 'DESC');
return $this->_ci->JobsQueueModel->loadWhere(array('status' => $status, 'type' => $type, 'input' => $input));
}
/**
* Add new jobs in the jobs queue with the given type
* jobs is an array of job objects
*/
public function addNewJobsToQueue($type, $jobs)
{
// Checks parameters
if (isEmptyString($type)) return error('The provided type parameter is not a valid string');
if (isEmptyArray($jobs)) return error('The provided jobs parameter is not a valid array');
// Get all the job types
$dbResult = $this->_ci->JobTypesModel->load();
if (isError($dbResult)) return $dbResult;
$types = getData($dbResult);
// If the given type is not present in database
if (!$this->_checkJobType($type, $types)) return error('The provided type parameter is not valid');
$results = $jobs; // returned values
$errorOccurred = false; // very optimistic
// Get all the job statuses
$dbResult = $this->_ci->JobStatusesModel->load();
if (isError($dbResult)) return $dbResult;
$statuses = getData($dbResult);
// Loops through all the provided jobs
foreach ($results as $job)
{
// If the structure of the job object is valid AND the type is valid AND the status is valid
if ($this->_checkNewJobStructure($job) && $this->_checkJobStatus($job, $statuses))
{
$this->_dropNotAllowedPropertiesNewJob($job); // remove the black listed properties from this object
$job->{self::PROPERTY_TYPE} = $type; // What you asked is what you get!
// Try to insert the single job into database
$dbNewJobResult = $this->_ci->JobsQueueModel->insert($job);
// If an error occurred during while inserting in database
if (isError($dbNewJobResult))
{
$job->{self::PROPERTY_ERROR} = getError($dbNewJobResult); // retrieve the cause and store it in job object
$errorOccurred = true; // set error occurred flag
}
else // otherwise
{
$job->{self::PROPERTY_JOBID} = getData($dbNewJobResult); // get the jobid and store it in job object
$dbNewTriggeredJobResult = $this->_addNewTriggeredJobToQueue($type, $job, array(self::STATUS_NEW));
// If an error occurred during while inserting in database
if (isError($dbNewTriggeredJobResult)) return $dbNewTriggeredJobResult;
}
}
else // otherwise
{
$errorOccurred = true; // set error occurred flag
}
}
// If an error occurred then returns the results in an error object
if ($errorOccurred) return error($results);
return success($results); // otherwise return results in a success object
}
/**
* Updates jobs already present in the jobs queue
* jobs is an array of job objects
*/
public function updateJobsQueue($type, $jobs)
{
// Checks parameters
if (isEmptyArray($jobs)) return error('The provided jobs parameter is not a valid array');
$results = $jobs; // returned values
$errorOccurred = false; // very optimistic
// Get all the job statuses
$dbResultStatuses = $this->_ci->JobStatusesModel->load();
if (isError($dbResultStatuses)) return $dbResultStatuses;
$statuses = getData($dbResultStatuses);
// Loops through all the provided jobs
foreach ($results as $job)
{
// Check if the required job is present in the database
$dbResultJobs = $this->_ci->JobsQueueModel->load($job->{self::PROPERTY_JOBID});
if (isError($dbResultJobs))
{
$job->{self::PROPERTY_ERROR} = getError($dbResultJobs); // retrieve the cause and store it in job object
$errorOccurred = true; // set error occurred flag
}
elseif (!hasData($dbResultJobs)) // if no jobs were found
{
$job->{self::PROPERTY_ERROR} = 'The required job is not present';
$errorOccurred = true; // set error occurred flag
}
else // if a job was found then it could be updated
{
// If the structure of the job object is valid
if ($this->_checkUpdateJobStructure($job) && $this->_checkJobStatus($job, $statuses))
{
$this->_dropNotAllowedPropertiesUpdateJob($job); // remove the black listed properties from this object
$job->{self::PROPERTY_TYPE} = $type; // What you asked is what you get!
// Try to update the single job into database
$dbResult = $this->_ci->JobsQueueModel->update($job->{self::PROPERTY_JOBID}, (array)$job);
// If an error occurred during while updating in database
if (isError($dbResult))
{
$job->{self::PROPERTY_ERROR} = getError($dbResult); // retrieve the cause and store it in job object
$errorOccurred = true; // set error occurred flag
}
else // otherwise
{
$dbNewTriggeredJobResult = $this->_addNewTriggeredJobToQueue(
$type,
$job,
array($job->status)
);
// If an error occurred during while inserting in database
if (isError($dbNewTriggeredJobResult)) return $dbNewTriggeredJobResult;
}
}
else // otherwise
{
$errorOccurred = true; // set error occurred flag
}
}
}
// If an error occurred then returns the results in an error object
if ($errorOccurred) return error($results);
return success($results); // otherwise return results in a success object
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Checks the job object structure when needed for insert
*/
private function _checkNewJobStructure(&$job)
{
// If job is a valid object and contains the required properties AND does NOT already contain the property error
if (is_object($job)
&& property_exists($job, self::PROPERTY_STATUS)
&& !property_exists($job, self::PROPERTY_ERROR))
{
return true; // it is valid!
}
// If not object then object it!
if (!is_object($job)) $job = new stdClass();
// If an error property was not already previously stored then store an error message in job object
if (!property_exists($job, self::PROPERTY_ERROR))
{
$job->{self::PROPERTY_ERROR} = 'The structure of the provided job is not valid';
}
return false; // better sorry than wrong
}
/**
* Checks the job object structure when needed for update
*/
private function _checkUpdateJobStructure(&$job)
{
// If job is a valid object
if (is_object($job) && property_exists($job, self::PROPERTY_JOBID)) return true; // it is valid!
// If not object then object it!
if (!is_object($job)) $job = new stdClass();
// If an error property was not already previously stored then store an error message in job object
if (!property_exists($job, self::PROPERTY_ERROR))
{
$job->{self::PROPERTY_ERROR} = 'The structure of the provided job is not valid';
}
return false; // better sorry than wrong
}
/**
* Checks if the given job contains a valid type
*/
private function _checkJobType($type, $types)
{
return $this->_inArray($type, $types, self::PROPERTY_TYPE);
}
/**
* Checks if the given job contains a valid status
*/
private function _checkJobStatus(&$job, $statuses)
{
// If the given job doesn't have the property status then it is not valid
if (!isset($job->{self::PROPERTY_STATUS}))
{
$found = false;
}
else // otherwise test if it valid
{
$found = $this->_inArray($job->{self::PROPERTY_STATUS}, $statuses, self::PROPERTY_STATUS);
}
// No status was found and does NOT already contain the property error
if (!$found && !property_exists($job, self::PROPERTY_ERROR))
{
$job->{self::PROPERTY_ERROR} = 'The provided status of this job is not valid'; // store the error message in the object
}
return $found;
}
/**
* Search in an array the given value
* The elements of the given array are objects
* The given value is compared with the property specified by the $propertyName parameter of each object of the given array
*/
private function _inArray($value, $array, $propertyName)
{
$found = false;
foreach ($array as $element)
{
if ($value == $element->{$propertyName})
{
$found = true;
break;
}
}
return $found;
}
/**
* Drop not allowed properties from the given job
*/
private function _dropNotAllowedPropertiesNewJob(&$job)
{
unset($job->{self::PROPERTY_JOBID});
unset($job->{self::PROPERTY_CREATIONTIME});
unset($job->{self::PROPERTY_TYPE});
}
/**
* Drop not allowed properties from the given job
*/
private function _dropNotAllowedPropertiesUpdateJob(&$job)
{
unset($job->{self::PROPERTY_CREATIONTIME});
unset($job->{self::PROPERTY_TYPE});
}
/**
* Add e new triggered job to the jobs queue
* NOTE:
* - In this method there are less checks compared to addNewJobsToQueue method because
* the new jobs that will be added are generate in this method
* - Job ids in this case are not returned, therefore the caller is not going to be informed about these new jobs
*/
private function _addNewTriggeredJobToQueue($type, $job, $triggeredStatuses)
{
// Get all the job trigggers for the given type and for the given statuses
$dbTriggersResult = $this->_ci->JobTriggersModel->getJobtriggersByTypeStatuses($type, $triggeredStatuses);
// If an error occurred while getting job triggers from database then return it
if (isError($dbTriggersResult)) return $dbTriggersResult;
if (hasData($dbTriggersResult)) // If triggers were retrieved
{
// The output of the trigging job is the input of the trigged job
$triggeredJobInput = null;
if (isset($job->{self::PROPERTY_OUTPUT})) $triggeredJobInput = $job->{self::PROPERTY_OUTPUT};
// For each trigger
foreach (getData($dbTriggersResult) as $trigger)
{
$triggeredJob = array(
self::PROPERTY_TYPE => $trigger->following_type, // the new type is the one defined in tbl_jobtriggers
self::PROPERTY_STATUS => self::STATUS_NEW, // new job status is new
self::PROPERTY_INPUT => $triggeredJobInput // new job input
);
// Try to insert the single job into database
$dbNewJob = $this->_ci->JobsQueueModel->insert($triggeredJob);
// If an error occurred during while inserting in database
if (isError($dbNewJob)) return $dbNewJob;
}
}
return success(); // if here then it was a success!
}
}
+45 -12
View File
@@ -42,6 +42,8 @@ class LogLib
const P_NAME_LINE_INDEX = 'lineIndex';
const P_NAME_DB_LOG_TYPE = 'dbLogType';
const P_NAME_DB_EXECUTE_USER = 'dbExecuteUser';
const P_NAME_REQUEST_ID = 'requestId';
const P_NAME_REQUEST_DATA_FORMATTER = 'requestDataFormatter';
// Properties used to retrieve caller data
private $_classIndex;
@@ -52,6 +54,9 @@ class LogLib
private $_dbLogType;
private $_dbExecuteUser;
private $_requestId; // is it possible to specify a request id when loading this library
private $_requestDataFormatter; // is possible to provide a function to format request data
/**
* Set properties to a default value or overwrites them with the given parameters
*/
@@ -63,7 +68,18 @@ class LogLib
$this->_lineIndex = self::LINE_INDEX;
$this->_dbLogType = null;
$this->_dbExecuteUser = self::DB_EXECUTE_USER;
$this->_requestId = null;
$this->_requestDataFormatter = null;
// If parameters are given then overwrite the default values
if (!isEmptyArray($params)) $this->setConfigs($params);
}
/**
* Store configuration parameters for this lib
*/
public function setConfigs($params)
{
// If parameters are given then overwrite the default values
if (!isEmptyArray($params))
{
@@ -72,6 +88,8 @@ class LogLib
if (isset($params[self::P_NAME_LINE_INDEX])) $this->_lineIndex = $params[self::P_NAME_LINE_INDEX];
if (isset($params[self::P_NAME_DB_LOG_TYPE])) $this->_dbLogType = $params[self::P_NAME_DB_LOG_TYPE];
if (isset($params[self::P_NAME_DB_EXECUTE_USER])) $this->_dbExecuteUser = $params[self::P_NAME_DB_EXECUTE_USER];
if (isset($params[self::P_NAME_REQUEST_ID])) $this->_requestId = $params[self::P_NAME_REQUEST_ID];
if (isset($params[self::P_NAME_REQUEST_DATA_FORMATTER])) $this->_requestDataFormatter = $params[self::P_NAME_REQUEST_DATA_FORMATTER];
}
}
@@ -108,33 +126,33 @@ class LogLib
/**
* Writes an info log to database
*/
public function logInfoDB($requestId, $data)
public function logInfoDB($data, $requestId = null)
{
$this->_logDB(self::INFO, $requestId, $data);
$this->_logDB(self::INFO, $data, $requestId);
}
/**
* Writes a debug log to database
*/
public function logDebugDB($requestId, $data)
public function logDebugDB($data, $requestId = null)
{
$this->_logDB(self::DEBUG, $requestId, $data);
$this->_logDB(self::DEBUG, $data, $requestId);
}
/**
* Writes an warning log to database
*/
public function logWarningDB($requestId, $data)
public function logWarningDB($data, $requestId = null)
{
$this->_logDB(self::WARNING, $requestId, $data);
$this->_logDB(self::WARNING, $data, $requestId);
}
/**
* Writes an error log to database
*/
public function logErrorDB($requestId, $data)
public function logErrorDB($data, $requestId = null)
{
$this->_logDB(self::ERROR, $requestId, $data);
$this->_logDB(self::ERROR, $data, $requestId);
}
// --------------------------------------------------------------------------------------------------------------
@@ -151,8 +169,15 @@ class LogLib
/**
* Writes logs to database
*/
private function _logDB($level, $requestId, $data)
private function _logDB($level, $data, $requestId, $executionTime = null)
{
// If there isn't a valid request id provided during the loading of this library or when any log to db method is called
// NOTE: this message will be displayed only to the developer AND stops the execution
if (isEmptyString($this->_requestId) && isEmptyString($requestId))
{
show_error('To log to database you need to specify or give the "'.self::P_NAME_REQUEST_ID.'" parameter when the LogLib is loaded or when log'.ucfirst($level).'DB is called');
}
// If the _dbLogType parameter was not given when this library was loaded
// NOTE: this message will be displayed only to the developer AND stops the execution
if ($this->_dbLogType == null)
@@ -175,14 +200,21 @@ class LogLib
// Get caller data
$callerData = $this->_getCaller();
// If a request data formatter was defined then use it
$request_data = $data;
if ($this->_requestDataFormatter != null && is_callable($this->_requestDataFormatter))
{
$request_data = call_user_func_array($this->_requestDataFormatter, array($data));
}
// Writes a log to database
$ci->WebservicelogModel->insert(array(
'webservicetyp_kurzbz' => $this->_dbLogType,
'request_id' => $requestId,
'request_id' => (!isEmptyString($requestId) ? $requestId : $this->_requestId).' - '.$level,
'beschreibung' => $this->_getDatabaseDescription($callerData),
'request_data' => $data,
'request_data' => $request_data,
'execute_user' => $this->_dbExecuteUser,
'execute_time' => 'NOW()' // current time
'execute_time' => $executionTime == null ? 'NOW()' : $executionTime // default current time, if not otherwise specified
));
}
}
@@ -251,3 +283,4 @@ class LogLib
return $formatted;
}
}
+3 -3
View File
@@ -147,7 +147,7 @@ class PermissionLib
$accessType = '';
// Checks if the required access type is compliant with the HTTP method (GET => r, POST => w)
// Set the access type
if (strpos($requiredAccessType, PermissionLib::READ_RIGHT) !== false)
{
$accessType = PermissionLib::SELECT_RIGHT; // S
@@ -184,12 +184,12 @@ class PermissionLib
}
else
{
show_error('The given permission array does not contain the called method or is not correctly set');
show_error('The given permission array does not contain the given method or is not correctly set');
}
}
else
{
show_error('You must give the permissions array as parameter to the constructor of the controller');
show_error('The given permissions is not a valid array or it is an empty one');
}
return $checkPermissions;
+284 -119
View File
@@ -3,15 +3,20 @@
if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Library to manage UDF
* Library to manage UDFs
*/
class UDFLib
{
const WIDGET_NAME = 'UDFWidget';
const SCHEMA_ARG_NAME = 'schema';
const TABLE_ARG_NAME = 'table';
const FIELD_ARG_NAME = 'field';
const UDFS_ARG_NAME = 'udfs';
const UDF_UNIQUE_ID = 'udfUniqueId'; // Name of the UDF widget unique id
const SESSION_NAME = 'FHC_UDF_WIDGET'; // Name of the session area used for UDFs
// Parameters names
const WIDGET_NAME = 'UDFWidget'; // UDFWidget name
const SCHEMA_ARG_NAME = 'schema'; // Schema parameter name
const TABLE_ARG_NAME = 'table'; // Table parameter name
const FIELD_ARG_NAME = 'field'; // Field parameter name
const UDFS_ARG_NAME = 'udfs'; // UDFs parameter name
// UDF json schema attributes
const NAME = 'name'; // UDF name attribute
@@ -22,6 +27,16 @@ class UDFLib
const FE_REGEX_LANGUAGE = 'js'; // UDF javascript regex language attribute (front end)
const BE_REGEX_LANGUAGE = 'php'; // UDF php regex language attribute (back end)
// ...to specify permissions that are needed to use this TableWidget
const REQUIRED_PERMISSIONS_PARAMETER = 'requiredPermissions';
// ...to specify the primary key name and value
const PRIMARY_KEY_NAME = 'primaryKeyName';
const PRIMARY_KEY_VALUE = 'primaryKeyValue';
const PERMISSION_TABLE_METHOD = 'UDFWidget'; // Name for fake method to be checked by the PermissionLib
const PERMISSION_TYPE = 'rw';
// HTML components
const LABEL = 'title';
const TITLE = 'description';
@@ -47,8 +62,10 @@ class UDFLib
private $_ci; // Code igniter instance
private $_udfUniqueId; // Property that contains the UDF widget unique id
/**
* Loads fhc helper
* Gets CI instance
*/
public function __construct()
{
@@ -63,8 +80,8 @@ class UDFLib
*/
public function UDFWidget($args, $htmlArgs = array())
{
if ((isset($args[UDFLib::SCHEMA_ARG_NAME]) && !isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
&& (isset($args[UDFLib::TABLE_ARG_NAME]) && !isEmptyString($args[UDFLib::TABLE_ARG_NAME])))
if ((isset($args[self::SCHEMA_ARG_NAME]) && !isEmptyString($args[self::SCHEMA_ARG_NAME]))
&& (isset($args[self::TABLE_ARG_NAME]) && !isEmptyString($args[self::TABLE_ARG_NAME])))
{
// Loads the widget library
$this->_ci->load->library('WidgetLib');
@@ -73,26 +90,26 @@ class UDFLib
loadResource(APPPATH.'widgets/udf');
// Default external block is true
if (!isset($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
if (!isset($args[self::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
{
$htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
}
return $this->_ci->widgetlib->widget(
UDFLib::WIDGET_NAME,
self::WIDGET_NAME,
$args,
$htmlArgs
);
}
else
{
if (!isset($args[UDFLib::SCHEMA_ARG_NAME]) || isEmptyString($args[UDFLib::SCHEMA_ARG_NAME]))
if (!isset($args[self::SCHEMA_ARG_NAME]) || isEmptyString($args[self::SCHEMA_ARG_NAME]))
{
show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
show_error(self::SCHEMA_ARG_NAME.' parameter is missing!');
}
if (!isset($args[UDFLib::TABLE_ARG_NAME]) || isEmptyString($args[UDFLib::TABLE_ARG_NAME]))
if (!isset($args[self::TABLE_ARG_NAME]) || isEmptyString($args[self::TABLE_ARG_NAME]))
{
show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
show_error(self::TABLE_ARG_NAME.' parameter is missing!');
}
}
}
@@ -105,12 +122,12 @@ class UDFLib
*/
public function displayUDFWidget(&$widgetData)
{
$schema = $widgetData[UDFLib::SCHEMA_ARG_NAME]; // schema attribute
$table = $widgetData[UDFLib::TABLE_ARG_NAME]; // table attribute
$schema = $widgetData[self::SCHEMA_ARG_NAME]; // schema attribute
$table = $widgetData[self::TABLE_ARG_NAME]; // table attribute
if (isset($widgetData[UDFLib::FIELD_ARG_NAME]))
if (isset($widgetData[self::FIELD_ARG_NAME]))
{
$field = $widgetData[UDFLib::FIELD_ARG_NAME]; // UDF name
$field = $widgetData[self::FIELD_ARG_NAME]; // UDF name
}
$udfResults = $this->_loadUDF($schema, $table); // loads UDF definition
@@ -122,6 +139,9 @@ class UDFLib
$jsonSchemas = json_decode($udf->jsons); // decode the json schema
if (is_object($jsonSchemas) || is_array($jsonSchemas))
{
//
$this->_printStartUDFBlock($widgetData);
// If the schema is an object then convert it into an array
if (is_object($jsonSchemas))
{
@@ -140,18 +160,18 @@ class UDFLib
foreach ($jsonSchemasArray as $jsonSchema)
{
// If the type property is not present then show an error
if (!isset($jsonSchema->{UDFLib::TYPE}))
if (!isset($jsonSchema->{self::TYPE}))
{
show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table));
}
// If the name property is not present then show an error
if (!isset($jsonSchema->{UDFLib::NAME}))
if (!isset($jsonSchema->{self::NAME}))
{
show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table));
}
// If a UDF is specified and is present in the json schemas list or no UDF is specified
if ((isset($field) && $field == $jsonSchema->{UDFLib::NAME}) || !isset($field))
if ((isset($field) && $field == $jsonSchema->{self::NAME}) || !isset($field))
{
// Set attributes using phrases
$this->_setAttributesWithPhrases($jsonSchema, $widgetData[HTMLWidget::HTML_ARG_NAME]);
@@ -166,7 +186,7 @@ class UDFLib
$this->_render($jsonSchema, $widgetData);
// If a UDf is specified and it was found then stop looking through this list
if (isset($field) && $field == $jsonSchema->{UDFLib::NAME})
if (isset($field) && $field == $jsonSchema->{self::NAME})
{
$found = true;
break;
@@ -179,6 +199,9 @@ class UDFLib
{
show_error(sprintf('%s.%s: No schema present for field: %s', $schema, $table, $field));
}
//
$this->_printEndUDFBlock();
}
else // not a valid schema
{
@@ -218,7 +241,7 @@ class UDFLib
// Decodes json that define the UDFs for this table
$decodedUDFDefinitions = json_decode(
$resultUDFsDefinitions->retval[0]->{UDFLib::COLUMN_JSON_DESCRIPTION}
$resultUDFsDefinitions->retval[0]->{self::COLUMN_JSON_DESCRIPTION}
);
// Loops through the UDFs definitions
@@ -232,28 +255,28 @@ class UDFLib
$tmpValidate = success(true); // temporary variable used to store the returned value from _validateUDFs
// If this is the definition of this UDF
if ($decodedUDFDefinition->{UDFLib::NAME} == $key)
if ($decodedUDFDefinition->{self::NAME} == $key)
{
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION})) // If validation rules are present for this UDF
if (isset($decodedUDFDefinition->{self::VALIDATION})) // If validation rules are present for this UDF
{
// Checks if the given UDF is required and the result will be stored in $chkRequiredPassed
// If $chkRequiredPassed == true => required check passed
// If $chkRequiredPassed == false => required check NOT passed
$chkRequiredPassed = true;
// If required property is present in the UDF description and it is true
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === true)
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === true)
{
// If this UDF is a checkbox and the given value is false
// OR
// if this UDF is NOT a checkbox and the given value is null
if (($decodedUDFDefinition->{UDFLib::TYPE} == UDFLib::CHKBOX_TYPE && $val === false)
|| ($decodedUDFDefinition->{UDFLib::TYPE} != UDFLib::CHKBOX_TYPE && $val == null))
// if this UD7F is NOT a checkbox and the given value is null
if (($decodedUDFDefinition->{self::TYPE} == self::CHKBOX_TYPE && $val === false)
|| ($decodedUDFDefinition->{self::TYPE} != self::CHKBOX_TYPE && $val == null))
{
$chkRequiredPassed = false; // not passed
// A new error is generated and added to array $requiredUDFsArray
$requiredUDFsArray[$decodedUDFDefinition->{UDFLib::NAME}] = error(
$decodedUDFDefinition->{UDFLib::NAME},
$requiredUDFsArray[$decodedUDFDefinition->{self::NAME}] = error(
$decodedUDFDefinition->{self::NAME},
EXIT_VALIDATION_UDF_REQUIRED
);
}
@@ -267,22 +290,22 @@ class UDFLib
// If $toBeValidated == false => validation is NOT performed
$toBeValidated = false;
// If this UDF is NOT a checkbox
if ($decodedUDFDefinition->{UDFLib::TYPE} != UDFLib::CHKBOX_TYPE)
if ($decodedUDFDefinition->{self::TYPE} != self::CHKBOX_TYPE)
{
// If required property is NOT present in the UDF description
if (!isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED}))
if (!isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED}))
{
$toBeValidated = true;
}
// If required property is present in the UDF description and it is true
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === true)
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === true)
{
$toBeValidated = true;
}
// If required property is present in the UDF description and it is true and the given value is null
if (isset($decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED})
&& $decodedUDFDefinition->{UDFLib::VALIDATION}->{UDFLib::REQUIRED} === false
if (isset($decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED})
&& $decodedUDFDefinition->{self::VALIDATION}->{self::REQUIRED} === false
&& $val != null)
{
$toBeValidated = true;
@@ -292,8 +315,8 @@ class UDFLib
if ($toBeValidated === true) // Checks if validation should be performed
{
$tmpValidate = $this->_validateUDFs(
$decodedUDFDefinition->{UDFLib::VALIDATION},
$decodedUDFDefinition->{UDFLib::NAME},
$decodedUDFDefinition->{self::VALIDATION},
$decodedUDFDefinition->{self::NAME},
$val
);
}
@@ -341,7 +364,7 @@ class UDFLib
if ($encodedToBeStoredUDFs !== false) // if encode was ok
{
// Save the supplied UDFs values
$data[UDFLib::COLUMN_NAME] = $encodedToBeStoredUDFs;
$data[self::COLUMN_NAME] = $encodedToBeStoredUDFs;
}
}
else // otherwise the returning value will be the list of UDFs validation errors
@@ -360,8 +383,8 @@ class UDFLib
{
$isUDFColumn = false;
if (substr($columnName, 0, strlen(UDFLib::COLUMN_PREFIX)) == UDFLib::COLUMN_PREFIX
&& $columnType == UDFLib::COLUMN_TYPE)
if (substr($columnName, 0, strlen(self::COLUMN_PREFIX)) == self::COLUMN_PREFIX
&& $columnType == self::COLUMN_TYPE)
{
$isUDFColumn = true;
}
@@ -369,9 +392,151 @@ class UDFLib
return $isUDFColumn;
}
/**
* Set the _udfUniqueId property
*/
public function setUDFUniqueId($udfUniqueId)
{
$this->_udfUniqueId = $udfUniqueId;
}
/**
* Return an unique string that identify this UDF widget
* NOTE: The default value is the URI where the FilterWidget is called
* If the fhc_controller_id is present then is also used
*/
public function setUDFUniqueIdByParams($params)
{
if ($params != null
&& is_array($params)
&& isset($params[self::UDF_UNIQUE_ID])
&& !isEmptyString($params[self::UDF_UNIQUE_ID]))
{
$udfUniqueId = $this->_ci->router->directory.$this->_ci->router->class.'/'.
$this->_ci->router->method.'/'.
$params[self::UDF_UNIQUE_ID];
$this->setUDFUniqueId($udfUniqueId);
}
}
/**
* Wrapper method to the session helper funtions to retrieve the whole session for this UDF widget
*/
public function getSession()
{
return getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
}
/**
* Wrapper method to the session helper funtions to retrieve one element from the session of this UDF widget
*/
public function getSessionElement($name)
{
$session = getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
if (isset($session[$name]))
{
return $session[$name];
}
return null;
}
/**
* Wrapper method to the session helper funtions to set the whole session for this UDF widget
*/
public function setSession($data)
{
setSessionElement(self::SESSION_NAME, $this->_udfUniqueId, $data);
}
/**
* Wrapper method to the session helper funtions to set one element in the session for this UDF widget
*/
public function setSessionElement($name, $value)
{
$session = getSessionElement(self::SESSION_NAME, $this->_udfUniqueId);
$session[$name] = $value;
setSessionElement(self::SESSION_NAME, $this->_udfUniqueId, $session); // stores the single value
}
/**
* Save UDFs
*/
public function saveUDFs($udfUniqueId, $udfs)
{
// Read the all session for this udf widget
$session = $this->getSession();
// If session is empty then return an error
if ($session == null) return error('No UDFWidget loaded');
// Workaround to load CI
$this->_ci->load->model('system/UDF_model', 'UDFModel');
// Initialize a new DB_Model
$dbModel = new DB_Model();
// Setup the new dbModel object with...
$dbModel->setup(
$session[self::SCHEMA_ARG_NAME], // ... schema...
$session[self::TABLE_ARG_NAME], // ...table...
$session[self::PRIMARY_KEY_NAME] // ...and primary key name
);
// Returns the result of the database update operation to save UDFs
return $dbModel->update(
array($session[self::PRIMARY_KEY_NAME] => $session[self::PRIMARY_KEY_VALUE]),
(array)$udfs
);
}
/**
* Checks if at least one of the permissions given as parameter (requiredPermissions) belongs
* to the authenticated user, if confirmed then is allowed to use this UDFWidget.
* If the parameter requiredPermissions is NOT given or is not present in the session,
* then NO one is allow to use this UDFWidget
* Wrapper method to permissionlib->hasAtLeastOne
*/
public function isAllowed($requiredPermissions = null)
{
$this->_ci->load->library('PermissionLib'); // Load permission library
// Gets the required permissions from the session if they are not provided as parameter
$rq = $requiredPermissions;
if ($rq == null) $rq = $this->getSessionElement(self::REQUIRED_PERMISSIONS_PARAMETER);
return $this->_ci->permissionlib->hasAtLeastOne($rq, self::PERMISSION_TABLE_METHOD, self::PERMISSION_TYPE);
}
// -------------------------------------------------------------------------------------------------
// Private methods
/**
* Print the block for UDFs
*/
private function _printStartUDFBlock($widgetData)
{
$startBlock = '<div type="%s" udfUniqueId="%s">'."\n";
echo sprintf(
$startBlock,
self::WIDGET_NAME,
$widgetData[self::UDF_UNIQUE_ID]
);
}
/**
* Print the end of the UDFs block
*/
private function _printEndUDFBlock()
{
echo '</div>'."\n";
}
/**
* Move UDFs from $data to $UDFs
*/
@@ -381,7 +546,7 @@ class UDFLib
foreach ($data as $key => $val)
{
if (substr($key, 0, 4) == UDFLib::COLUMN_PREFIX)
if (substr($key, 0, 4) == self::COLUMN_PREFIX)
{
$udfsParameters[$key] = $val; // stores UDF value into property UDFs
unset($data[$key]); // remove from data
@@ -416,8 +581,8 @@ class UDFLib
{
// If min value attribute is present in the validation for this UDF,
// then checks if the value of this UDF is compliant to this attribute
if (isset($decodedUDFValidation->{UDFLib::MIN_VALUE})
&& $udfVal < $decodedUDFValidation->{UDFLib::MIN_VALUE})
if (isset($decodedUDFValidation->{self::MIN_VALUE})
&& $udfVal < $decodedUDFValidation->{self::MIN_VALUE})
{
// validation is failed and the error is stored in $returnArrayValidation
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_VALUE);
@@ -425,8 +590,8 @@ class UDFLib
// If max value attribute is present in the validation for this UDF,
// then checks if the value of this UDF is compliant to this attribute
if (isset($decodedUDFValidation->{UDFLib::MAX_VALUE})
&& $udfVal > $decodedUDFValidation->{UDFLib::MAX_VALUE})
if (isset($decodedUDFValidation->{self::MAX_VALUE})
&& $udfVal > $decodedUDFValidation->{self::MAX_VALUE})
{
// validation is failed and the error is stored in $returnArrayValidation
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_VALUE);
@@ -436,8 +601,8 @@ class UDFLib
$strUdfVal = strval($udfVal); // store in $strUdfVal the string conversion of $udfVal
// If min length attribute is present in the validation for this UDF,
// then checks if the value of this UDF is compliant to this attribute
if (isset($decodedUDFValidation->{UDFLib::MIN_LENGTH}) && isset($strUdfVal)
&& strlen($strUdfVal) < $decodedUDFValidation->{UDFLib::MIN_LENGTH})
if (isset($decodedUDFValidation->{self::MIN_LENGTH}) && isset($strUdfVal)
&& strlen($strUdfVal) < $decodedUDFValidation->{self::MIN_LENGTH})
{
// validation is failed and the error is stored in $returnArrayValidation
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MIN_LENGTH);
@@ -445,8 +610,8 @@ class UDFLib
// If max length attribute is present in the validation for this UDF,
// then checks if the value of this UDF is compliant to this attribute
if (isset($decodedUDFValidation->{UDFLib::MAX_LENGTH}) && isset($strUdfVal)
&& strlen($strUdfVal) > $decodedUDFValidation->{UDFLib::MAX_LENGTH})
if (isset($decodedUDFValidation->{self::MAX_LENGTH}) && isset($strUdfVal)
&& strlen($strUdfVal) > $decodedUDFValidation->{self::MAX_LENGTH})
{
// validation is failed and the error is stored in $returnArrayValidation
$returnArrayValidation[] = error($udfName, EXIT_VALIDATION_UDF_MAX_LENGTH);
@@ -457,12 +622,12 @@ class UDFLib
{
// Search for a php regular expression in the validation of this UDF, if one is found
// then checks if the value of this UDF is compliant to this attribute
if (isset($decodedUDFValidation->{UDFLib::REGEX})
&& is_array($decodedUDFValidation->{UDFLib::REGEX}))
if (isset($decodedUDFValidation->{self::REGEX})
&& is_array($decodedUDFValidation->{self::REGEX}))
{
foreach ($decodedUDFValidation->{UDFLib::REGEX} as $regexIndx => $regex)
foreach ($decodedUDFValidation->{self::REGEX} as $regexIndx => $regex)
{
if ($regex->language == UDFLib::BE_REGEX_LANGUAGE)
if ($regex->language == self::BE_REGEX_LANGUAGE)
{
if (preg_match($regex->expression, $udfVal) != 1)
{
@@ -494,8 +659,8 @@ class UDFLib
*/
private function _setNameAndId($jsonSchema, &$htmlParameters)
{
$htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{UDFLib::NAME};
$htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{UDFLib::NAME};
$htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{self::NAME};
$htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{self::NAME};
}
/**
@@ -504,20 +669,20 @@ class UDFLib
private function _sortJsonSchemas(&$jsonSchemasArray)
{
usort($jsonSchemasArray, function ($a, $b) {
if (!isset($a->{UDFLib::SORT}))
if (!isset($a->{self::SORT}))
{
$a->{UDFLib::SORT} = 9999;
$a->{self::SORT} = 9999;
}
if (!isset($b->{UDFLib::SORT}))
if (!isset($b->{self::SORT}))
{
$b->{UDFLib::SORT} = 9999;
$b->{self::SORT} = 9999;
}
if ($a->{UDFLib::SORT} == $b->{UDFLib::SORT})
if ($a->{self::SORT} == $b->{self::SORT})
{
return 0;
}
return ($a->{UDFLib::SORT} < $b->{UDFLib::SORT}) ? -1 : 1;
return ($a->{self::SORT} < $b->{self::SORT}) ? -1 : 1;
});
}
@@ -565,32 +730,32 @@ class UDFLib
private function _render($jsonSchema, &$widgetData)
{
// Checkbox
if ($jsonSchema->{UDFLib::TYPE} == 'checkbox')
if ($jsonSchema->{self::TYPE} == 'checkbox')
{
$this->_renderCheckbox($jsonSchema, $widgetData);
}
// Textfield
elseif ($jsonSchema->{UDFLib::TYPE} == 'textfield')
elseif ($jsonSchema->{self::TYPE} == 'textfield')
{
$this->_renderTextfield($jsonSchema, $widgetData);
}
// Textarea
elseif ($jsonSchema->{UDFLib::TYPE} == 'textarea')
elseif ($jsonSchema->{self::TYPE} == 'textarea')
{
$this->_renderTextarea($jsonSchema, $widgetData);
}
// Date
elseif ($jsonSchema->{UDFLib::TYPE} == 'date')
elseif ($jsonSchema->{self::TYPE} == 'date')
{
// To be done
}
// Dropdown
elseif ($jsonSchema->{UDFLib::TYPE} == 'dropdown')
elseif ($jsonSchema->{self::TYPE} == 'dropdown')
{
$this->_renderDropdown($jsonSchema, $widgetData);
}
// Multiple dropdown
elseif ($jsonSchema->{UDFLib::TYPE} == 'multipledropdown')
elseif ($jsonSchema->{self::TYPE} == 'multipledropdown')
{
$this->_renderDropdown($jsonSchema, $widgetData, true);
}
@@ -602,29 +767,29 @@ class UDFLib
private function _renderDropdown($jsonSchema, &$widgetData, $multiple = false)
{
// Selected element/s
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
if (isset($widgetData[self::UDFS_ARG_NAME])
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
{
$widgetData[DropdownWidget::SELECTED_ELEMENT] = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
$widgetData[DropdownWidget::SELECTED_ELEMENT] = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
}
else
{
$widgetData[DropdownWidget::SELECTED_ELEMENT] = null;
}
$dropdownWidgetUDF = new DropdownWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
$dropdownWidgetUDF = new DropdownWidgetUDF(self::WIDGET_NAME, $widgetData);
$parameters = array();
// If the list of values to show is an array
if (isset($jsonSchema->{UDFLib::LIST_VALUES}->enum))
if (isset($jsonSchema->{self::LIST_VALUES}->enum))
{
$parameters = $jsonSchema->{UDFLib::LIST_VALUES}->enum;
$parameters = $jsonSchema->{self::LIST_VALUES}->enum;
}
// If the list of values to show should be retrieved with a SQL statement
elseif (isset($jsonSchema->{UDFLib::LIST_VALUES}->sql))
elseif (isset($jsonSchema->{self::LIST_VALUES}->sql))
{
// UDFModel is loaded in method _loadUDF that is called before the current method
$queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{UDFLib::LIST_VALUES}->sql);
$queryResult = $this->_ci->UDFModel->execReadOnlyQuery($jsonSchema->{self::LIST_VALUES}->sql);
if (hasData($queryResult))
{
$parameters = $queryResult->retval;
@@ -645,13 +810,13 @@ class UDFLib
private function _renderTextarea($jsonSchema, &$widgetData)
{
$text = null; // text value
$textareaUDF = new TextareaWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
$textareaUDF = new TextareaWidgetUDF(self::WIDGET_NAME, $widgetData);
// Set text value if present in the DB
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
if (isset($widgetData[self::UDFS_ARG_NAME])
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
{
$text = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
$text = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
}
$textareaUDF->render($text);
@@ -663,13 +828,13 @@ class UDFLib
private function _renderTextfield($jsonSchema, &$widgetData)
{
$text = null; // text value
$textareaUDF = new TextfieldWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
$textareaUDF = new TextfieldWidgetUDF(self::WIDGET_NAME, $widgetData);
// Set text value if present in the DB
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
if (isset($widgetData[self::UDFS_ARG_NAME])
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
{
$text = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
$text = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
}
$textareaUDF->render($text);
@@ -681,17 +846,17 @@ class UDFLib
private function _renderCheckbox($jsonSchema, &$widgetData)
{
// Set checkbox value if present in the DB
if (isset($widgetData[UDFLib::UDFS_ARG_NAME])
&& isset($widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]))
if (isset($widgetData[self::UDFS_ARG_NAME])
&& isset($widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}]))
{
$widgetData[CheckboxWidget::VALUE_FIELD] = $widgetData[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}];
$widgetData[CheckboxWidget::VALUE_FIELD] = $widgetData[self::UDFS_ARG_NAME][$jsonSchema->{self::NAME}];
}
else
{
$widgetData[CheckboxWidget::VALUE_FIELD] = CheckboxWidget::HTML_DEFAULT_VALUE;
}
$checkboxWidgetUDF = new CheckboxWidgetUDF(UDFLib::WIDGET_NAME, $widgetData);
$checkboxWidgetUDF = new CheckboxWidgetUDF(self::WIDGET_NAME, $widgetData);
$checkboxWidgetUDF->render();
}
@@ -707,21 +872,21 @@ class UDFLib
$htmlParameters[HTMLWidget::PLACEHOLDER] = null;
// Description, title and placeholder
if (isset($jsonSchema->{UDFLib::LABEL})
|| isset($jsonSchema->{UDFLib::TITLE})
|| isset($jsonSchema->{UDFLib::PLACEHOLDER}))
if (isset($jsonSchema->{self::LABEL})
|| isset($jsonSchema->{self::TITLE})
|| isset($jsonSchema->{self::PLACEHOLDER}))
{
// Loads phrases library
$this->_ci->load->library('PhrasesLib');
// If is set the label property in the json schema
if (isset($jsonSchema->{UDFLib::LABEL}))
if (isset($jsonSchema->{self::LABEL}))
{
// Load the related phrase
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFLib::PHRASES_APP_NAME,
self::PHRASES_APP_NAME,
getUserLanguage(),
$jsonSchema->{UDFLib::LABEL},
$jsonSchema->{self::LABEL},
null,
null,
'no'
@@ -733,13 +898,13 @@ class UDFLib
}
// If is set the title property in the json schema
if (isset($jsonSchema->{UDFLib::TITLE}))
if (isset($jsonSchema->{self::TITLE}))
{
// Load the related phrase
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFLib::PHRASES_APP_NAME,
self::PHRASES_APP_NAME,
getUserLanguage(),
$jsonSchema->{UDFLib::TITLE},
$jsonSchema->{self::TITLE},
null,
null,
'no'
@@ -751,13 +916,13 @@ class UDFLib
}
// If is set the placeholder property in the json schema
if (isset($jsonSchema->{UDFLib::PLACEHOLDER}))
if (isset($jsonSchema->{self::PLACEHOLDER}))
{
// Load the related phrase
$tmpResult = $this->_ci->phraseslib->getPhrases(
UDFLib::PHRASES_APP_NAME,
self::PHRASES_APP_NAME,
getUserLanguage(),
$jsonSchema->{UDFLib::PLACEHOLDER},
$jsonSchema->{self::PLACEHOLDER},
null,
null,
'no'
@@ -784,17 +949,17 @@ class UDFLib
$htmlParameters[HTMLWidget::MAX_LENGTH] = null;
// If validation property is present in the json schema
if (isset($jsonSchema->{UDFLib::VALIDATION}))
if (isset($jsonSchema->{self::VALIDATION}))
{
$jsonSchemaValidation =& $jsonSchema->{UDFLib::VALIDATION}; // Reference for a better code readability
$jsonSchemaValidation =& $jsonSchema->{self::VALIDATION}; // Reference for a better code readability
// Front-end regex
if (isset($jsonSchemaValidation->{UDFLib::REGEX})
&& is_array($jsonSchemaValidation->{UDFLib::REGEX}))
if (isset($jsonSchemaValidation->{self::REGEX})
&& is_array($jsonSchemaValidation->{self::REGEX}))
{
foreach ($jsonSchemaValidation->{UDFLib::REGEX} as $regex)
foreach ($jsonSchemaValidation->{self::REGEX} as $regex)
{
if ($regex->language === UDFLib::FE_REGEX_LANGUAGE)
if ($regex->language === self::FE_REGEX_LANGUAGE)
{
$htmlParameters[HTMLWidget::REGEX] = $regex->expression;
}
@@ -802,33 +967,33 @@ class UDFLib
}
// Required
if (isset($jsonSchemaValidation->{UDFLib::REQUIRED}))
if (isset($jsonSchemaValidation->{self::REQUIRED}))
{
$htmlParameters[HTMLWidget::REQUIRED] = $jsonSchemaValidation->{UDFLib::REQUIRED};
$htmlParameters[HTMLWidget::REQUIRED] = $jsonSchemaValidation->{self::REQUIRED};
}
// Min value
if (isset($jsonSchemaValidation->{UDFLib::MIN_VALUE}))
if (isset($jsonSchemaValidation->{self::MIN_VALUE}))
{
$htmlParameters[HTMLWidget::MIN_VALUE] = $jsonSchemaValidation->{UDFLib::MIN_VALUE};
$htmlParameters[HTMLWidget::MIN_VALUE] = $jsonSchemaValidation->{self::MIN_VALUE};
}
// Max value
if (isset($jsonSchemaValidation->{UDFLib::MAX_VALUE}))
if (isset($jsonSchemaValidation->{self::MAX_VALUE}))
{
$htmlParameters[HTMLWidget::MAX_VALUE] = $jsonSchemaValidation->{UDFLib::MAX_VALUE};
$htmlParameters[HTMLWidget::MAX_VALUE] = $jsonSchemaValidation->{self::MAX_VALUE};
}
// Min length
if (isset($jsonSchemaValidation->{UDFLib::MIN_LENGTH}))
if (isset($jsonSchemaValidation->{self::MIN_LENGTH}))
{
$htmlParameters[HTMLWidget::MIN_LENGTH] = $jsonSchemaValidation->{UDFLib::MIN_LENGTH};
$htmlParameters[HTMLWidget::MIN_LENGTH] = $jsonSchemaValidation->{self::MIN_LENGTH};
}
// Max length
if (isset($jsonSchemaValidation->{UDFLib::MAX_LENGTH}))
if (isset($jsonSchemaValidation->{self::MAX_LENGTH}))
{
$htmlParameters[HTMLWidget::MAX_LENGTH] = $jsonSchemaValidation->{UDFLib::MAX_LENGTH};
$htmlParameters[HTMLWidget::MAX_LENGTH] = $jsonSchemaValidation->{self::MAX_LENGTH};
}
}
}