Resolved gh-489 to load field name with the field type

This commit is contained in:
Llewellyn van der Merwe 2019-11-09 03:53:24 +02:00
parent 693f51aff3
commit 04c080d460
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
11 changed files with 66 additions and 61 deletions

View File

@ -1,7 +1,7 @@
# Joomla Component Builder ([JCB](http://joomlacomponentbuilder.com)) # 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) [![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) [![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) 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) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 8th November, 2019 + *Last Build*: 9th November, 2019
+ *Version*: 2.10.4 + *Version*: 2.10.4
+ *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **255756** + *Line count*: **255944**
+ *Field count*: **1350** + *Field count*: **1350**
+ *File count*: **1614** + *File count*: **1614**
+ *Folder count*: **256** + *Folder count*: **256**

View File

@ -1,7 +1,7 @@
# Joomla Component Builder ([JCB](http://joomlacomponentbuilder.com)) # 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) [![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) [![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) 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) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 8th November, 2019 + *Last Build*: 9th November, 2019
+ *Version*: 2.10.4 + *Version*: 2.10.4
+ *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **255756** + *Line count*: **255944**
+ *Field count*: **1350** + *Field count*: **1350**
+ *File count*: **1614** + *File count*: **1614**
+ *Folder count*: **256** + *Folder count*: **256**

View File

@ -1813,7 +1813,7 @@ abstract class ComponentbuilderHelper
return false; return false;
} }
protected static function getFieldNameAndType($id) public static function getFieldNameAndType($id, $spacers = false)
{ {
// Get a db connection. // Get a db connection.
$db = JFactory::getDbo(); $db = JFactory::getDbo();
@ -1840,17 +1840,17 @@ abstract class ComponentbuilderHelper
$field->type_name = self::safeTypeName($field->type_name); $field->type_name = self::safeTypeName($field->type_name);
$load = true; $load = true;
// if category then name must be catid (only one per view) // if category then name must be catid (only one per view)
if ($field->type_name == 'category') if ($field->type_name === 'category')
{ {
$name = 'catid'; $name = 'catid';
} }
// if tag is set then enable all tag options for this view (only one per view) // 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'; $name = 'tags';
} }
// don't add spacers or notes // 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 // make sure the name is unique
return false; return false;

View File

