From e4160088e87e20a4684c71c73a0d9733212d4f17 Mon Sep 17 00:00:00 2001 From: Paolo Date: Thu, 17 Aug 2017 11:51:40 +0200 Subject: [PATCH] - Added headers where they were missing - 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 --- application/helpers/fhc_helper.php | 53 ++-- application/helpers/message_helper.php | 23 ++ application/libraries/UDFLib.php | 16 +- application/libraries/WidgetLib.php | 290 ++++++++++++------ .../models/system/MessageToken_model.php | 2 +- application/views/widgets/checkbox.php | 1 - application/views/widgets/dropdown.php | 2 +- application/views/widgets/textarea.php | 4 +- application/views/widgets/textfield.php | 6 +- application/widgets/html/CheckboxWidget.php | 4 +- application/widgets/html/DropdownWidget.php | 25 +- application/widgets/html/HTMLWidget.php | 24 +- application/widgets/html/TextareaWidget.php | 10 +- application/widgets/html/TextfieldWidget.php | 8 +- application/widgets/udf/CheckboxWidgetUDF.php | 4 +- application/widgets/udf/DropdownWidgetUDF.php | 47 +-- application/widgets/udf/TextareaWidgetUDF.php | 4 +- .../widgets/udf/TextfieldWidgetUDF.php | 4 +- application/widgets/udf/UDFWidget.php | 242 ++++++++------- skin/widgets.css | 2 +- 20 files changed, 478 insertions(+), 293 deletions(-) diff --git a/application/helpers/fhc_helper.php b/application/helpers/fhc_helper.php index a29ac240d..a7b5b2a29 100644 --- a/application/helpers/fhc_helper.php +++ b/application/helpers/fhc_helper.php @@ -3,26 +3,24 @@ /** * FH-Complete * - * @package FHC-Helper - * @author FHC-Team + * @package FHC-Helper + * @author FHC-Team * @copyright Copyright (c) 2016 fhcomplete.org - * @license GPLv3 - * @link https://fhcomplete.org - * @since Version 1.0.0 - * @filesource + * @license GPLv3 + * @since Version 1.0.0 */ -if (! defined('BASEPATH')) exit('No direct script access allowed'); - + /** * FHC Helper * - * @package FH-Complete * @subpackage Helpers * @category Helpers - * @author FHC-Team - * @link http://fhcomplete.org/user_guide/helpers/fhcauth_helper.html */ +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +// ------------------------------------------------------------------------ +// Collection of utility functions for general purpose // ------------------------------------------------------------------------ /** @@ -77,19 +75,29 @@ function var_dump_to_error_log($parameter) } /** - * + * Utility function to include only once one or more php files + * It can load more php files and also search in the subdirectories (one level only) + * Ex: + * - loadResource('/var/www/htdocs'): it loads all the php files present in path (no subdirectories) + * - loadResource('/var/www/htdocs', null, true): it loads all the php files present path and + * subdirectories (one level only) + * - loadResource('/var/www/htdocs', 'file1'): it loads the file file1.php present in path + * - loadResource('/var/www/htdocs', 'file1', true): it loads the file file1.php present in path + * or in the subdirs (one level only) + * - loadResource('/var/www/htdocs', array('file1', 'file2', 'file3')): it loads the files file1.php, + * file2.php and file3.php present in path + * - loadResource('/var/www/htdocs', array('file1', 'file2', 'file3'), true): it loads the files + * file1.php, file2.php and file3.php present in path or in the subdirectories (one level only) */ function loadResource($path, $resources = null, $subdir = false) { - $_ci = & get_instance(); - - // + // Place a / character at the and of the string if not present if (strrpos($path, '/') < strlen($path) - 1) { $path .= '/'; } - // + // Loads in $tmpResources all the given resources $tmpResources = $resources; if ($resources == null) { @@ -100,21 +108,23 @@ function loadResource($path, $resources = null, $subdir = false) $tmpResources = array($resources); } - // + // Loads in $tmpPaths path and eventually the subdirectories $tmpPaths = array($path); // NOTE: Used @ to prevent ugly error messages if (is_dir($path) && ($dirHandler = @opendir($path)) !== false) { + // Reads all file system entries present in path while (($entry = readdir($dirHandler)) !== false) { - // + // If entry is a directory but not the current and subdirectories should be loaded if ($subdir === true && $entry != '.' && $entry != '..' && is_dir($entry)) { $tmpPaths[] = $entry; } - // + // If no resources are specified and the current file system entry is a file if ($resources == null && is_file($path.$entry)) { + // If the current entry is a php file store the name without extension if ($entry != ($tmpName = str_replace('.php', '', $entry))) { $tmpResources[] = $tmpName; @@ -124,12 +134,13 @@ function loadResource($path, $resources = null, $subdir = false) closedir($dirHandler); } - // + // Loops through the resources foreach($tmpResources as $tmpResource) { + // Loops through the paths foreach($tmpPaths as $tmpPath) { - $fileName = $tmpPath.$tmpResource.'.php'; + $fileName = $tmpPath.$tmpResource.'.php'; // Php extension if (file_exists($fileName)) { include_once($fileName); diff --git a/application/helpers/message_helper.php b/application/helpers/message_helper.php index 70685ecee..1cba07eec 100644 --- a/application/helpers/message_helper.php +++ b/application/helpers/message_helper.php @@ -1,5 +1,28 @@ _ci->load->library('WidgetLib'); - // Loads widgets to render HTML elements - // NOTE: the first one to be loaded must be HTMLWidget + // Loads widgets to render HTML for UDF loadResource(APPPATH . 'widgets/udf'); } diff --git a/application/libraries/WidgetLib.php b/application/libraries/WidgetLib.php index bd6694136..0829944d8 100644 --- a/application/libraries/WidgetLib.php +++ b/application/libraries/WidgetLib.php @@ -33,7 +33,7 @@ class WidgetLib /* default values */ private $_template = 'template'; - private $_parser = FALSE; + private $_parser = false; private $_cache_ttl = 0; private $_widget_path = ''; @@ -51,7 +51,7 @@ class WidgetLib $this->_ci->load->helper('fhc'); // Set the default widget path with APPPATH - $this->_widget_path = APPPATH . 'widgets/'; + $this->_widget_path = APPPATH.'widgets/'; // Loads widgets to render HTML elements // NOTE: the first one to be loaded must be HTMLWidget @@ -72,10 +72,10 @@ class WidgetLib public function initialize($config = array()) { foreach ($config as $key => $val) - $this->{'_' . $key} = $val; + $this->{'_'.$key} = $val; if ($this->_widget_path == '') - $this->_widget_path = APPPATH . 'widgets/'; + $this->_widget_path = APPPATH.'widgets/'; if ($this->_parser && !class_exists('CI_Parser')) $this->_ci->load->library('parser'); @@ -126,28 +126,38 @@ class WidgetLib * @param string $template * @param array $data */ - public function publish($template = FALSE, $data = array()) { - if (is_array($template) || is_object($template)) { + public function publish($template = false, $data = array()) + { + if (is_array($template) || is_object($template)) + { $data = $template; - } else if ($template) { + } + else if ($template) + { $this->_template = $template; } - if (!$this->_template) { + if (!$this->_template) + { show_error('There was no template file selected for the current template'); } - if (is_array($data) || is_object($data)) { - foreach ($data as $name => $content) { + if (is_array($data) || is_object($data)) + { + foreach ($data as $name => $content) + { $this->partial($name)->set($content); } } unset($data); - if ($this->_parser) { + if ($this->_parser) + { $this->_ci->parser->parse($this->_template, $this->_partials); - } else { + } + else + { $this->_ci->load->view($this->_template, $this->_partials); } } @@ -159,25 +169,32 @@ class WidgetLib * @param string $default * @return Partial */ - public function partial($name, $default = FALSE) { - if ($this->exists($name)) { + public function partial($name, $default = false) + { + if ($this->exists($name)) + { $partial = $this->_partials[$name]; - } else { + } + else + { // create new partial $partial = new Partial($name); - if ($this->_cache_ttl) { + if ($this->_cache_ttl) + { $partial->cache($this->_cache_ttl); } // detect local triggers - if (method_exists($this, 'trigger_' . $name)) { - $partial->bind($this, 'trigger_' . $name); + if (method_exists($this, 'trigger_'.$name)) + { + $partial->bind($this, 'trigger_'.$name); } $this->_partials[$name] = $partial; } - if (!$partial->content() && $default) { + if (!$partial->content() && $default) + { $partial->set($default); } @@ -194,12 +211,12 @@ class WidgetLib */ public function widget($name, $data = array(), $htmlArgs = array()) { - // + // Loads the widget file, trying to find it also in the subdirectories loadResource($this->_widget_path, $name, true); if (!class_exists($name)) { - show_error("Widget '" . $name . "' was not found."); + show_error("Widget '".$name."' was not found."); } return new $name($name, $data, $htmlArgs); @@ -210,8 +227,10 @@ class WidgetLib * @param int $ttl * @param mixed $identifier */ - public function cache($ttl = 60, $identifier = '') { - foreach ($this->_partials as $partial) { + public function cache($ttl = 60, $identifier = '') + { + foreach ($this->_partials as $partial) + { $partial->cache($ttl, $identifier); } @@ -224,35 +243,44 @@ class WidgetLib * Stylesheet trigger * @param string $source */ - public function trigger_stylesheet($url, $attributes = FALSE) { + public function trigger_stylesheet($url, $attributes = false) + { // array support - if (is_array($url)) { + if (is_array($url)) + { $return = ''; - foreach ($url as $u) { + foreach ($url as $u) + { $return .= $this->trigger_stylesheet($u, $attributes); } return $return; } - if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') { - $url = $this->_ci->config->item('base_url') . $url; + if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') + { + $url = $this->_ci->config->item('base_url').$url; } // legacy support for media - if (is_string($attributes)) { + if (is_string($attributes)) + { $attributes = array('media' => $attributes); } - if (is_array($attributes)) { + if (is_array($attributes)) + { $attributeString = ""; - foreach ($attributes as $key => $value) { - $attributeString .= $key . '="' . $value . '" '; + foreach ($attributes as $key => $value) + { + $attributeString .= $key.'="'.$value.'" '; } - return '' . "\n\t"; - } else { - return '' . "\n\t"; + return ''."\n\t"; + } + else + { + return ''."\n\t"; } } @@ -260,21 +288,25 @@ class WidgetLib * Javascript trigger * @param string $source */ - public function trigger_javascript($url) { + public function trigger_javascript($url) + { // array support - if (is_array($url)) { + if (is_array($url)) + { $return = ''; - foreach ($url as $u) { + foreach ($url as $u) + { $return .= $this->trigger_javascript($u); } return $return; } - if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') { - $url = $this->_ci->config->item('base_url') . $url; + if (!stristr($url, 'http://') && !stristr($url, 'https://') && substr($url, 0, 2) != '//') + { + $url = $this->_ci->config->item('base_url').$url; } - return '' . "\n\t"; + return ''."\n\t"; } /** @@ -283,20 +315,23 @@ class WidgetLib * @param mixed $value * @param enum $type */ - public function trigger_meta($name, $value, $type = 'meta') { + public function trigger_meta($name, $value, $type = 'meta') + { $name = htmlspecialchars(strip_tags($name)); $value = htmlspecialchars(strip_tags($value)); - if ($name == 'keywords' and !strpos($value, ',')) { + if ($name == 'keywords' and !strpos($value, ',')) + { $content = preg_replace('/[\s]+/', ', ', trim($value)); } - switch ($type) { + switch ($type) + { case 'meta' : - $content = '' . "\n\t"; + $content = ''."\n\t"; break; case 'link' : - $content = '' . "\n\t"; + $content = ''."\n\t"; break; } @@ -309,7 +344,8 @@ class WidgetLib * @param mixed $value * @param enum $type */ - public function trigger_title($title) { + public function trigger_title($title) + { return htmlspecialchars(strip_tags($title)); } @@ -319,7 +355,8 @@ class WidgetLib * @param mixed $value * @param enum $type */ - public function trigger_description($description) { + public function trigger_description($description) + { return htmlspecialchars(strip_tags($description)); } @@ -346,15 +383,18 @@ class Partial * This will be handy in extending classes * @param string $index */ - function __get($name) { + function __get($name) + { return $this->_ci->$name; } /** * Alias methods */ - function __call($name, $args) { - switch ($name) { + function __call($name, $args) + { + switch ($name) + { case 'default' : return call_user_func_array(array($this, 'set_default'), $args); break; @@ -368,7 +408,8 @@ class Partial * Returns the content when converted to a string * @return string */ - public function __toString() { + public function __toString() + { return (string) $this->content(); } @@ -376,8 +417,10 @@ class Partial * Returns the content * @return string */ - public function content() { - if ($this->_cache_ttl && !$this->_cached) { + public function content() + { + if ($this->_cache_ttl && !$this->_cached) + { $this->cache->save($this->cache_id(), $this->_content, $this->_cache_ttl); } @@ -389,8 +432,10 @@ class Partial * @param mixed $content * @return Partial */ - public function set() { - if (!$this->_cached) { + public function set() + { + if (!$this->_cached) + { $this->_content = (string) $this->trigger(func_get_args()); } @@ -402,8 +447,10 @@ class Partial * @param mixed $content * @return Partial */ - public function append() { - if (!$this->_cached) { + public function append() + { + if (!$this->_cached) + { $this->_content .= (string) $this->trigger(func_get_args()); } @@ -415,9 +462,11 @@ class Partial * @param mixed $content * @return Partial */ - public function prepend() { - if (!$this->_cached) { - $this->_content = (string) $this->trigger(func_get_args()) . $this->_content; + public function prepend() + { + if (!$this->_cached) + { + $this->_content = (string) $this->trigger(func_get_args()).$this->_content; } return $this; @@ -428,9 +477,12 @@ class Partial * @param mixed $default * @return Partial */ - public function set_default($default) { - if (!$this->_cached) { - if (!$this->_content) { + public function set_default($default) + { + if (!$this->_cached) + { + if (!$this->_content) + { $this->_content = $default; } } @@ -445,13 +497,16 @@ class Partial * @param bool $overwrite * @return Partial */ - public function view($view, $data = array(), $overwrite = false) { - if (!$this->_cached) { - + public function view($view, $data = array(), $overwrite = false) + { + if (!$this->_cached) + { // better object to array - if (is_object($data)) { + if (is_object($data)) + { $array = array(); - foreach ($data as $k => $v) { + foreach ($data as $k => $v) + { $array[$k] = $v; } $data = $array; @@ -459,9 +514,12 @@ class Partial $content = $this->_ci->load->view($view, $data, true); - if ($overwrite) { + if ($overwrite) + { $this->set($content); - } else { + } + else + { $this->append($content); } } @@ -475,16 +533,21 @@ class Partial * @param bool $overwrite * @return Partial */ - public function parse($view, $data = array(), $overwrite = false) { - if (!$this->_cached) { - if (!class_exists('CI_Parser')) { + public function parse($view, $data = array(), $overwrite = false) + { + if (!$this->_cached) + { + if (!class_exists('CI_Parser')) + { $this->_ci->load->library('parser'); } // better object to array - if (is_object($data)) { + if (is_object($data)) + { $array = array(); - foreach ($data as $k => $v) { + foreach ($data as $k => $v) + { $array[$k] = $v; } $data = $array; @@ -492,9 +555,12 @@ class Partial $content = $this->_ci->parser->parse($view, $data, true); - if ($overwrite) { + if ($overwrite) + { $this->set($content); - } else { + } + else + { $this->append($content); } } @@ -509,13 +575,18 @@ class Partial * @param bool $overwrite * @return Partial */ - public function widget($name, $data = array(), $overwrite = false) { - if (!$this->_cached) { + public function widget($name, $data = array(), $overwrite = false) + { + if (!$this->_cached) + { $widget = $this->template->widget($name, $data); - if ($overwrite) { + if ($overwrite) + { $this->set($widget->content()); - } else { + } + else + { $this->append($widget->content()); } } @@ -527,15 +598,18 @@ class Partial * @param int $ttl * @param mixed $identifier */ - public function cache($ttl = 60, $identifier = '') { - if (!class_exists('CI_Cache')) { + public function cache($ttl = 60, $identifier = '') + { + if (!class_exists('CI_Cache')) + { $this->_ci->load->driver('cache', array('adapter' => 'file')); } $this->_cache_ttl = $ttl; $this->_identifier = $identifier; - if ($cached = $this->_ci->cache->get($this->cache_id())) { + if ($cached = $this->_ci->cache->get($this->cache_id())) + { $this->_cached = true; $this->_content = $cached; } @@ -546,11 +620,15 @@ class Partial * Used for cache identification * @return string */ - private function cache_id() { - if ($this->_identifier) { - return $this->_name . '_' . $this->_identifier . '_' . md5(get_class($this) . implode('', $this->_args)); - } else { - return $this->_name . '_' . md5(get_class($this) . implode('', $this->_args)); + private function cache_id() + { + if ($this->_identifier) + { + return $this->_name.'_'.$this->_identifier.'_'.md5(get_class($this).implode('', $this->_args)); + } + else + { + return $this->_name.'_'.md5(get_class($this).implode('', $this->_args)); } } @@ -559,10 +637,14 @@ class Partial * @param array $args * @return string */ - public function trigger($args) { - if (!$this->_trigger) { + public function trigger($args) + { + if (!$this->_trigger) + { return implode('', $args); - } else { + } + else + { return call_user_func_array($this->_trigger, $args); } } @@ -572,24 +654,32 @@ class Partial * Can be used like bind($this, "function") or bind("function") * @param mixed $arg */ - public function bind() { - if ($count = func_num_args()) { - if ($count >= 2) { + public function bind() + { + if ($count = func_num_args()) + { + if ($count >= 2) + { $args = func_get_args(); $obj = array_shift($args); $func = array_pop($args); - foreach ($args as $trigger) { + foreach ($args as $trigger) + { $obj = $obj->$trigger; } $this->_trigger = array($obj, $func); - } else { + } + else + { $args = func_get_args(); $this->_trigger = reset($args); } - } else { - $this->_trigger = FALSE; + } + else + { + $this->_trigger = false; } } } diff --git a/application/models/system/MessageToken_model.php b/application/models/system/MessageToken_model.php index 331039a7b..6d808e792 100755 --- a/application/models/system/MessageToken_model.php +++ b/application/models/system/MessageToken_model.php @@ -61,7 +61,7 @@ class MessageToken_model extends CI_Model /** * Set the status of a message to read. If the status of the message - * is already read, than update updateamum + * is already read then update updateamum */ public function setReadMessageStatusByToken($token) { diff --git a/application/views/widgets/checkbox.php b/application/views/widgets/checkbox.php index 50832b134..6debb2afd 100644 --- a/application/views/widgets/checkbox.php +++ b/application/views/widgets/checkbox.php @@ -23,7 +23,6 @@ - - + > diff --git a/application/views/widgets/textarea.php b/application/views/widgets/textarea.php index 6866c17a5..c72b52658 100644 --- a/application/views/widgets/textarea.php +++ b/application/views/widgets/textarea.php @@ -23,8 +23,10 @@ - + + + > diff --git a/application/views/widgets/textfield.php b/application/views/widgets/textfield.php index 0807f3ed1..73b1daa1b 100644 --- a/application/views/widgets/textfield.php +++ b/application/views/widgets/textfield.php @@ -23,8 +23,12 @@ - + + + + + value="" diff --git a/application/widgets/html/CheckboxWidget.php b/application/widgets/html/CheckboxWidget.php index 6a77f0d43..57a6e2a2c 100644 --- a/application/widgets/html/CheckboxWidget.php +++ b/application/widgets/html/CheckboxWidget.php @@ -11,9 +11,11 @@ class CheckboxWidget extends HTMLWidget const DESCRIPTION_FIELD = 'description'; // Value of value attribute of the checkbox const CHECKBOX_VALUE = 'true'; + // Default checkbox value + const HTML_DEFAULT_VALUE = false; /** - * + * Loads the view that renders a checkbox */ protected function loadCheckboxView() { diff --git a/application/widgets/html/DropdownWidget.php b/application/widgets/html/DropdownWidget.php index 63e1b414d..bc615d30f 100644 --- a/application/widgets/html/DropdownWidget.php +++ b/application/widgets/html/DropdownWidget.php @@ -15,11 +15,11 @@ class DropdownWidget extends HTMLWidget // 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'; - // + // Default HTML value const HTML_DEFAULT_VALUE = 'null'; - const SIZE = 'size'; // - const MULTIPLE = 'multiple'; // + const SIZE = 'size'; // size of the dropdown + const MULTIPLE = 'multiple'; // multiple attribute /** * @@ -28,31 +28,36 @@ class DropdownWidget extends HTMLWidget { parent::__construct($name, $args, $htmlArgs); - // + // If the selectd element is not set then set it to HTML_DEFAULT_VALUE if (!isset($this->_args[DropdownWidget::SELECTED_ELEMENT])) { $this->_args[DropdownWidget::SELECTED_ELEMENT] = DropdownWidget::HTML_DEFAULT_VALUE; } + + // By default is not a multiple dropdown + unset($this->htmlParameters[DropdownWidget::MULTIPLE]); } /** - * + * Set this dropdown as multiple: + * - Setting the multiple attribute + * - Adding square brackets to the name */ public function setMultiple() { - $this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE; - $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] .= '[]'; + $this->htmlParameters[DropdownWidget::MULTIPLE] = DropdownWidget::MULTIPLE; + $this->htmlParameters[HTMLWidget::HTML_NAME] .= '[]'; } /** - * + * Checks if this object is a multiple dropdown */ public function isMultipleDropdown() { $isMultipleDropdown = false; - if (isset($this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE]) - && $this->_args[HTMLWidget::HTML_ARG_NAME][DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE) + if (isset($this->htmlParameters[DropdownWidget::MULTIPLE]) + && $this->htmlParameters[DropdownWidget::MULTIPLE] == DropdownWidget::MULTIPLE) { $isMultipleDropdown = true; } diff --git a/application/widgets/html/HTMLWidget.php b/application/widgets/html/HTMLWidget.php index 04f5d4d5f..7cb073ea8 100644 --- a/application/widgets/html/HTMLWidget.php +++ b/application/widgets/html/HTMLWidget.php @@ -11,22 +11,25 @@ class HTMLWidget extends Widget const HTML_NAME = 'name'; // HTML name attribute const HTML_ID = 'id'; // HTML id attribute - // - const EXTERNAL_BLOCK = 'externalBlock'; // - const EXTERNAL_START_BLOCK_HTML_TAG = '
'; // - const EXTERNAL_END_BLOCK_HTML_TAG = '
'; // + // External block definition + const EXTERNAL_BLOCK = 'externalBlock'; // External block name + const EXTERNAL_START_BLOCK_HTML_TAG = '
'; // External block start tag + const EXTERNAL_END_BLOCK_HTML_TAG = '
'; // External block end tag - // + // HTML attributes const LABEL = 'title'; const REGEX = 'regex'; const TITLE = 'description'; - const REQUIRED = 'udf-required'; + const REQUIRED = 'required-field'; const MAX_VALUE = 'max-value'; const MIN_VALUE = 'min-value'; const MAX_LENGTH = 'max-length'; const MIN_LENGTH = 'min-length'; const PLACEHOLDER = 'placeholder'; + // Alias of $this->_args[HTMLWidget::HTML_ARG_NAME] for a better code readability + protected $htmlParameters; + /** * It gets also the htmlArgs array as parameter, it will be used to set the HTML properties */ @@ -61,10 +64,13 @@ class HTMLWidget extends Widget $this->_args[HTMLWidget::HTML_ARG_NAME][$argName] = $argValue; } } + + $this->htmlParameters =& $this->_args[HTMLWidget::HTML_ARG_NAME]; // Reference for a better code readability } /** - * + * Prints an attribute name and eventually also the value extracted from $htmlArgs + * Set $isValuePresent to false the value should not be displayed */ public static function printAttribute($htmlArgs, $attribute, $isValuePresent = true) { @@ -92,7 +98,7 @@ class HTMLWidget extends Widget } /** - * + * Prints the external block start tag */ public static function printStartBlock($htmlArgs) { @@ -104,7 +110,7 @@ class HTMLWidget extends Widget } /** - * + * Prints the external block end tag */ public static function printEndBlock($htmlArgs) { diff --git a/application/widgets/html/TextareaWidget.php b/application/widgets/html/TextareaWidget.php index ffb9e538d..b98c21b25 100644 --- a/application/widgets/html/TextareaWidget.php +++ b/application/widgets/html/TextareaWidget.php @@ -5,12 +5,12 @@ */ class TextareaWidget extends HTMLWidget { - const TEXT = 'text'; // - const ROWS = 'rows'; // - const COLS = 'cols'; // + const TEXT = 'text'; // Text value + const ROWS = 'rows'; // Rows attribute + const COLS = 'cols'; // Cols attribute /** - * + * Set the text value */ protected function setText($text) { @@ -18,7 +18,7 @@ class TextareaWidget extends HTMLWidget } /** - * + * Loads the view that renders a text area */ protected function loadTextareaView() { diff --git a/application/widgets/html/TextfieldWidget.php b/application/widgets/html/TextfieldWidget.php index e5ad146c9..5468499e3 100644 --- a/application/widgets/html/TextfieldWidget.php +++ b/application/widgets/html/TextfieldWidget.php @@ -5,11 +5,11 @@ */ class TextfieldWidget extends HTMLWidget { - const VALUE = 'text'; // - const SIZE = 'size'; // + const VALUE = 'text'; // Text value + const SIZE = 'size'; // Size attribute /** - * + * Set the text value */ protected function setValue($value) { @@ -17,7 +17,7 @@ class TextfieldWidget extends HTMLWidget } /** - * + * Loads the view that renders an input text */ protected function loadTextfieldView() { diff --git a/application/widgets/udf/CheckboxWidgetUDF.php b/application/widgets/udf/CheckboxWidgetUDF.php index 096a7a737..7a71c8743 100644 --- a/application/widgets/udf/CheckboxWidgetUDF.php +++ b/application/widgets/udf/CheckboxWidgetUDF.php @@ -1,12 +1,12 @@ content() is needed */ public function render() { diff --git a/application/widgets/udf/DropdownWidgetUDF.php b/application/widgets/udf/DropdownWidgetUDF.php index 46a3f9733..04552e953 100644 --- a/application/widgets/udf/DropdownWidgetUDF.php +++ b/application/widgets/udf/DropdownWidgetUDF.php @@ -1,53 +1,60 @@ content() is needed */ public function render($parameters) { - $tmpElements = array(); + // Array that will contains the elements to be displayed in the dropdown + $tmpNewElements = array(); - // + // Loops through the given parameters foreach($parameters as $parameter) { - // + // Every single element of the array is checked, and it could only be: + // - An array with two elements OR + // - A string or a number OR + // - An object with two properties: id and description if ((is_array($parameter) && count($parameter) == 2) || (is_string($parameter) || is_numeric($parameter)) - || (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD}))) + || (is_object($parameter) && isset($parameter->{DropdownWidget::ID_FIELD}) + && isset($parameter->{DropdownWidget::DESCRIPTION_FIELD}))) { - $element = new stdClass(); // - // + $newElement = new stdClass(); // New single element + // If the single element is an array of two element if (is_array($parameter) && count($parameter) == 2) { - $element->{PARENT::ID_FIELD} = $parameter[0]; // - $element->{PARENT::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)) { - $element->{PARENT::ID_FIELD} = $parameter; // - $element->{PARENT::DESCRIPTION_FIELD} = $parameter; // + $newElement->{DropdownWidget::ID_FIELD} = $parameter; // + $newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter; // } - // - else if (is_object($parameter) && isset($parameter->{PARENT::ID_FIELD}) && isset($parameter->{PARENT::DESCRIPTION_FIELD})) + // 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})) { - $element->{PARENT::ID_FIELD} = $parameter->{PARENT::ID_FIELD}; // - $element->{PARENT::DESCRIPTION_FIELD} = $parameter->{PARENT::DESCRIPTION_FIELD}; // + $newElement->{DropdownWidget::ID_FIELD} = $parameter->{DropdownWidget::ID_FIELD}; // + $newElement->{DropdownWidget::DESCRIPTION_FIELD} = $parameter->{DropdownWidget::DESCRIPTION_FIELD}; // } - array_push($tmpElements, $element); // + array_push($tmpNewElements, $newElement); // Add $newElement into $tmpNewElements } } + // Set the list of elements $this->setElementsArray( - success($tmpElements), + success($tmpNewElements), true, - $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::PLACEHOLDER], + $this->htmlParameters[HTMLWidget::PLACEHOLDER], 'No data found for this UDF' ); diff --git a/application/widgets/udf/TextareaWidgetUDF.php b/application/widgets/udf/TextareaWidgetUDF.php index d64015190..8fa3ace53 100644 --- a/application/widgets/udf/TextareaWidgetUDF.php +++ b/application/widgets/udf/TextareaWidgetUDF.php @@ -1,12 +1,12 @@ content() is needed */ public function render($parameters) { diff --git a/application/widgets/udf/TextfieldWidgetUDF.php b/application/widgets/udf/TextfieldWidgetUDF.php index 2d78b0d1a..7ad9214f8 100644 --- a/application/widgets/udf/TextfieldWidgetUDF.php +++ b/application/widgets/udf/TextfieldWidgetUDF.php @@ -1,12 +1,12 @@ content() is needed */ public function render($parameters) { diff --git a/application/widgets/udf/UDFWidget.php b/application/widgets/udf/UDFWidget.php index 9168c86da..830aadb6b 100644 --- a/application/widgets/udf/UDFWidget.php +++ b/application/widgets/udf/UDFWidget.php @@ -1,79 +1,76 @@ _loadUDF($schema, $table); + $udfResults = $this->_loadUDF($schema, $table); // loads UDF definition if (hasData($udfResults)) { - $udf = $udfResults->retval[0]; + $udf = $udfResults->retval[0]; // only one record is loaded if (isset($udf->jsons)) { - $jsonSchemas = json_decode($udf->jsons); + $jsonSchemas = json_decode($udf->jsons); // decode the json schema if (is_object($jsonSchemas) || is_array($jsonSchemas)) { - // + // If the schema is an object then convert it into an array if (is_object($jsonSchemas)) { $jsonSchemasArray = array($jsonSchemas); } - else + else // keep it as it is { $jsonSchemasArray = $jsonSchemas; } - $found = false; // + $found = false; // used to check if the field is found or not in the json schema - $this->_sortJsonSchemas($jsonSchemasArray); // + $this->_sortJsonSchemas($jsonSchemasArray); // Sort the list of UDF by sort property - // + // Loops through json schemas foreach($jsonSchemasArray as $jsonSchema) { - // - if (!isset($jsonSchema->{UDFWidget::TYPE})) + // If the type property is not present then show an error + if (!isset($jsonSchema->{UDFLib::TYPE})) { show_error(sprintf('%s.%s: Attribute "type" not present in the json schema', $schema, $table)); break; } - if (!isset($jsonSchema->{UDFWidget::NAME})) + // If the name property is not present then show an error + if (!isset($jsonSchema->{UDFLib::NAME})) { show_error(sprintf('%s.%s: Attribute "name" not present in the json schema', $schema, $table)); break; } - // - if ((isset($field) && $field == $jsonSchema->{UDFWidget::NAME}) || !isset($field)) + // 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)) { - $this->_setAttributesWithPhrases($jsonSchema); + $this->_setAttributesWithPhrases($jsonSchema); // Set attributes using phrases - $this->_setValidationAttributes($jsonSchema); + $this->_setValidationAttributes($jsonSchema); // Set validation attributes - $this->_setNameAndId($jsonSchema); + $this->_setNameAndId($jsonSchema); // Set name and id attributes - $this->_render($jsonSchema); + $this->_render($jsonSchema); // Render the HTML for this UDF - // - if (isset($field) && $field == $jsonSchema->{UDFWidget::NAME}) + // If a UDf is specified and it was found then stop looking through this list + if (isset($field) && $field == $jsonSchema->{UDFLib::NAME}) { $found = true; break; @@ -81,18 +78,18 @@ class UDFWidget extends HTMLWidget } } - // + // If a UDf is specified and it was not found then show an error if (isset($field) && !$found) { show_error(sprintf('%s.%s: No schema present for field: %s', $schema, $table, $field)); } } - else + else // not a valid schema { show_error(sprintf('%s.%s: Not a valid json schema', $schema, $table)); } } - else + else // no json column present in table tbl_udf { show_error(sprintf('%s.%s: Does not contain "jsons" field', $schema, $table)); } @@ -100,42 +97,42 @@ class UDFWidget extends HTMLWidget } /** - * + * Set the name and id attribute of the HTML element */ private function _setNameAndId($jsonSchema) { - $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_ID] = $jsonSchema->{UDFWidget::NAME}; - $this->_args[HTMLWidget::HTML_ARG_NAME][HTMLWidget::HTML_NAME] = $jsonSchema->{UDFWidget::NAME}; + $this->htmlParameters[HTMLWidget::HTML_ID] = $jsonSchema->{UDFLib::NAME}; + $this->htmlParameters[HTMLWidget::HTML_NAME] = $jsonSchema->{UDFLib::NAME}; } /** - * + * Sort the list of UDF by sort property */ private function _sortJsonSchemas(&$jsonSchemasArray) { // usort($jsonSchemasArray, function ($a, $b) { // - if (!isset($a->sort)) + if (!isset($a->{UDFLib::SORT})) { - $a->sort = 9999; + $a->{UDFLib::SORT} = 9999; } - if (!isset($b->sort)) + if (!isset($b->{UDFLib::SORT})) { - $b->sort = 9999; + $b->{UDFLib::SORT} = 9999; } - if ($a->sort == $b->sort) + if ($a->{UDFLib::SORT} == $b->{UDFLib::SORT}) { return 0; } - return ($a->sort < $b->sort) ? -1 : 1; + return ($a->{UDFLib::SORT} < $b->{UDFLib::SORT}) ? -1 : 1; }); } /** - * + * Loads the UDF description by the given schema and table */ private function _loadUDF($schema, $table) { @@ -173,46 +170,52 @@ class UDFWidget extends HTMLWidget } /** - * + * Render the HTML for the UDF */ private function _render($jsonSchema) { - // Type - if ($jsonSchema->{UDFWidget::TYPE} == 'checkbox') + // Checkbox + if ($jsonSchema->{UDFLib::TYPE} == 'checkbox') { $this->_renderCheckbox($jsonSchema); } - else if ($jsonSchema->{UDFWidget::TYPE} == 'textfield') + // Textfield + else if ($jsonSchema->{UDFLib::TYPE} == 'textfield') { $this->_renderTextfield($jsonSchema); } - else if ($jsonSchema->{UDFWidget::TYPE} == 'textarea') + // Textarea + else if ($jsonSchema->{UDFLib::TYPE} == 'textarea') { $this->_renderTextarea($jsonSchema); } - else if ($jsonSchema->{UDFWidget::TYPE} == 'date') + // Date + else if ($jsonSchema->{UDFLib::TYPE} == 'date') { } - else if ($jsonSchema->{UDFWidget::TYPE} == 'dropdown') + // Dropdown + else if ($jsonSchema->{UDFLib::TYPE} == 'dropdown') { $this->_renderDropdown($jsonSchema); } - else if ($jsonSchema->{UDFWidget::TYPE} == 'multipledropdown') + // Multiple dropdown + else if ($jsonSchema->{UDFLib::TYPE} == 'multipledropdown') { $this->_renderDropdown($jsonSchema, true); } } /** - * + * Renders a dropdown element */ private function _renderDropdown($jsonSchema, $multiple = false) { + // Selected element/s if (isset($this->_args[UDFLib::UDFS_ARG_NAME]) - && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}])) + && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}])) { - $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]; + $this->_args[DropdownWidget::SELECTED_ELEMENT] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]; } else { @@ -222,22 +225,22 @@ class UDFWidget extends HTMLWidget $dropdownWidgetUDF = new DropdownWidgetUDF($this->_name, $this->_args); $parameters = array(); - // - if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->enum)) + // If the list of values to show is an array + if (isset($jsonSchema->{UDFLib::LIST_VALUES}->enum)) { - $parameters = $jsonSchema->{UDFWidget::LIST_VALUES}->enum; + $parameters = $jsonSchema->{UDFLib::LIST_VALUES}->enum; } - // - else if (isset($jsonSchema->{UDFWidget::LIST_VALUES}->sql)) + // If the list of values to show should be retrived with a SQL statement + else if (isset($jsonSchema->{UDFLib::LIST_VALUES}->sql)) { - $queryResult = $this->UDFModel->execQuery($jsonSchema->{UDFWidget::LIST_VALUES}->sql); + $queryResult = $this->UDFModel->execQuery($jsonSchema->{UDFLib::LIST_VALUES}->sql); if (hasData($queryResult)) { $parameters = $queryResult->retval; } } - if ($multiple) + if ($multiple) // multiple dropdown { $dropdownWidgetUDF->setMultiple(); } @@ -246,52 +249,55 @@ class UDFWidget extends HTMLWidget } /** - * + * Renders a textarea element */ private function _renderTextarea($jsonSchema) { + $text = null; // text value $textareaUDF = new TextareaWidgetUDF($this->_name, $this->_args); - $text = null; + // Set text value if present in the DB if (isset($this->_args[UDFLib::UDFS_ARG_NAME]) - && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}])) + && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}])) { - $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]; + $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]; } $textareaUDF->render($text); } /** - * + * Renders an input text element */ private function _renderTextfield($jsonSchema) { + $text = null; // text value $textareaUDF = new TextfieldWidgetUDF($this->_name, $this->_args); - $text = null; + // Set text value if present in the DB if (isset($this->_args[UDFLib::UDFS_ARG_NAME]) - && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}])) + && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}])) { - $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]; + $text = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]; } $textareaUDF->render($text); } /** - * + * Renders a checkbox element */ private function _renderCheckbox($jsonSchema) { + // Set checkbox value if present in the DB if (isset($this->_args[UDFLib::UDFS_ARG_NAME]) - && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}])) + && isset($this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}])) { - $this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFWidget::NAME}]; + $this->_args[CheckboxWidget::VALUE_FIELD] = $this->_args[UDFLib::UDFS_ARG_NAME][$jsonSchema->{UDFLib::NAME}]; } else { - $this->_args[CheckboxWidget::VALUE_FIELD] = HTMLWidget::HTML_DEFAULT_VALUE; + $this->_args[CheckboxWidget::VALUE_FIELD] = CheckboxWidget::HTML_DEFAULT_VALUE; } $checkboxWidgetUDF = new CheckboxWidgetUDF($this->_name, $this->_args); @@ -300,7 +306,7 @@ class UDFWidget extends HTMLWidget } /** - * + * Sets the attributes of the HTML element using the phrases system */ private function _setAttributesWithPhrases($jsonSchema) { @@ -309,14 +315,15 @@ class UDFWidget extends HTMLWidget || isset($jsonSchema->{UDFLib::TITLE}) || isset($jsonSchema->{UDFLib::PLACEHOLDER})) { - // + // Loads PhrasesLib $this->_ci->load->library('PhrasesLib'); - // + // If is set the label property in the json schema if (isset($jsonSchema->{UDFLib::LABEL})) { + // Load the related phrase $tmpResult = $this->_ci->phraseslib->getPhrases( - UDFWidget::PHRASES_APP_NAME, + UDFLib::PHRASES_APP_NAME, DEFAULT_LEHREINHEIT_SPRACHE, $jsonSchema->{UDFLib::LABEL}, null, @@ -325,19 +332,20 @@ class UDFWidget extends HTMLWidget ); if (hasData($tmpResult)) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = $tmpResult->retval[0]->text; + $this->htmlParameters[HTMLWidget::LABEL] = $tmpResult->retval[0]->text; } else { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::LABEL] = null; + $this->htmlParameters[HTMLWidget::LABEL] = null; } } - // + // If is set the title property in the json schema if (isset($jsonSchema->{UDFLib::TITLE})) { + // Load the related phrase $tmpResult = $this->_ci->phraseslib->getPhrases( - UDFWidget::PHRASES_APP_NAME, + UDFLib::PHRASES_APP_NAME, DEFAULT_LEHREINHEIT_SPRACHE, $jsonSchema->{UDFLib::TITLE}, null, @@ -346,19 +354,20 @@ class UDFWidget extends HTMLWidget ); if (hasData($tmpResult)) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = $tmpResult->retval[0]->text; + $this->htmlParameters[HTMLWidget::TITLE] = $tmpResult->retval[0]->text; } else { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::TITLE] = null; + $this->htmlParameters[HTMLWidget::TITLE] = null; } } - // + // If is set the placeholder property in the json schema if (isset($jsonSchema->{UDFLib::PLACEHOLDER})) { + // Load the related phrase $tmpResult = $this->_ci->phraseslib->getPhrases( - UDFWidget::PHRASES_APP_NAME, + UDFLib::PHRASES_APP_NAME, DEFAULT_LEHREINHEIT_SPRACHE, $jsonSchema->{UDFLib::PLACEHOLDER}, null, @@ -367,54 +376,73 @@ class UDFWidget extends HTMLWidget ); if (hasData($tmpResult)) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = $tmpResult->retval[0]->text; + $this->htmlParameters[HTMLWidget::PLACEHOLDER] = $tmpResult->retval[0]->text; } else { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::PLACEHOLDER] = null; + $this->htmlParameters[HTMLWidget::PLACEHOLDER] = null; } } } } /** - * + * Sets the validation attributes of the HTML element using the configuration inside the json schema */ private function _setValidationAttributes($jsonSchema) { - // Validation - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = null; - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = null; - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = null; - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = null; + // Validation attributes set by default to null + $this->htmlParameters[HTMLWidget::REGEX] = null; + $this->htmlParameters[HTMLWidget::REQUIRED] = null; + $this->htmlParameters[HTMLWidget::MIN_VALUE] = null; + $this->htmlParameters[HTMLWidget::MAX_VALUE] = null; - if (isset($jsonSchema->validation)) + // If validation property is present in the json schema + if (isset($jsonSchema->{UDFLib::VALIDATION})) { - if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX}) - && is_array($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX})) + $jsonSchemaValidation =& $jsonSchema->{UDFLib::VALIDATION}; // Reference for a better code readability + + // Front end regex + if (isset($jsonSchemaValidation->{UDFLib::REGEX}) + && is_array($jsonSchemaValidation->{UDFLib::REGEX})) { - foreach($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REGEX} as $regex) + foreach($jsonSchemaValidation->{UDFLib::REGEX} as $regex) { - if ($regex->language === UDFWidget::REGEX_LANGUAGE) + if ($regex->language === UDFLib::FE_REGEX_LANGUAGE) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::REGEX] = $regex->expression; + $this->htmlParameters[HTMLWidget::REGEX] = $regex->expression; } } } - if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED})) + // Required + if (isset($jsonSchemaValidation->{UDFLib::REQUIRED})) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFWidget::REQUIRED] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::REQUIRED}; + $this->htmlParameters[HTMLWidget::REQUIRED] = $jsonSchemaValidation->{UDFLib::REQUIRED}; } - if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE})) + // Min value + if (isset($jsonSchemaValidation->{UDFLib::MIN_VALUE})) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MAX_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MAX_VALUE}; + $this->htmlParameters[HTMLWidget::MIN_VALUE] = $jsonSchemaValidation->{UDFLib::MIN_VALUE}; } - if (isset($jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE})) + // Max value + if (isset($jsonSchemaValidation->{UDFLib::MAX_VALUE})) { - $this->_args[HTMLWidget::HTML_ARG_NAME][UDFLib::MIN_VALUE] = $jsonSchema->{UDFWidget::VALIDATION}->{UDFLib::MIN_VALUE}; + $this->htmlParameters[HTMLWidget::MAX_VALUE] = $jsonSchemaValidation->{UDFLib::MAX_VALUE}; + } + + // Min length + if (isset($jsonSchemaValidation->{UDFLib::MIN_LENGTH})) + { + $this->htmlParameters[HTMLWidget::MIN_LENGTH] = $jsonSchemaValidation->{UDFLib::MIN_LENGTH}; + } + + // Max length + if (isset($jsonSchemaValidation->{UDFLib::MAX_LENGTH})) + { + $this->htmlParameters[HTMLWidget::MAX_LENGTH] = $jsonSchemaValidation->{UDFLib::MAX_LENGTH}; } } } diff --git a/skin/widgets.css b/skin/widgets.css index d0f2f5299..91b0b6889 100644 --- a/skin/widgets.css +++ b/skin/widgets.css @@ -14,7 +14,7 @@ display: table-cell; } -label[udf-required=true]::after { +label[required-field=true]::after { content: "*"; }