From 994c4e1d36d4634d4c298113e4334c7cef8b0a35 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 28 Jul 2017 17:21:01 +0200 Subject: [PATCH] If a UDF is of type checkbox, convert the string value to a boolean --- application/core/DB_Model.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 7fd1c04ee..ae9853364 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -23,6 +23,8 @@ class DB_Model extends FHC_Model const UDF_FIELD_TYPE = 'jsonb'; const UDF_FIELD_PREFIX = 'udf_'; const UDF_ATTRIBUTE_NAME = 'name'; + const UDF_TYPE_NAME = 'type'; + const UDF_CHKBOX_TYPE = 'checkbox'; const UDF_FIELD_JSON_DESCRIPTION = 'jsons'; // UDF validation attributes @@ -34,6 +36,9 @@ class DB_Model extends FHC_Model const UDF_MAX_LENGTH = 'max-length'; const UDF_MIN_LENGTH = 'min-length'; + const STRING_TRUE = 'true'; + const STRING_FALSE = 'false'; + protected $dbTable; // Name of the DB-Table for CI-Insert, -Update, ... protected $pk; // Name of the PrimaryKey for DB-Update, Load, ... protected $hasSequence; // False if this table has a composite primary key that is not using a sequence @@ -1032,6 +1037,14 @@ class DB_Model extends FHC_Model // If validation is ok copy the value that is to be stored into $toBeStoredUDFsArray if (isSuccess($validate)) { + // If this UDF is a checkbox + if ($decodedUDFDefinition->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_CHKBOX_TYPE) + { + // Converts from string to boolean + if ($val == DB_Model::STRING_TRUE) $val = true; + else if ($val == DB_Model::STRING_FALSE) $val = false; + } + $toBeStoredUDFsArray[$key] = $val; } else // otherwise store the validation error in $notValidUDFsArray