improve the method to detect that it is working with another component, and so tell the method to also look outside the current scope (component)

This commit is contained in:
2018-05-02 23:59:01 +02:00
parent d961652f56
commit 2f4f9ff0a3
10 changed files with 129 additions and 51 deletions

View File

@ -37,6 +37,13 @@ abstract class ###Component###Helper
public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name')
{
// do some table foot work
$external = false;
if (strpos($table, '#__') !== false)
{
$external = true;
$table = str_replace('#__', '', $table);
}
// check if string is JSON
$result = json_decode($value, true);
if (json_last_error() === JSON_ERROR_NONE)
@ -49,9 +56,19 @@ abstract class ###Component###Helper
$names = array();
foreach ($result as $val)
{
if ($name = self::getVar($table, $val, $id, $name))
if ($external)
{
$names[] = $name;
if ($name = self::getVar(null, $val, $id, $name, '=', $table))
{
$names[] = $name;
}
}
else
{
if ($name = self::getVar($table, $val, $id, $name))
{
$names[] = $name;
}
}
}
if (self::checkArray($names))