- 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
This commit is contained in:
Paolo
2017-08-17 11:51:40 +02:00
parent 31e21acd67
commit e4160088e8
20 changed files with 478 additions and 293 deletions
+32 -21
View File
@@ -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);
+23
View File
@@ -1,5 +1,28 @@
<?php
/**
* FH-Complete
*
* @package FHC-Helper
* @author FHC-Team
* @copyright Copyright (c) 2016 fhcomplete.org
* @license GPLv3
* @since Version 1.0.0
*/
/**
* Message Helper
*
* @subpackage Helpers
* @category Helpers
*/
if (! defined('BASEPATH')) exit('No direct script access allowed');
// -------------------------------------------------------------------------------------------------------
// Collection of functions to handle successful and error messages that methods and functions can return
// -------------------------------------------------------------------------------------------------------
/**
* Success
*
+12 -4
View File
@@ -13,11 +13,18 @@ class UDFLib
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';
const DEFAULT_VALUE = 'defaultValue';
// Validation attributes
const REGEX = 'regex';
@@ -27,7 +34,9 @@ class UDFLib
const MAX_LENGTH = 'max-length';
const MIN_LENGTH = 'min-length';
private $_ci;
const PHRASES_APP_NAME = 'core'; // Name of the app parameter used to retrive phrases
private $_ci; // Code igniter instance
public function __construct($config = array())
{
@@ -38,8 +47,7 @@ class UDFLib
// Loads the widget library
$this->_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');
}
+190 -100
View File
@@ -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 '<link rel="stylesheet" href="' . htmlspecialchars(strip_tags($url)) . '" ' . $attributeString . '>' . "\n\t";
} else {
return '<link rel="stylesheet" href="' . htmlspecialchars(strip_tags($url)) . '">' . "\n\t";
return '<link rel="stylesheet" href="'.htmlspecialchars(strip_tags($url)).'" '.$attributeString.'>'."\n\t";
}
else
{
return '<link rel="stylesheet" href="'.htmlspecialchars(strip_tags($url)).'">'."\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 '<script src="' . htmlspecialchars(strip_tags($url)) . '"></script>' . "\n\t";
return '<script src="'.htmlspecialchars(strip_tags($url)).'"></script>'."\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 = '<meta name="' . $name . '" content="' . $value . '">' . "\n\t";
$content = '<meta name="'.$name.'" content="'.$value.'">'."\n\t";
break;
case 'link' :
$content = '<link rel="' . $name . '" href="' . $value . '">' . "\n\t";
$content = '<link rel="'.$name.'" href="'.$value.'">'."\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;
}
}
}
@@ -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)
{
-1
View File
@@ -23,7 +23,6 @@
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
<?php
$checked = '';
+1 -1
View File
@@ -29,8 +29,8 @@
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, DropdownWidget::SIZE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, DropdownWidget::MULTIPLE, false); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MIN_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
>
+3 -1
View File
@@ -23,8 +23,10 @@
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextareaWidget::ROWS); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextareaWidget::COLS); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::PLACEHOLDER); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MIN_LENGTH); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_LENGTH); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
><?php echo ${TextareaWidget::TEXT}; ?></textarea>
+5 -1
View File
@@ -23,8 +23,12 @@
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_ID); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::HTML_NAME); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, TextfieldWidget::SIZE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::PLACEHOLDER); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REQUIRED); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MIN_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_VALUE); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MIN_LENGTH); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::MAX_LENGTH); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::REGEX); ?>
<?php HTMLWidget::printAttribute(${HTMLWidget::HTML_ARG_NAME}, HTMLWidget::TITLE); ?>
value="<?php echo ${TextfieldWidget::VALUE}; ?>"
+3 -1
View File
@@ -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()
{
+15 -10
View File
@@ -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;
}
+15 -9
View File
@@ -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 = '<div>'; //
const EXTERNAL_END_BLOCK_HTML_TAG = '</div>'; //
// External block definition
const EXTERNAL_BLOCK = 'externalBlock'; // External block name
const EXTERNAL_START_BLOCK_HTML_TAG = '<div>'; // External block start tag
const EXTERNAL_END_BLOCK_HTML_TAG = '</div>'; // 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)
{
+5 -5
View File
@@ -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()
{
+4 -4
View File
@@ -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()
{
@@ -1,12 +1,12 @@
<?php
/**
*
* It exends the CheckboxWidget class to represent an HTML checkbox
*/
class CheckboxWidgetUDF extends CheckboxWidget
{
/**
*
* NOTE: echo $this->content() is needed
*/
public function render()
{
+27 -20
View File
@@ -1,53 +1,60 @@
<?php
/**
*
* It exends the DropdownWidget class to represent an HTML dropdown
*/
class DropdownWidgetUDF extends DropdownWidget
{
/**
*
* NOTE: echo $this->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'
);
@@ -1,12 +1,12 @@
<?php
/**
*
* It exends the TextareaWidget class to represent an HTML textarea
*/
class TextareaWidgetUDF extends TextareaWidget
{
/**
*
* NOTE: echo $this->content() is needed
*/
public function render($parameters)
{
@@ -1,12 +1,12 @@
<?php
/**
*
* It exends the TextfieldWidget class to represent an HTML input text
*/
class TextfieldWidgetUDF extends TextfieldWidget
{
/**
*
* NOTE: echo $this->content() is needed
*/
public function render($parameters)
{
+135 -107
View File
@@ -1,79 +1,76 @@
<?php
/**
*
* Represents a generic UDF element
* It's used to render the HTML of a UDF element using widgets
*/
class UDFWidget extends HTMLWidget
{
const NAME = 'name';
const TYPE = 'type';
const VALIDATION = 'validation';
const LIST_VALUES = 'listValues';
const REGEX_LANGUAGE = 'js';
const PHRASES_APP_NAME = 'core';
/**
* Called by the WidgetLib, it renders the HTML of the UDF
*/
public function display($widgetData)
{
$schema = $widgetData[UDFLib::SCHEMA_ARG_NAME];
$table = $widgetData[UDFLib::TABLE_ARG_NAME];
$schema = $widgetData[UDFLib::SCHEMA_ARG_NAME]; // schema attribute
$table = $widgetData[UDFLib::TABLE_ARG_NAME]; // table attribute
if (isset($widgetData[UDFLib::FIELD_ARG_NAME]))
{
$field = $widgetData[UDFLib::FIELD_ARG_NAME];
$field = $widgetData[UDFLib::FIELD_ARG_NAME]; // UDF name
}
$udfResults = $this->_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};
}
}
}
+1 -1
View File
@@ -14,7 +14,7 @@
display: table-cell;
}
label[udf-required=true]::after {
label[required-field=true]::after {
content: "*";
}