sql.php
1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* @package Joomla.Plugin
* @subpackage Fields.Sql
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
$value = $field->value;
if ($value == '')
{
return;
}
$db = JFactory::getDbo();
$value = (array) $value;
$condition = '';
foreach ($value as $v)
{
if (!$v)
{
continue;
}
$condition .= ', ' . $db->q($v);
}
$query = $fieldParams->get('query', '');
// Run the query with a having condition because it supports aliases
$db->setQuery($query . ' having value in (' . trim($condition, ',') . ')');
try
{
$items = $db->loadObjectlist();
}
catch (Exception $e)
{
// If the query failed, we fetch all elements
$db->setQuery($query);
$items = $db->loadObjectlist();
}
$texts = array();
foreach ($items as $item)
{
if (in_array($item->value, $value))
{
$texts[] = $item->text;
}
}
echo htmlentities(implode(', ', $texts));