From ab471e3ccb7b1263e0b6c2ddf0e2137da2f25e2e Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 18 Oct 2021 22:12:19 +0200 Subject: [PATCH] Added search by translated string to the translation area. --- README.md | 12 +- admin/README.txt | 12 +- admin/compiler/joomla_3/Helper_email.php | 3 + admin/controllers/ajax.json.php | 3 +- admin/helpers/compiler.php | 35 +++++- admin/helpers/compiler/a_Get.php | 4 +- admin/helpers/componentbuilder.php | 109 +++++++++++++++++- admin/helpers/componentbuilderemail.php | 3 + .../en-GB/en-GB.com_componentbuilder.ini | 10 +- admin/models/ajax.php | 19 ++- admin/models/joomla_components.php | 7 ++ admin/models/language_translations.php | 2 +- componentbuilder.xml | 6 +- componentbuilder_update_server.xml | 4 +- media/js/custom_code.js | 4 +- media/js/placeholder.js | 4 +- script.php | 2 +- site/helpers/componentbuilder.php | 109 +++++++++++++++++- 18 files changed, 313 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index c61f1f52b..0816c1a23 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 save 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.12.11) 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.12.14) 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) @@ -143,13 +143,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*: 31st August, 2021 -+ *Version*: 2.12.11 ++ *Last Build*: 18th October, 2021 ++ *Version*: 2.12.14 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **292284** -+ *Field count*: **1630** -+ *File count*: **1936** ++ *Line count*: **293253** ++ *Field count*: **1654** ++ *File count*: **1937** + *Folder count*: **322** > 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 c61f1f52b..0816c1a23 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 save 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.12.11) 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.12.14) 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) @@ -143,13 +143,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*: 31st August, 2021 -+ *Version*: 2.12.11 ++ *Last Build*: 18th October, 2021 ++ *Version*: 2.12.14 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **292284** -+ *Field count*: **1630** -+ *File count*: **1936** ++ *Line count*: **293253** ++ *Field count*: **1654** ++ *File count*: **1937** + *Folder count*: **322** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](http://joomlacomponentbuilder.com). diff --git a/admin/compiler/joomla_3/Helper_email.php b/admin/compiler/joomla_3/Helper_email.php index 0cab1b295..309817cac 100644 --- a/admin/compiler/joomla_3/Helper_email.php +++ b/admin/compiler/joomla_3/Helper_email.php @@ -14,6 +14,9 @@ defined('_JEXEC') or die('Restricted access'); ?> ###BOM### +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + /** * ###Component### component email helper */ diff --git a/admin/controllers/ajax.json.php b/admin/controllers/ajax.json.php index c6fbccf9b..692f4c61b 100644 --- a/admin/controllers/ajax.json.php +++ b/admin/controllers/ajax.json.php @@ -423,9 +423,10 @@ class ComponentbuilderControllerAjax extends JControllerLegacy { $idValue = $jinput->get('id', NULL, 'INT'); $typeValue = $jinput->get('type', NULL, 'WORD'); + $keyValue = $jinput->get('key', 1, 'INT'); if($idValue && $user->id != 0 && $typeValue) { - $result = $this->getModel('ajax')->getClassCodeIds($idValue, $typeValue); + $result = $this->getModel('ajax')->getClassCodeIds($idValue, $typeValue, $keyValue); } else { diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index 24821dd50..062ece59d 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -690,6 +690,39 @@ class Compiler extends Infusion File::delete($update_server_xml_path); } } + // move the modules update server to host + if (ComponentbuilderHelper::checkArray($this->joomlaModules)) + { + foreach ($this->joomlaModules as $module) + { + if (ComponentbuilderHelper::checkObject($module) + && isset($module->add_update_server) + && $module->add_update_server == 1 + && isset($module->update_server_target) + && $module->update_server_target == 1 + && isset($module->update_server) + && is_numeric($module->update_server) + && $module->update_server > 0 + && isset($module->update_server_xml_path) + && File::exists($module->update_server_xml_path) + && isset($module->update_server_xml_file_name) + && ComponentbuilderHelper::checkString( + $module->update_server_xml_file_name + )) + { + // move to server + ComponentbuilderHelper::moveToServer( + $module->update_server_xml_path, + $module->update_server_xml_file_name, + (int) $module->update_server, + $module->update_server_protocol + ); + // remove the local file + File::delete($module->update_server_xml_path); + } + // var_dump($module->update_server_xml_path);exit; + } + } // move the plugins update server to host if (ComponentbuilderHelper::checkArray($this->joomlaPlugins)) { @@ -724,7 +757,7 @@ class Compiler extends Infusion } } - // link canges made to views into the file license + // link changes made to views into the file license protected function fixLicenseValues($data) { // check if these files have its own config data) diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 0f08ac0ce..464d04a09 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -1,5 +1,5 @@ {$server} = 0; - // only change this for sales server (update server can be added loacaly to the zip file) + // only change this for sales server (update server can be added locally to the zip file) if ('sales_server' === $server) { $plugin->{'add_' . $server} = 0; diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 91e9f01dd..d18f167ff 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -78,6 +78,11 @@ abstract class ComponentbuilderHelper **/ protected static $localCompany = array(); + /** + * The excluded powers + **/ + protected static $exPowers= array(); + /** * The snippet paths **/ @@ -1968,6 +1973,39 @@ abstract class ComponentbuilderHelper } return false; } + + /** + * Powers to exclude + **/ + public static function excludePowers($id) + { + // first check if this power set is already found + if (!isset(self::$exPowers[$id])) + { + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id'))); + $query->from($db->quoteName('#__componentbuilder_power', 'a')); + $query->join('LEFT', $db->quoteName('#__componentbuilder_power', 'b') . ' ON (' . $db->quoteName('a.name') . ' = ' . $db->quoteName('b.name') . ' AND ' . $db->quoteName('a.namespace') . ' = ' . $db->quoteName('b.namespace') . ')'); + $query->where($db->quoteName('b.id') . ' = ' . (int) $id); + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + self::$exPowers[$id] = $db->loadColumn(); + } + // all ways add itself aswell + self::$exPowers[$id][] = $id; + } + // if found return + if (isset(self::$exPowers[$id])) + { + return self::$exPowers[$id]; + } + return false; + } /** * The array of dynamic content @@ -2606,7 +2644,7 @@ abstract class ComponentbuilderHelper $field['values'] .= PHP_EOL . "/>"; $field['values_description'] .= ''; // load the database defaults if set and wanted - if ($db_defaults && isset($result->has_defaults) && $result->has_defaults == 1) + if ($dbDefaults && isset($result->has_defaults) && $result->has_defaults == 1) { $field['database'] = array( 'datatype' => $result->datatype, @@ -6716,6 +6754,75 @@ abstract class ComponentbuilderHelper } return false; } + + + /** + * Check if a row already exist + * + * @param string $table The table from which to get the variable + * @param array $where The value where + * @param string $main The component in which the table is found + * + * @return int the id, or false + * + */ + public static function checkExist($table, $where, $what = 'id', $operator = '=', $main = 'componentbuilder') + { + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array($what))); + if (empty($table)) + { + $query->from($db->quoteName('#__'.$main)); + } + else + { + $query->from($db->quoteName('#__'.$main.'_'.$table)); + } + if (self::checkArray($where)) + { + foreach ($where as $key => $value) + { + if (is_numeric($value)) + { + if (is_float($value + 0)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (float) $value); + } + else + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (int) $value); + } + } + elseif (is_bool($value)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (bool) $value); + } + // we do not allow arrays at this point + elseif (!self::checkArray($value)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . $db->quote( (string) $value)); + } + else + { + return false; + } + } + } + else + { + return false; + } + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + return $db->loadResult(); + } + return false; + } /** diff --git a/admin/helpers/componentbuilderemail.php b/admin/helpers/componentbuilderemail.php index 78d12e9bc..66889886e 100644 --- a/admin/helpers/componentbuilderemail.php +++ b/admin/helpers/componentbuilderemail.php @@ -9,6 +9,9 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ +// No direct access to this file +defined('_JEXEC') or die('Restricted access'); + /** * Componentbuilder component email helper */ diff --git a/admin/language/en-GB/en-GB.com_componentbuilder.ini b/admin/language/en-GB/en-GB.com_componentbuilder.ini index a10d04495..0031efab6 100644 --- a/admin/language/en-GB/en-GB.com_componentbuilder.ini +++ b/admin/language/en-GB/en-GB.com_componentbuilder.ini @@ -4226,6 +4226,7 @@ COM_COMPONENTBUILDER_CUSTOM_CODE_NOTE_PLACEHOLDERS_EXPLAINED_DESCRIPTION=" + @@ -6824,13 +6825,13 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_JOOMLA_PLUGIN_GROUP_LABEL="Joomla Plugin Grou COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_DESCRIPTION="Not mandatory, used to Label the Fieldset" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_HINT="Name" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_LABEL_LABEL="Label" -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_DESCRIPTION="Add the class properties & methods here." -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_LABEL="Class Properties & Methods" +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_DESCRIPTION="Add the properties & methods here." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MAIN_CLASS_CODE_LABEL="Properties & Methods" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHOD="Method" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHODS_BUTTON_ACCESS="Joomla Plugin Methods Button Access" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHODS_BUTTON_ACCESS_DESC="Allows the users in this group to access the methods button." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHOD_LABEL="Methods" -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHOD_SELECTION_DESCRIPTION="Select methods you want to use in your plugin class." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHOD_SELECTION_DESCRIPTION="Select methods you want to use in your joomla_plugin." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_METHOD_SELECTION_LABEL="Method Selection" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MODIFIED_BY_DESC="The last user that modified this Joomla Plugin." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_MODIFIED_BY_LABEL="Modified By" @@ -6882,7 +6883,7 @@ COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTIES_BUTTON_ACCESS="Joomla Plugin Prope COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTIES_BUTTON_ACCESS_DESC="Allows the users in this group to access the properties button." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTY="Property" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTY_LABEL="Properties" -COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTY_SELECTION_DESCRIPTION="Select properties you want to use in your plugin class." +COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTY_SELECTION_DESCRIPTION="Select properties you want to use in your joomla_plugin." COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PROPERTY_SELECTION_LABEL="Property Selection" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_PUBLISHING="Publishing" COM_COMPONENTBUILDER_JOOMLA_PLUGIN_README="Readme" @@ -7791,6 +7792,7 @@ COM_COMPONENTBUILDER_PLACEHOLDER_NOTE_PLACEHOLDERS_PLACEDIN_DESCRIPTION=" + diff --git a/admin/models/ajax.php b/admin/models/ajax.php index c2d132383..f25dc6881 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -317,11 +317,19 @@ class ComponentbuilderModelAjax extends JModelList return ComponentbuilderHelper::getClassCode($id, $type); } - public function getClassCodeIds($id, $type) + public function getClassCodeIds($id, $type, $key) { if ('property' === $type || 'method' === $type) { - return ComponentbuilderHelper::getVars('class_' . $type, $id, 'joomla_plugin_group', 'id'); + // we get the plugin group, or the powers + if ($key == 1) + { + return ComponentbuilderHelper::getVars('class_' . $type, $id, 'joomla_plugin_group', 'id'); + } + elseif ($key == 2) + { + return ComponentbuilderHelper::getVars('class_' . $type, 'powers', 'extension_type', 'id'); + } } elseif ('joomla_plugin_group' === $type) { @@ -2659,6 +2667,13 @@ class ComponentbuilderModelAjax extends JModelList 'views' => 'class_methods', 'not_base64' => array(), 'name' => 'name' + ), + // #__componentbuilder_power (v) + 'class_method' => array( + 'search' => array('id', 'name', 'description', 'head', 'head', 'main_class_code'), + 'views' => 'powers', + 'not_base64' => array('description'), + 'name' => 'name' ) ); diff --git a/admin/models/joomla_components.php b/admin/models/joomla_components.php index 557bddd30..02e54887b 100644 --- a/admin/models/joomla_components.php +++ b/admin/models/joomla_components.php @@ -2073,6 +2073,13 @@ class ComponentbuilderModelJoomla_components extends JModelList 'views' => 'class_methods', 'not_base64' => array(), 'name' => 'name' + ), + // #__componentbuilder_power (v) + 'class_method' => array( + 'search' => array('id', 'name', 'description', 'head', 'head', 'main_class_code'), + 'views' => 'powers', + 'not_base64' => array('description'), + 'name' => 'name' ) ); diff --git a/admin/models/language_translations.php b/admin/models/language_translations.php index 6e22b378f..ee12e3f84 100644 --- a/admin/models/language_translations.php +++ b/admin/models/language_translations.php @@ -387,7 +387,7 @@ class ComponentbuilderModelLanguage_translations extends JModelList else { $search = $db->quote('%' . $db->escape($search) . '%'); - $query->where('(a.source LIKE '.$search.')'); + $query->where('(a.source LIKE '.$search.' OR a.translation LIKE '.$search.')'); } } diff --git a/componentbuilder.xml b/componentbuilder.xml index 5c244e2e3..49e86422a 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,15 +1,15 @@ COM_COMPONENTBUILDER - 31st August, 2021 + 18th October, 2021 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com Copyright (C) 2015 Vast Development Method. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt - 2.12.11 + 2.12.14 Component Builder (v.2.12.11) +

Component Builder (v.2.12.14)

The Component Builder for [Joomla](https://extensions.joomla.org/extension/component-builder/) is highly advanced tool that is truly able to build extremely complex components in a fraction of the time. diff --git a/componentbuilder_update_server.xml b/componentbuilder_update_server.xml index 4ffc5cb8d..e11cea060 100644 --- a/componentbuilder_update_server.xml +++ b/componentbuilder_update_server.xml @@ -1041,10 +1041,10 @@ Builds Complex Joomla Components com_componentbuilder component - 2.12.11 + 2.12.14 http://www.joomlacomponentbuilder.com - http://domain.com/demo.zip + https://github.com/vdm-io/Joomla-Component-Builder/releases/download/v2.12.14/JCB_v2.12.14.zip stable diff --git a/media/js/custom_code.js b/media/js/custom_code.js index 4829cd915..317bc3c84 100644 --- a/media/js/custom_code.js +++ b/media/js/custom_code.js @@ -328,8 +328,8 @@ function usedin(functioName, ide) { jQuery('#note-usedin-not').hide(); jQuery('#note-usedin-found').hide(); jQuery('#loading-usedin').show(); - var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u']; // if you update this, also update (below 20) & [customcode-codeUsedInHtmlNote]! - var targetNumber = 20; + var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v']; // if you update this, also update (below 21) & [customcode-codeUsedInHtmlNote]! + var targetNumber = 21; var run = 0; var usedinChecker = setInterval(function(){ var target = targets[run]; diff --git a/media/js/placeholder.js b/media/js/placeholder.js index 976e08401..a18ecc8da 100644 --- a/media/js/placeholder.js +++ b/media/js/placeholder.js @@ -78,8 +78,8 @@ function placedin(placeholder, ide) { jQuery('#note-placedin-not').hide(); jQuery('#note-placedin-found').hide(); jQuery('#loading-placedin').show(); - var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u']; // if you update this, also update (below 20) & [customcode-codeUsedInHtmlNote]! - var targetNumber = 20; + var targets = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v']; // if you update this, also update (below 21) & [customcode-codeUsedInHtmlNote]! + var targetNumber = 21; var run = 0; var placedinChecker = setInterval(function(){ var target = targets[run]; diff --git a/script.php b/script.php index 9fc8f2423..01b039d3d 100644 --- a/script.php +++ b/script.php @@ -9252,7 +9252,7 @@ class com_componentbuilderInstallerScript echo ' -

Upgrade to Version 2.12.11 Was Successful! Let us know if anything is not working as expected.

'; +

Upgrade to Version 2.12.14 Was Successful! Let us know if anything is not working as expected.

'; // Set db if not set already. if (!isset($db)) diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index cd1e9e2fd..521ca8485 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -75,6 +75,11 @@ abstract class ComponentbuilderHelper **/ protected static $localCompany = array(); + /** + * The excluded powers + **/ + protected static $exPowers= array(); + /** * The snippet paths **/ @@ -1965,6 +1970,39 @@ abstract class ComponentbuilderHelper } return false; } + + /** + * Powers to exclude + **/ + public static function excludePowers($id) + { + // first check if this power set is already found + if (!isset(self::$exPowers[$id])) + { + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id'))); + $query->from($db->quoteName('#__componentbuilder_power', 'a')); + $query->join('LEFT', $db->quoteName('#__componentbuilder_power', 'b') . ' ON (' . $db->quoteName('a.name') . ' = ' . $db->quoteName('b.name') . ' AND ' . $db->quoteName('a.namespace') . ' = ' . $db->quoteName('b.namespace') . ')'); + $query->where($db->quoteName('b.id') . ' = ' . (int) $id); + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + self::$exPowers[$id] = $db->loadColumn(); + } + // all ways add itself aswell + self::$exPowers[$id][] = $id; + } + // if found return + if (isset(self::$exPowers[$id])) + { + return self::$exPowers[$id]; + } + return false; + } /** * The array of dynamic content @@ -2603,7 +2641,7 @@ abstract class ComponentbuilderHelper $field['values'] .= PHP_EOL . "/>"; $field['values_description'] .= ''; // load the database defaults if set and wanted - if ($db_defaults && isset($result->has_defaults) && $result->has_defaults == 1) + if ($dbDefaults && isset($result->has_defaults) && $result->has_defaults == 1) { $field['database'] = array( 'datatype' => $result->datatype, @@ -6713,6 +6751,75 @@ abstract class ComponentbuilderHelper } return false; } + + + /** + * Check if a row already exist + * + * @param string $table The table from which to get the variable + * @param array $where The value where + * @param string $main The component in which the table is found + * + * @return int the id, or false + * + */ + public static function checkExist($table, $where, $what = 'id', $operator = '=', $main = 'componentbuilder') + { + // Get a db connection. + $db = JFactory::getDbo(); + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array($what))); + if (empty($table)) + { + $query->from($db->quoteName('#__'.$main)); + } + else + { + $query->from($db->quoteName('#__'.$main.'_'.$table)); + } + if (self::checkArray($where)) + { + foreach ($where as $key => $value) + { + if (is_numeric($value)) + { + if (is_float($value + 0)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (float) $value); + } + else + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (int) $value); + } + } + elseif (is_bool($value)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . (bool) $value); + } + // we do not allow arrays at this point + elseif (!self::checkArray($value)) + { + $query->where($db->quoteName($key) . ' ' . $operator . ' ' . $db->quote( (string) $value)); + } + else + { + return false; + } + } + } + else + { + return false; + } + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + return $db->loadResult(); + } + return false; + } /**