From fd154a81bc6a822f1800b4dbdd9d18e12e273af8 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Tue, 9 Apr 2019 22:42:19 +0200 Subject: [PATCH 1/9] Resolved gh-404 by adding the option to use grouping in dynamicGet query. --- README.md | 12 +- admin/README.txt | 12 +- admin/helpers/compiler/a_Get.php | 7 + admin/helpers/compiler/e_Interpretation.php | 72 +- .../en-GB/en-GB.com_componentbuilder.ini | 5 +- admin/layouts/dynamic_get/tweak_fullwidth.php | 1 + admin/models/dynamic_get.php | 63 +- admin/models/forms/dynamic_get.js | 2 + admin/models/forms/dynamic_get.xml | 648 +++++++++--------- admin/sql/install.mysql.utf8.sql | 3 +- admin/sql/updates/mysql/2.9.14.sql | 1 + componentbuilder.xml | 6 +- componentbuilder_update_server.xml | 17 + script.php | 10 +- 14 files changed, 500 insertions(+), 359 deletions(-) create mode 100644 admin/sql/updates/mysql/2.9.14.sql diff --git a/README.md b/README.md index 451063e7a..33d6db07a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.14) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.15) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -146,13 +146,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 4th April, 2019 -+ *Version*: 2.9.14 ++ *Last Build*: 9th April, 2019 ++ *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*: **203650** -+ *Field count*: **1114** -+ *File count*: **1337** ++ *Line count*: **203724** ++ *Field count*: **1116** ++ *File count*: **1338** + *Folder count*: **209** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/README.txt b/admin/README.txt index 451063e7a..33d6db07a 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -12,7 +12,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.14) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.15) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -146,13 +146,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 4th April, 2019 -+ *Version*: 2.9.14 ++ *Last Build*: 9th April, 2019 ++ *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*: **203650** -+ *Field count*: **1114** -+ *File count*: **1337** ++ *Line count*: **203724** ++ *Field count*: **1116** ++ *File count*: **1338** + *Folder count*: **209** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 34ea1ccbf..00e62fbbf 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -3283,6 +3283,12 @@ class Get { unset($result->order); } + // set grouping + $result->group = json_decode($result->group, true); + if (!ComponentbuilderHelper::checkArray($result->group)) + { + unset($result->group); + } // set global details $result->global = json_decode($result->global, true); if (!ComponentbuilderHelper::checkArray($result->global)) @@ -3298,6 +3304,7 @@ class Get unset($result->filter); unset($result->where); unset($result->order); + unset($result->group); unset($result->global); } // load the events if any is set diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 13fc34e0b..2f5db303a 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -2067,6 +2067,30 @@ class Interpretation extends Fields return $filters; } + public function setCustomViewGroup(&$group, &$code, $tab = '') + { + $grouping = ''; + if (ComponentbuilderHelper::checkArray($group)) + { + foreach ($group as $gr) + { + list($as, $field) = array_map('trim', explode('.', $gr['table_key'])); + // set the string + $string = "\$query->group('" . $gr['table_key'] . "');"; + // sort where + if ($as === 'a' || (isset($this->siteMainGet[$this->target][$code][$as]) && ComponentbuilderHelper::checkString($this->siteMainGet[$this->target][$code][$as]))) + { + $grouping .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . $string; + } + else + { + $this->otherGroup[$this->target][$code][$as][$field] = PHP_EOL . $this->_t(2) . $string; + } + } + } + return $grouping; + } + public function setCustomViewOrder(&$order, &$code, $tab = '') { $ordering = ''; @@ -2313,11 +2337,25 @@ class Interpretation extends Fields // set main get query $getItem .= $this->setCustomViewQuery($get->main_get, $code, $tab); // setup filters - $getItem .= $this->setCustomViewFilter($get->filter, $code, $tab); + if (isset($get->filter)) + { + $getItem .= $this->setCustomViewFilter($get->filter, $code, $tab); + } // setup Where - $getItem .= $this->setCustomViewWhere($get->where, $code, $tab); + if (isset($get->where)) + { + $getItem .= $this->setCustomViewWhere($get->where, $code, $tab); + } // setup ordering - $getItem .= $this->setCustomViewOrder($get->order, $code, $tab); + if (isset($get->order)) + { + $getItem .= $this->setCustomViewOrder($get->order, $code, $tab); + } + // setup grouping + if (isset($get->group)) + { + $getItem .= $this->setCustomViewGroup($get->group, $code, $tab); + } // get ready to get query $getItem .= PHP_EOL . PHP_EOL . $tab . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object."; $getItem .= PHP_EOL . $this->_t(1) . $tab . $this->_t(1) . "\$db->setQuery(\$query);"; @@ -2798,6 +2836,14 @@ class Interpretation extends Fields $methods .= $string; } } + // add any other grouping that was set + if (isset($this->otherGroup[$this->target][$default['code']][$default['as']]) && ComponentbuilderHelper::checkArray($this->otherGroup[$this->target][$default['code']][$default['as']])) + { + foreach ($this->otherGroup[$this->target][$default['code']][$default['as']] as $field => $string) + { + $methods .= $string; + } + } $methods .= PHP_EOL . PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object."; $methods .= PHP_EOL . $this->_t(2) . "\$db->setQuery(\$query);"; $methods .= PHP_EOL . $this->_t(2) . "\$db->execute();"; @@ -3031,11 +3077,25 @@ class Interpretation extends Fields // set main get query $getItem .= $this->setCustomViewQuery($get->main_get, $code); // setup filters - $getItem .= $this->setCustomViewFilter($get->filter, $code); + if (isset($get->filter)) + { + $getItem .= $this->setCustomViewFilter($get->filter, $code); + } // setup where - $getItem .= $this->setCustomViewWhere($get->where, $code); + if (isset($get->where)) + { + $getItem .= $this->setCustomViewWhere($get->where, $code); + } // setup ordering - $getItem .= $this->setCustomViewOrder($get->order, $code); + if (isset($get->order)) + { + $getItem .= $this->setCustomViewOrder($get->order, $code); + } + // setup grouping + if (isset($get->group)) + { + $getItem .= $this->setCustomViewGroup($get->group, $code); + } if ($return) { // return the query object diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index 0d4fd2dc5..a578e1c95 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -4018,6 +4018,9 @@ COM_COMPONENTBUILDER_DYNAMIC_GET_GLOBAL_DESCRIPTION="Here you can add global var COM_COMPONENTBUILDER_DYNAMIC_GET_GLOBAL_LABEL="Set Global" COM_COMPONENTBUILDER_DYNAMIC_GET_GREATER_THAN="greater than" COM_COMPONENTBUILDER_DYNAMIC_GET_GREATER_THAN_OR_EQUAL="greater than or equal" +COM_COMPONENTBUILDER_DYNAMIC_GET_GROUP="Group" +COM_COMPONENTBUILDER_DYNAMIC_GET_GROUP_DESCRIPTION="Here you can set the grouping per data set." +COM_COMPONENTBUILDER_DYNAMIC_GET_GROUP_LABEL="Grouping" COM_COMPONENTBUILDER_DYNAMIC_GET_H="h" COM_COMPONENTBUILDER_DYNAMIC_GET_HH="hh" COM_COMPONENTBUILDER_DYNAMIC_GET_I="i" @@ -4169,7 +4172,7 @@ COM_COMPONENTBUILDER_DYNAMIC_GET_TAGS="Tags" COM_COMPONENTBUILDER_DYNAMIC_GET_THIS="This" COM_COMPONENTBUILDER_DYNAMIC_GET_TT="tt" COM_COMPONENTBUILDER_DYNAMIC_GET_TWEAK="Tweak" -COM_COMPONENTBUILDER_DYNAMIC_GET_TYPE_LABEL="Type" +COM_COMPONENTBUILDER_DYNAMIC_GET_TYPE_LABEL="Set Type" COM_COMPONENTBUILDER_DYNAMIC_GET_U="u" COM_COMPONENTBUILDER_DYNAMIC_GET_USER="User" COM_COMPONENTBUILDER_DYNAMIC_GET_USER_GROUPS="User Groups" diff --git a/admin/layouts/dynamic_get/tweak_fullwidth.php b/admin/layouts/dynamic_get/tweak_fullwidth.php index ff247ead4..0a85c6f11 100644 --- a/admin/layouts/dynamic_get/tweak_fullwidth.php +++ b/admin/layouts/dynamic_get/tweak_fullwidth.php @@ -18,6 +18,7 @@ $fields = $displayData->get('fields') ?: array( 'filter', 'where', 'order', + 'group', 'global' ); diff --git a/admin/models/dynamic_get.php b/admin/models/dynamic_get.php index 81ee9bf3f..aa7936163 100644 --- a/admin/models/dynamic_get.php +++ b/admin/models/dynamic_get.php @@ -134,6 +134,14 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $item->php_calculation = base64_decode($item->php_calculation); } + if (!empty($item->join_view_table)) + { + // Convert the join_view_table field to an array. + $join_view_table = new Registry; + $join_view_table->loadString($item->join_view_table); + $item->join_view_table = $join_view_table->toArray(); + } + if (!empty($item->join_db_table)) { // Convert the join_db_table field to an array. @@ -166,6 +174,14 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $item->order = $order->toArray(); } + if (!empty($item->group)) + { + // Convert the group field to an array. + $group = new Registry; + $group->loadString($item->group); + $item->group = $group->toArray(); + } + if (!empty($item->global)) { // Convert the global field to an array. @@ -174,14 +190,6 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $item->global = $global->toArray(); } - if (!empty($item->join_view_table)) - { - // Convert the join_view_table field to an array. - $join_view_table = new Registry; - $join_view_table->loadString($item->join_view_table); - $item->join_view_table = $join_view_table->toArray(); - } - if (!empty($item->plugin_events)) { // JSON Decode plugin_events. @@ -986,6 +994,19 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $data['metadata'] = (string) $metadata; } + // Set the join_view_table items to data. + if (isset($data['join_view_table']) && is_array($data['join_view_table'])) + { + $join_view_table = new JRegistry; + $join_view_table->loadArray($data['join_view_table']); + $data['join_view_table'] = (string) $join_view_table; + } + elseif (!isset($data['join_view_table'])) + { + // Set the empty join_view_table to data + $data['join_view_table'] = ''; + } + // Set the join_db_table items to data. if (isset($data['join_db_table']) && is_array($data['join_db_table'])) { @@ -1038,6 +1059,19 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $data['order'] = ''; } + // Set the group items to data. + if (isset($data['group']) && is_array($data['group'])) + { + $group = new JRegistry; + $group->loadArray($data['group']); + $data['group'] = (string) $group; + } + elseif (!isset($data['group'])) + { + // Set the empty group to data + $data['group'] = ''; + } + // Set the global items to data. if (isset($data['global']) && is_array($data['global'])) { @@ -1051,19 +1085,6 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin $data['global'] = ''; } - // Set the join_view_table items to data. - if (isset($data['join_view_table']) && is_array($data['join_view_table'])) - { - $join_view_table = new JRegistry; - $join_view_table->loadArray($data['join_view_table']); - $data['join_view_table'] = (string) $join_view_table; - } - elseif (!isset($data['join_view_table'])) - { - // Set the empty join_view_table to data - $data['join_view_table'] = ''; - } - // Set the plugin_events string to JSON string. if (isset($data['plugin_events'])) { diff --git a/admin/models/forms/dynamic_get.js b/admin/models/forms/dynamic_get.js index ac6e83c31..7d49b105d 100644 --- a/admin/models/forms/dynamic_get.js +++ b/admin/models/forms/dynamic_get.js @@ -657,6 +657,7 @@ function vvvvvzp(main_source_vvvvvzp) { jQuery('#jform_filter-lbl').closest('.control-group').show(); jQuery('#jform_global-lbl').closest('.control-group').show(); + jQuery('#jform_group-lbl').closest('.control-group').show(); jQuery('#jform_order-lbl').closest('.control-group').show(); jQuery('#jform_where-lbl').closest('.control-group').show(); jQuery('#jform_join_db_table-lbl').closest('.control-group').show(); @@ -666,6 +667,7 @@ function vvvvvzp(main_source_vvvvvzp) { jQuery('#jform_filter-lbl').closest('.control-group').hide(); jQuery('#jform_global-lbl').closest('.control-group').hide(); + jQuery('#jform_group-lbl').closest('.control-group').hide(); jQuery('#jform_order-lbl').closest('.control-group').hide(); jQuery('#jform_where-lbl').closest('.control-group').hide(); jQuery('#jform_join_db_table-lbl').closest('.control-group').hide(); diff --git a/admin/models/forms/dynamic_get.xml b/admin/models/forms/dynamic_get.xml index d019d039d..eb47ec68f 100644 --- a/admin/models/forms/dynamic_get.xml +++ b/admin/models/forms/dynamic_get.xml @@ -143,6 +143,16 @@ + + COM_COMPONENTBUILDER_DYNAMIC_GET_NO - + - - - - + type="textarea" + name="view_selection" + label="COM_COMPONENTBUILDER_DYNAMIC_GET_VIEW_SELECTION_LABEL" + rows="22" + cols="30" + description="COM_COMPONENTBUILDER_DYNAMIC_GET_VIEW_SELECTION_DESCRIPTION" + class="text_area span12" + filter="HTML" + hint="COM_COMPONENTBUILDER_DYNAMIC_GET_VIEW_SELECTION_HINT" + required="true" + /> COM_COMPONENTBUILDER_DYNAMIC_GET_NO - + + type="radio" + name="add_php_after_getitem" + label="COM_COMPONENTBUILDER_DYNAMIC_GET_ADD_PHP_AFTER_GETITEM_LABEL" + class="btn-group btn-group-yesno" + default="0" + required="true"> + + + + @@ -303,21 +313,267 @@ hint="COM_COMPONENTBUILDER_DYNAMIC_GET_DB_SELECTION_HINT" required="true" /> - + - + type="subform" + name="join_view_table" + label="COM_COMPONENTBUILDER_DYNAMIC_GET_JOIN_VIEW_TABLE_LABEL" + layout="joomla.form.field.subform.repeatable-table" + multiple="true" + description="COM_COMPONENTBUILDER_DYNAMIC_GET_JOIN_VIEW_TABLE_DESCRIPTION" + icon="list"> +