From 59045e11368d9f71fea0d70aa6b60384d54a16f0 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 28 Jul 2017 18:36:08 +0200 Subject: [PATCH] Added private method _fillMissingChkboxUDF to UDF_model. It checks if UDF checkboxes are NOT posted and sets theirs values to false --- application/core/DB_Model.php | 1 + application/models/system/UDF_model.php | 31 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index ae9853364..c24d695a3 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -36,6 +36,7 @@ class DB_Model extends FHC_Model const UDF_MAX_LENGTH = 'max-length'; const UDF_MIN_LENGTH = 'min-length'; + // String values of booleans const STRING_TRUE = 'true'; const STRING_FALSE = 'false'; diff --git a/application/models/system/UDF_model.php b/application/models/system/UDF_model.php index 537dacd10..c5aec0b52 100644 --- a/application/models/system/UDF_model.php +++ b/application/models/system/UDF_model.php @@ -61,6 +61,8 @@ class UDF_model extends DB_Model // Load model Person_model $this->load->model('person/Person_model', 'PersonModel'); + $udfs = $this->_fillMissingChkboxUDF($udfs, 'public', 'tbl_person'); + $resultPerson = $this->PersonModel->update($person_id, $udfs); } @@ -70,6 +72,8 @@ class UDF_model extends DB_Model // Load model Prestudent_model $this->load->model('crm/Prestudent_model', 'PrestudentModel'); + $udfs = $this->_fillMissingChkboxUDF($udfs, 'public', 'tbl_prestudent'); + $resultPrestudent = $this->PrestudentModel->update($prestudent_id, $udfs); } @@ -88,4 +92,31 @@ class UDF_model extends DB_Model return $result; } + + /** + * + */ + private function _fillMissingChkboxUDF($udfs, $schema, $table) + { + $_fillMissingChkboxUDF = $udfs; + + $result = $this->load(array($schema, $table)); + if (isSuccess($result) && count($result->retval) == 1) + { + $jsons = json_decode($result->retval[0]->jsons); + + foreach($jsons as $udfDescription) + { + if ($udfDescription->{DB_Model::UDF_TYPE_NAME} == DB_Model::UDF_CHKBOX_TYPE) + { + if (!isset($_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}])) + { + $_fillMissingChkboxUDF[$udfDescription->{DB_Model::UDF_ATTRIBUTE_NAME}] = DB_Model::STRING_FALSE; + } + } + } + } + + return $_fillMissingChkboxUDF; + } } \ No newline at end of file