CoreFiles by mySites.guru
sql.php49 lines, 1,118 bytes, from Joomla_5.2.6-Stable-Full_Package.zip
Raw History Compare with 5.2.5
md5
55c44115e7349a8dd99ae2ee64208dab
sha1
86a0b0c0570ee02371e80c94dab1bfb9ee96037e
sha256
9a7c8110fc4426f81e16d87b79c341bbcdd61b900b1aa7f36ae098eb80c22800
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  Fields.Sql
 *
 * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\Database\ParameterType;

$value = $field->value;

if ($value == '') {
    return;
}

$db    = Factory::getDbo();
$value = (array) $value;
$query = $db->getQuery(true);
$sql   = $fieldParams->get('query', '');

$bindNames = $query->bindArray($value, ParameterType::STRING);

// Run the query with a having condition because it supports aliases
$query->setQuery($sql . ' HAVING ' . $db->quoteName('value') . ' IN (' . implode(',', $bindNames) . ')');

try {
    $db->setQuery($query);
    $items = $db->loadObjectList();
} catch (Exception $e) {
    // If the query failed, we fetch all elements
    $db->setQuery($sql);
    $items = $db->loadObjectList();
}

$texts = [];

foreach ($items as $item) {
    if (in_array($item->value, $value)) {
        $texts[] = $item->text;
    }
}

echo htmlentities(implode(', ', $texts));

The same content is in 170 releases, Joomla 4.2.7-rc1 to 6.0.0-beta3. See them all, or every version of this file.