From b55d824e63b7fcedcc60dad8d3f62eb5ccf1c4c2 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sun, 28 Apr 2019 00:16:06 +0200 Subject: [PATCH] Resolved gh-379 to allow null and zero values to pass via ajax call/post --- README.md | 4 +- admin/README.txt | 4 +- admin/helpers/compiler/e_Interpretation.php | 50 ++++++++++++++----- .../en-GB/en-GB.com_componentbuilder.ini | 6 +++ admin/models/forms/admin_view.xml | 10 ++++ admin/models/forms/custom_admin_view.xml | 10 ++++ admin/models/forms/site_view.xml | 10 ++++ 7 files changed, 77 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d499e7641..9a15630de 100644 --- a/README.md +++ b/README.md @@ -150,8 +150,8 @@ TODO + *Version*: 2.9.15 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **203733** -+ *Field count*: **1116** ++ *Line count*: **203769** ++ *Field count*: **1119** + *File count*: **1338** + *Folder count*: **209** diff --git a/admin/README.txt b/admin/README.txt index d499e7641..9a15630de 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -150,8 +150,8 @@ TODO + *Version*: 2.9.15 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **203733** -+ *Field count*: **1116** ++ *Line count*: **203769** ++ *Field count*: **1119** + *File count*: **1338** + *Folder count*: **209** diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index cc1744ac0..8ed9b5836 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -10528,16 +10528,21 @@ class Interpretation extends Fields { $input = array(); $valueArray = array(); + $ifArray = array(); $getModel = array(); $userCheck = array(); foreach ($this->customScriptBuilder[$target]['ajax_controller'] as $view) { foreach ($view as $task) { - $input[$task['task_name']][] = PHP_EOL . $this->_t(6) . "\$" . $task['value_name'] . "Value = \$jinput->get('" . $task['value_name'] . "', " . $task['input_default'] . ", '" . $task['input_filter'] . "');"; + $input[$task['task_name']][] = "\$" . $task['value_name'] . "Value = \$jinput->get('" . $task['value_name'] . "', " . $task['input_default'] . ", '" . $task['input_filter'] . "');"; $valueArray[$task['task_name']][] = "\$" . $task['value_name'] . "Value"; - $getModel[$task['task_name']] = PHP_EOL . $this->_t(7) . "\$result = \$this->getModel('ajax')->" . $task['method_name'] . "(" . $this->bbb . "valueArray" . $this->ddd . ");"; - + $getModel[$task['task_name']] = "\$result = \$this->getModel('ajax')->" . $task['method_name'] . "(" . $this->bbb . "valueArray" . $this->ddd . ");"; + // check if null or zero is allowed + if (!isset($task['allow_zero']) || 1 != $task['allow_zero']) + { + $ifArray[$task['task_name']][] = "\$" . $task['value_name'] . "Value"; + } // see user check is needed if (isset($task['user_check']) && 1 == $task['user_check']) { @@ -10561,21 +10566,40 @@ class Interpretation extends Fields $cases .= PHP_EOL . $this->_t(6) . "\$returnRaw = \$jinput->get('raw', false, 'BOOLEAN');"; foreach ($input[$task] as $string) { - $cases .= $string; + $cases .= PHP_EOL . $this->_t(6) . $string; } // set the values $values = implode(', ', $valueArray[$task]); - $ifvalues = implode(' && ', $valueArray[$task]); // set the values to method $getMethod = str_replace($this->bbb . 'valueArray' . $this->ddd, $values, $getMethod); - $cases .= PHP_EOL . $this->_t(6) . "if(" . $ifvalues . $userCheck[$task] . ")"; - $cases .= PHP_EOL . $this->_t(6) . "{"; - $cases .= $getMethod; - $cases .= PHP_EOL . $this->_t(6) . "}"; - $cases .= PHP_EOL . $this->_t(6) . "else"; - $cases .= PHP_EOL . $this->_t(6) . "{"; - $cases .= PHP_EOL . $this->_t(7) . "\$result = false;"; - $cases .= PHP_EOL . $this->_t(6) . "}"; + // check if we have some values to check + if (isset($ifArray[$task]) && ComponentbuilderHelper::checkArray($ifArray[$task])) + { + $ifvalues = implode(' && ', $ifArray[$task]); + } + else + { + $ifvalues = ''; + } + // build the if string + $ifvalues = $ifvalues . $userCheck[$task]; + // check if we have a if string + if (ComponentbuilderHelper::checkString($ifvalues)) + { + $cases .= PHP_EOL . $this->_t(6) . "if(" . $ifvalues . ")"; + $cases .= PHP_EOL . $this->_t(6) . "{"; + $cases .= PHP_EOL . $this->_t(7) . $getMethod; + $cases .= PHP_EOL . $this->_t(6) . "}"; + $cases .= PHP_EOL . $this->_t(6) . "else"; + $cases .= PHP_EOL . $this->_t(6) . "{"; + $cases .= PHP_EOL . $this->_t(7) . "\$result = false;"; + $cases .= PHP_EOL . $this->_t(6) . "}"; + } + else + { + $cases .= PHP_EOL . $this->_t(6) . $getMethod; + } + // continue the build $cases .= PHP_EOL . $this->_t(6) . "if(\$callback = \$jinput->get('callback', null, 'CMD'))"; $cases .= PHP_EOL . $this->_t(6) . "{"; $cases .= PHP_EOL . $this->_t(7) . "echo \$callback . \"(\".json_encode(\$result).\");\";"; diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 69be153cc..1f033d126 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -542,6 +542,8 @@ COM_COMPONENTBUILDER_ADMIN_VIEW_ALIAS_BUILDER_LABEL="Alias Builder" COM_COMPONENTBUILDER_ADMIN_VIEW_ALIAS_BUILDER_TYPE="Alias Builder Type" COM_COMPONENTBUILDER_ADMIN_VIEW_ALIAS_BUILDER_TYPE_DESCRIPTION="How should the alias be build for this view" COM_COMPONENTBUILDER_ADMIN_VIEW_ALIAS_BUILDER_TYPE_LABEL="Alias Builder Type" +COM_COMPONENTBUILDER_ADMIN_VIEW_ALLOW_ZERO_DESCRIPTION="null & zero values" +COM_COMPONENTBUILDER_ADMIN_VIEW_ALLOW_ZERO_LABEL="Allow" COM_COMPONENTBUILDER_ADMIN_VIEW_ALNUM="ALNUM" COM_COMPONENTBUILDER_ADMIN_VIEW_ARCHIVE="Archive" COM_COMPONENTBUILDER_ADMIN_VIEW_ARMSCIIEIGHT_ARMSCIIEIGHT_ARMENIAN_MOST_SUITABLE_COLLATION_ARMSCIIEIGHT_GENERAL_CI="armscii8 - ARMSCII-8 Armenian (most suitable collation = armscii8_general_ci)" @@ -3215,6 +3217,8 @@ COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_PHP_VIEW="Add Php View" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_PHP_VIEW_LABEL="Add PHP (custom view script)" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_AJAX_INPUT="Ajax Input" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_AJAX_INPUT_LABEL="Ajax Input" +COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ALLOW_ZERO_DESCRIPTION="null & zero values" +COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ALLOW_ZERO_LABEL="Allow" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ALNUM="ALNUM" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ARCHIVE="Archive" COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ARRAY="ARRAY" @@ -6470,6 +6474,8 @@ COM_COMPONENTBUILDER_SITE_VIEW_ADD_PHP_VIEW="Add Php View" COM_COMPONENTBUILDER_SITE_VIEW_ADD_PHP_VIEW_LABEL="Add PHP (custom view script)" COM_COMPONENTBUILDER_SITE_VIEW_AJAX_INPUT="Ajax Input" COM_COMPONENTBUILDER_SITE_VIEW_AJAX_INPUT_LABEL="Ajax Input" +COM_COMPONENTBUILDER_SITE_VIEW_ALLOW_ZERO_DESCRIPTION="null & zero values" +COM_COMPONENTBUILDER_SITE_VIEW_ALLOW_ZERO_LABEL="Allow" COM_COMPONENTBUILDER_SITE_VIEW_ALNUM="ALNUM" COM_COMPONENTBUILDER_SITE_VIEW_ARCHIVE="Archive" COM_COMPONENTBUILDER_SITE_VIEW_ARRAY="ARRAY" diff --git a/admin/models/forms/admin_view.xml b/admin/models/forms/admin_view.xml index 0088e9d61..9099467ab 100644 --- a/admin/models/forms/admin_view.xml +++ b/admin/models/forms/admin_view.xml @@ -2619,6 +2619,16 @@ message="COM_COMPONENTBUILDER_ADMIN_VIEW_METHOD_NAME_MESSAGE" hint="COM_COMPONENTBUILDER_ADMIN_VIEW_METHOD_NAME_HINT" /> + + + + + +