mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
e4160088e8
- Added comments where needed - Beautified the code where needed, more readable and more compliant to CS - loadResource function in helper fhc_helper.php is not using anymore CI - Moved all constants from UDFWidget to UDFLib - Added constant SORT to UDFLib - Renamed constant REGEX_LANGUAGE to FE_REGEX_LANGUAGE in UDFLib - Better formatting and indentation of the code of WidgetLib (more compliant to CS) - Added missing validation attributes to HTML widgets - Added constant HTML_DEFAULT_VALUE to CheckboxWidget - Unset parameter multiple in DropdownWidget constructor - Changed value of constant REQUIRED in widget HTMLWidget - Added protected property $htmlParameters to widget HTMLWidget (it works as alias to $this->_args[HTMLWidget::HTML_ARG_NAME] -> better code) - Replaced $this->_args[HTMLWidget::HTML_ARG_NAME] with $this->htmlParameters in the widgets - Changed the CSS class label[udf-required=true]::after to label[required-field=true]::after in widgets.css - Better use of constants in UDFWidget: constants from HTMLWidget are used only for the HTML parameters, while constants from UDFLib are used only for UDF parameters
85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Library to manage UDF
|
|
*/
|
|
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';
|
|
|
|
// UDF json schema attributes
|
|
const NAME = 'name'; // UDF name attribute
|
|
const TYPE = 'type'; // UDF type attribute
|
|
const SORT = 'sort'; // UDF sort attribute
|
|
const VALIDATION = 'validation'; // UDF validation attribute
|
|
const LIST_VALUES = 'listValues'; // UDF listValues attribute
|
|
const FE_REGEX_LANGUAGE = 'js'; // UDF javascript regex language attribute (front end)
|
|
|
|
// HTML components
|
|
const TITLE = 'description';
|
|
const LABEL = 'title';
|
|
const PLACEHOLDER = 'placeholder';
|
|
|
|
// Validation attributes
|
|
const REGEX = 'regex';
|
|
const REQUIRED = 'required';
|
|
const MAX_VALUE = 'max-value';
|
|
const MIN_VALUE = 'min-value';
|
|
const MAX_LENGTH = 'max-length';
|
|
const MIN_LENGTH = 'min-length';
|
|
|
|
const PHRASES_APP_NAME = 'core'; // Name of the app parameter used to retrive phrases
|
|
|
|
private $_ci; // Code igniter instance
|
|
|
|
public function __construct($config = array())
|
|
{
|
|
$this->_ci = & get_instance();
|
|
|
|
$this->_ci->load->helper('fhc');
|
|
|
|
// Loads the widget library
|
|
$this->_ci->load->library('WidgetLib');
|
|
|
|
// Loads widgets to render HTML for UDF
|
|
loadResource(APPPATH . 'widgets/udf');
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function UDFWidget($args, $htmlArgs = array())
|
|
{
|
|
if (!empty($args[UDFLib::SCHEMA_ARG_NAME]) && !empty($args[UDFLib::TABLE_ARG_NAME]))
|
|
{
|
|
//
|
|
if (empty($args[UDFLib::FIELD_ARG_NAME]) && !isset($htmlArgs[HTMLWidget::EXTERNAL_BLOCK]))
|
|
{
|
|
$htmlArgs[HTMLWidget::EXTERNAL_BLOCK] = true;
|
|
}
|
|
|
|
return $this->_ci->widgetlib->widget(
|
|
UDFLib::WIDGET_NAME,
|
|
$args,
|
|
$htmlArgs
|
|
);
|
|
}
|
|
else
|
|
{
|
|
if (empty($args[UDFLib::SCHEMA_ARG_NAME]))
|
|
{
|
|
show_error(UDFLib::SCHEMA_ARG_NAME.' parameter is missing!');
|
|
}
|
|
if (empty($args[UDFLib::TABLE_ARG_NAME]))
|
|
{
|
|
show_error(UDFLib::TABLE_ARG_NAME.' parameter is missing!');
|
|
}
|
|
}
|
|
}
|
|
} |