@ -498,11 +498,11 @@ class ComponentbuilderModelAjax extends JModelList
protected $itemKeys = array( protected $itemKeys = array(
// admin view // admin view
'field' => 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', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), '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', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), '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', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), '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', 'type' => array('table' => 'fieldtype', 'field' => 'id', 'key' => 'fieldtype', 'get' => 'name')), 'joinfields' => array('table' => 'field', 'tables' => 'fields', 'id' => 'id', 'name' => 'name', 'text' => 'Field', 'get' => 'getFieldNameAndType'),
// joomla component view // joomla component view
'siteview' => array('table' => 'site_view', 'tables' => 'site_views', 'id' => 'id', 'name' => 'name', 'text' => 'Site 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'), '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) protected function setPermissions($header, $values)
{ {
// check if value is array // check if value is array
@ -1504,6 +1514,9 @@ class ComponentbuilderModelAjax extends JModelList
} }
return false; return false;
}; };
// check if functions exists
$guidEdit = method_exists('ComponentbuilderHelper', 'getEditButtonGUID');
$getEdit = method_exists('ComponentbuilderHelper', 'getEditButton');
// reset bucket // reset bucket
$bucket = array(); $bucket = array();
if (ComponentbuilderHelper::checkArray($value)) 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']); $this->itemNames[$this->itemKeys[$header]['table']][$item] = JText::sprintf('COM_COMPONENTBUILDER_NO_S_FOUND', $this->itemKeys[$header]['text']);
$edit = false; $edit = false;
} }
// check if we should load a type // check if we should load some get
if ($edit && isset($this->itemKeys[$header]['type']) && ComponentbuilderHelper::checkArray($this->itemKeys[$header]['type']) && isset($this->itemKeys[$header]['type']['table'])) if ($edit && isset($this->itemKeys[$header]['get']) && ComponentbuilderHelper::checkString($this->itemKeys[$header]['get']) && method_exists(__CLASS__, $this->itemKeys[$header]['get']))
{ {
// get the linked value // gets
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] .= $this->{$this->itemKeys[$header]['get']}($item);
{
$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']) .']';
}
} }
} }
// check if we are working with GUID // check if we are working with GUID
if ($validGUID($item) && method_exists('ComponentbuilderHelper', 'getEditButtonGUID')) if ($validGUID($item))
{ {
// set edit link // 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 else
{ {
// set edit link // 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 // load item
$bucket[] = $this->itemNames[$this->itemKeys[$header]['table']][$item] . $link; $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']); $this->itemNames[$this->itemKeys[$header]['table']][$value] = JText::sprintf('COM_COMPONENTBUILDER_NO_S_FOUND', $this->itemKeys[$header]['text']);
$edit = false; $edit = false;
} }
// check if we should load a type // check if we should load some get
if ($edit && isset($this->itemKeys[$header]['type']) && ComponentbuilderHelper::checkArray($this->itemKeys[$header]['type']) && isset($this->itemKeys[$header]['type']['table'])) if ($edit && isset($this->itemKeys[$header]['get']) && ComponentbuilderHelper::checkString($this->itemKeys[$header]['get']) && method_exists(__CLASS__, $this->itemKeys[$header]['get']))
{ {
// get the linked value // gets
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] .= $this->{$this->itemKeys[$header]['get']}($value);
{
$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']) .']';
}
} }
} }
// check if we are working with GUID // check if we are working with GUID
if ($validGUID($value) && method_exists('ComponentbuilderHelper', 'getEditButtonGUID')) if ($validGUID($value))
{ {
// set edit link // 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 else
{ {
// set edit link // 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 // load item
$bucket[] = $this->itemNames[$this->itemKeys[$header]['table']][$value] . $link; $bucket[] = $this->itemNames[$this->itemKeys[$header]['table']][$value] . $link;

View File

@ -36,24 +36,26 @@ class JFormFieldFields extends JFormFieldList
protected function getOptions() protected function getOptions()
{ {
$db = JFactory::getDBO(); $db = JFactory::getDBO();
$query = $db->getQuery(true); $query = $db->getQuery(true);
$query->select($db->quoteName(array('a.id','a.name','b.name'),array('id','field_name','type'))); $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->from($db->quoteName('#__componentbuilder_field', 'a'));
$query->join('LEFT', '#__componentbuilder_fieldtype AS b ON b.id = a.fieldtype'); $query->join('LEFT', '#__componentbuilder_fieldtype AS b ON b.id = a.fieldtype');
$query->where($db->quoteName('a.published') . ' >= 1'); $query->where($db->quoteName('a.published') . ' >= 1');
$query->order('a.name ASC'); $query->order('a.name ASC');
$db->setQuery((string)$query); $db->setQuery((string) $query);
$items = $db->loadObjectList(); $items = $db->loadObjectList();
$options = array(); $options = array();
if ($items) if ($items)
{ {
$options[] = JHtml::_('select.option', '', 'Select an option'); $options[] = JHtml::_('select.option', '', 'Select an option');
foreach($items as $item) foreach($items as $item)
{ {
$options[] = JHtml::_('select.option', $item->id, $item->field_name . ' [' . $item->type . ']'); // 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;
} }
} }

View File

@ -118,7 +118,6 @@
description="COM_COMPONENTBUILDER_ADMIN_FIELDS_FIELD_DESCRIPTION" description="COM_COMPONENTBUILDER_ADMIN_FIELDS_FIELD_DESCRIPTION"
class="list_class fieldFull" class="list_class fieldFull"
multiple="false" multiple="false"
default=""
required="true" required="true"
button="false" button="false"
/> />

View File

@ -117,7 +117,6 @@
description="COM_COMPONENTBUILDER_COMPONENT_CONFIG_FIELD_DESCRIPTION" description="COM_COMPONENTBUILDER_COMPONENT_CONFIG_FIELD_DESCRIPTION"
class="list_class fieldFull" class="list_class fieldFull"
multiple="false" multiple="false"
default=""
required="true" required="true"
button="false" button="false"
/> />

View File

@ -517,7 +517,6 @@
description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION" description="COM_COMPONENTBUILDER_JOOMLA_PLUGIN_FIELD_DESCRIPTION"
class="list_class fieldFull" class="list_class fieldFull"
multiple="false" multiple="false"
default=""
required="true" required="true"
button="false" button="false"
/> />

View File

@ -116,7 +116,6 @@
description="COM_COMPONENTBUILDER_LIBRARY_CONFIG_FIELD_DESCRIPTION" description="COM_COMPONENTBUILDER_LIBRARY_CONFIG_FIELD_DESCRIPTION"
class="list_class fieldFull" class="list_class fieldFull"
multiple="false" multiple="false"
default=""
required="true" required="true"
button="false" button="false"
/> />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>8th November, 2019</creationDate> <creationDate>9th November, 2019</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>

View File

@ -1813,7 +1813,7 @@ abstract class ComponentbuilderHelper
return false; return false;
} }
protected static function getFieldNameAndType($id) public static function getFieldNameAndType($id, $spacers = false)
{ {
// Get a db connection. // Get a db connection.
$db = JFactory::getDbo(); $db = JFactory::getDbo();
@ -1840,17 +1840,17 @@ abstract class ComponentbuilderHelper
$field->type_name = self::safeTypeName($field->type_name); $field->type_name = self::safeTypeName($field->type_name);
$load = true; $load = true;
// if category then name must be catid (only one per view) // if category then name must be catid (only one per view)
if ($field->type_name == 'category') if ($field->type_name === 'category')
{ {
$name = 'catid'; $name = 'catid';
} }
// if tag is set then enable all tag options for this view (only one per view) // 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'; $name = 'tags';
} }
// don't add spacers or notes // 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 // make sure the name is unique
return false; return false;