From 04c080d4600a62dd67006d1368ac0146cf079335 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 9 Nov 2019 03:53:24 +0200 Subject: [PATCH] Resolved gh-489 to load field name with the field type --- README.md | 6 +-- admin/README.txt | 6 +-- admin/helpers/componentbuilder.php | 8 ++-- admin/models/ajax.php | 57 ++++++++++++++----------- admin/models/fields/fields.php | 36 ++++++++-------- admin/models/forms/admin_fields.xml | 1 - admin/models/forms/component_config.xml | 1 - admin/models/forms/joomla_plugin.xml | 1 - admin/models/forms/library_config.xml | 1 - componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 8 ++-- 11 files changed, 66 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index a1740d26b..14829e7f9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Joomla Component Builder ([JCB](http://joomlacomponentbuilder.com)) [![GitHub release](https://img.shields.io/github/release/vdm-io/Joomla-Component-Builder.svg)](https://github.com/vdm-io/Joomla-Component-Builder/releases) [![Total Downloads](https://img.shields.io/github/downloads/vdm-io/Joomla-Component-Builder/total.svg)](https://github.com/vdm-io/Joomla-Component-Builder/releases) -[![JCB Pro Members](https://opencollective.com/joomla-component-builder/tiers/jcb-pro/badge.svg?label=JCB Pro&color=brightgreen)](#sponsors) +[![JCB Pro Members](https://opencollective.com/joomla-component-builder/tiers/jcb-pro/badge.svg?label=JCB+Pro&color=brightgreen)](#sponsors) This is a [Joomla 3.x](https://extensions.joomla.org/extension/component-builder/) component. [__See In Action__](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -143,11 +143,11 @@ 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*: 8th November, 2019 ++ *Last Build*: 9th November, 2019 + *Version*: 2.10.4 + *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*: **255756** ++ *Line count*: **255944** + *Field count*: **1350** + *File count*: **1614** + *Folder count*: **256** diff --git a/admin/README.txt b/admin/README.txt index a1740d26b..14829e7f9 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -1,7 +1,7 @@ # Joomla Component Builder ([JCB](http://joomlacomponentbuilder.com)) [![GitHub release](https://img.shields.io/github/release/vdm-io/Joomla-Component-Builder.svg)](https://github.com/vdm-io/Joomla-Component-Builder/releases) [![Total Downloads](https://img.shields.io/github/downloads/vdm-io/Joomla-Component-Builder/total.svg)](https://github.com/vdm-io/Joomla-Component-Builder/releases) -[![JCB Pro Members](https://opencollective.com/joomla-component-builder/tiers/jcb-pro/badge.svg?label=JCB Pro&color=brightgreen)](#sponsors) +[![JCB Pro Members](https://opencollective.com/joomla-component-builder/tiers/jcb-pro/badge.svg?label=JCB+Pro&color=brightgreen)](#sponsors) This is a [Joomla 3.x](https://extensions.joomla.org/extension/component-builder/) component. [__See In Action__](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -143,11 +143,11 @@ 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*: 8th November, 2019 ++ *Last Build*: 9th November, 2019 + *Version*: 2.10.4 + *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*: **255756** ++ *Line count*: **255944** + *Field count*: **1350** + *File count*: **1614** + *Folder count*: **256** diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 5e72cc1a4..5b562735b 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -1813,7 +1813,7 @@ abstract class ComponentbuilderHelper return false; } - protected static function getFieldNameAndType($id) + public static function getFieldNameAndType($id, $spacers = false) { // Get a db connection. $db = JFactory::getDbo(); @@ -1840,17 +1840,17 @@ abstract class ComponentbuilderHelper $field->type_name = self::safeTypeName($field->type_name); $load = true; // if category then name must be catid (only one per view) - if ($field->type_name == 'category') + if ($field->type_name === 'category') { $name = 'catid'; } // if tag is set then enable all tag options for this view (only one per view) - elseif ($field->type_name == 'tag') + elseif ($field->type_name === 'tag') { $name = 'tags'; } // don't add spacers or notes - elseif ($field->type_name == 'spacer' || $field->type_name == 'note') + elseif (!$spacers && ($field->type_name == 'spacer' || $field->type_name == 'note')) { // make sure the name is unique return false; diff --git a/admin/models/ajax.php b/admin/models/ajax.php index cb9fefd89..46c2f4ac9 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -498,11 +498,11 @@ class ComponentbuilderModelAjax extends JModelList protected $itemKeys = array( // admin view - 'field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), - 'target_field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), - 'match_field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), - 'listfield' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), - 'joinfields' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), + 'field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'), + 'target_field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'), + 'match_field' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'), + 'listfield' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'), + 'joinfields' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'), // joomla component view 'siteview' => array('table' => 'site_view', 'tables' => 'site_views', 'id' => 'id', 'name' => 'name', 'text' => 'Site View'), 'customadminview' => array('table' => 'custom_admin_view', 'tables' => 'custom_admin_views', 'id' => 'id', 'name' => 'system_name', 'text' => 'Custom Admin View'), @@ -536,6 +536,16 @@ class ComponentbuilderModelAjax extends JModelList } } + protected function getFieldNameAndType($id) + { + // check if we can get the field name and type + if (($array = ComponentbuilderHelper::getFieldNameAndType($id, true)) !== false) + { + return ' [' . $array['name'] . ' - ' . $array['type'] . ']'; + } + return ''; + } + protected function setPermissions($header, $values) { // check if value is array @@ -1504,6 +1514,9 @@ class ComponentbuilderModelAjax extends JModelList } return false; }; + // check if functions exists + $guidEdit = method_exists('ComponentbuilderHelper', 'getEditButtonGUID'); + $getEdit = method_exists('ComponentbuilderHelper', 'getEditButton'); // reset bucket $bucket = array(); if (ComponentbuilderHelper::checkArray($value)) @@ -1518,26 +1531,23 @@ class ComponentbuilderModelAjax extends JModelList $this->itemNames[$this->itemKeys[$header]['table']][$item] = JText::sprintf('COM_COMPONENTBUILDER_NO_S_FOUND', $this->itemKeys[$header]['text']); $edit = false; } - // check if we should load a type - if ($edit && isset($this->itemKeys[$header]['type']) && ComponentbuilderHelper::checkArray($this->itemKeys[$header]['type']) && isset($this->itemKeys[$header]['type']['table'])) + // check if we should load some get + if ($edit && isset($this->itemKeys[$header]['get']) && ComponentbuilderHelper::checkString($this->itemKeys[$header]['get']) && method_exists(__CLASS__, $this->itemKeys[$header]['get'])) { - // get the linked value - if (($_key = ComponentbuilderHelper::getVar($this->itemKeys[$header]['table'], $item, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['type']['key'])) !== false) - { - $this->itemNames[$this->itemKeys[$header]['table']][$item] .= ' [' . ComponentbuilderHelper::getVar($this->itemKeys[$header]['type']['table'], $_key, $this->itemKeys[$header]['type']['field'], $this->itemKeys[$header]['type']['get']) .']'; - } + // gets + $this->itemNames[$this->itemKeys[$header]['table']][$item] .= $this->{$this->itemKeys[$header]['get']}($item); } } // check if we are working with GUID - if ($validGUID($item) && method_exists('ComponentbuilderHelper', 'getEditButtonGUID')) + if ($validGUID($item)) { // set edit link - $link = ($edit) ? ComponentbuilderHelper::getEditButtonGUID($item, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; + $link = ($edit && $guidEdit) ? ComponentbuilderHelper::getEditButtonGUID($item, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; } else { // set edit link - $link = ($edit) ? ComponentbuilderHelper::getEditButton($item, $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; + $link = ($edit && $getEdit) ? ComponentbuilderHelper::getEditButton($item, $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; } // load item $bucket[] = $this->itemNames[$this->itemKeys[$header]['table']][$item] . $link; @@ -1553,26 +1563,23 @@ class ComponentbuilderModelAjax extends JModelList $this->itemNames[$this->itemKeys[$header]['table']][$value] = JText::sprintf('COM_COMPONENTBUILDER_NO_S_FOUND', $this->itemKeys[$header]['text']); $edit = false; } - // check if we should load a type - if ($edit && isset($this->itemKeys[$header]['type']) && ComponentbuilderHelper::checkArray($this->itemKeys[$header]['type']) && isset($this->itemKeys[$header]['type']['table'])) + // check if we should load some get + if ($edit && isset($this->itemKeys[$header]['get']) && ComponentbuilderHelper::checkString($this->itemKeys[$header]['get']) && method_exists(__CLASS__, $this->itemKeys[$header]['get'])) { - // get the linked value - if (($_key = ComponentbuilderHelper::getVar($this->itemKeys[$header]['table'], $value, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['type']['key'])) !== false) - { - $this->itemNames[$this->itemKeys[$header]['table']][$value] .= ' [' . ComponentbuilderHelper::getVar($this->itemKeys[$header]['type']['table'], $_key, $this->itemKeys[$header]['type']['field'], $this->itemKeys[$header]['type']['get']) .']'; - } + // gets + $this->itemNames[$this->itemKeys[$header]['table']][$value] .= $this->{$this->itemKeys[$header]['get']}($value); } } // check if we are working with GUID - if ($validGUID($value) && method_exists('ComponentbuilderHelper', 'getEditButtonGUID')) + if ($validGUID($value)) { // set edit link - $link = ($edit) ? ComponentbuilderHelper::getEditButtonGUID($value, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; + $link = ($edit && $guidEdit) ? ComponentbuilderHelper::getEditButtonGUID($value, $this->itemKeys[$header]['id'], $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; } else { // set edit link - $link = ($edit) ? ComponentbuilderHelper::getEditButton($value, $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; + $link = ($edit && $getEdit) ? ComponentbuilderHelper::getEditButton($value, $this->itemKeys[$header]['table'], $this->itemKeys[$header]['tables'], $this->ref) : ''; } // load item $bucket[] = $this->itemNames[$this->itemKeys[$header]['table']][$value] . $link; diff --git a/admin/models/fields/fields.php b/admin/models/fields/fields.php index 6a998ac3d..2b30c292e 100644 --- a/admin/models/fields/fields.php +++ b/admin/models/fields/fields.php @@ -36,24 +36,26 @@ class JFormFieldFields extends JFormFieldList protected function getOptions() { $db = JFactory::getDBO(); -$query = $db->getQuery(true); -$query->select($db->quoteName(array('a.id','a.name','b.name'),array('id','field_name','type'))); -$query->from($db->quoteName('#__componentbuilder_field', 'a')); + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id', 'a.name', 'a.xml', 'b.name'), array('id', 'field_name', 'xml', 'type'))); + $query->from($db->quoteName('#__componentbuilder_field', 'a')); $query->join('LEFT', '#__componentbuilder_fieldtype AS b ON b.id = a.fieldtype'); -$query->where($db->quoteName('a.published') . ' >= 1'); -$query->order('a.name ASC'); -$db->setQuery((string)$query); -$items = $db->loadObjectList(); -$options = array(); -if ($items) -{ - $options[] = JHtml::_('select.option', '', 'Select an option'); - foreach($items as $item) - { - $options[] = JHtml::_('select.option', $item->id, $item->field_name . ' [' . $item->type . ']'); - } -} + $query->where($db->quoteName('a.published') . ' >= 1'); + $query->order('a.name ASC'); + $db->setQuery((string) $query); + $items = $db->loadObjectList(); + $options = array(); + if ($items) + { + $options[] = JHtml::_('select.option', '', 'Select an option'); + foreach($items as $item) + { + // get the field name (TODO this could slow down the system so we will need to improve on this) + $field_name = ComponentbuilderHelper::safeFieldName(ComponentbuilderHelper::getBetween(json_decode($item->xml),'name="','"')); + $options[] = JHtml::_('select.option', $item->id, $item->field_name . ' [ ' . $field_name . ' - ' . $item->type . ' ]'); + } + } -return $options; + return $options; } } diff --git a/admin/models/forms/admin_fields.xml b/admin/models/forms/admin_fields.xml index 7d87d4478..b94b9b6cf 100644 --- a/admin/models/forms/admin_fields.xml +++ b/admin/models/forms/admin_fields.xml @@ -118,7 +118,6 @@ description="COM_COMPONENTBUILDER_ADMIN_FIELDS_FIELD_DESCRIPTION" class="list_class fieldFull" multiple="false" - default="" required="true" button="false" /> diff --git a/admin/models/forms/component_config.xml b/admin/models/forms/component_config.xml index a3e64055b..0497456dd 100644 --- a/admin/models/forms/component_config.xml +++ b/admin/models/forms/component_config.xml @@ -117,7 +117,6 @@ description="COM_COMPONENTBUILDER_COMPONENT_CONFIG_FIELD_DESCRIPTION" class="list_class fieldFull" multiple="false" - default="" required="true" button="false" /> diff --git a/admin/models/forms/joomla_plugin.xml b/admin/models/forms/joomla_plugin.xml index 9e51bcc1a..3d65b7f70 100644 --- a/admin/models/forms/joomla_plugin.xml +++ b/admin/models/forms/joomla_plugin.xml @@ -517,7 +517,6 @@ description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION" class="list_class fieldFull" multiple="false" - default="" required="true" button="false" /> diff --git a/admin/models/forms/library_config.xml b/admin/models/forms/library_config.xml index 01815163c..ce19805db 100644 --- a/admin/models/forms/library_config.xml +++ b/admin/models/forms/library_config.xml @@ -116,7 +116,6 @@ description="COM_COMPONENTBUILDER_LIBRARY_CONFIG_FIELD_DESCRIPTION" class="list_class fieldFull" multiple="false" - default="" required="true" button="false" /> diff --git a/componentbuilder.xml b/componentbuilder.xml index 8fb3b9e1c..491e82a1f 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 8th November, 2019 + 9th November, 2019 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index d9e9f4a86..59b68cf67 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -1813,7 +1813,7 @@ abstract class ComponentbuilderHelper return false; } - protected static function getFieldNameAndType($id) + public static function getFieldNameAndType($id, $spacers = false) { // Get a db connection. $db = JFactory::getDbo(); @@ -1840,17 +1840,17 @@ abstract class ComponentbuilderHelper $field->type_name = self::safeTypeName($field->type_name); $load = true; // if category then name must be catid (only one per view) - if ($field->type_name == 'category') + if ($field->type_name === 'category') { $name = 'catid'; } // if tag is set then enable all tag options for this view (only one per view) - elseif ($field->type_name == 'tag') + elseif ($field->type_name === 'tag') { $name = 'tags'; } // don't add spacers or notes - elseif ($field->type_name == 'spacer' || $field->type_name == 'note') + elseif (!$spacers && ($field->type_name == 'spacer' || $field->type_name == 'note')) { // make sure the name is unique return false;