[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/fields/sql/tmpl/ -> sql.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Fields.Sql
   6   *
   7   * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\Database\ParameterType;
  15  
  16  $value = $field->value;
  17  
  18  if ($value == '') {
  19      return;
  20  }
  21  
  22  $db    = Factory::getDbo();
  23  $value = (array) $value;
  24  $query = $db->getQuery(true);
  25  $sql   = $fieldParams->get('query', '');
  26  
  27  $bindNames = $query->bindArray($value, ParameterType::STRING);
  28  
  29  // Run the query with a having condition because it supports aliases
  30  $query->setQuery($sql . ' HAVING ' . $db->quoteName('value') . ' IN (' . implode(',', $bindNames) . ')');
  31  
  32  try {
  33      $db->setQuery($query);
  34      $items = $db->loadObjectList();
  35  } catch (Exception $e) {
  36      // If the query failed, we fetch all elements
  37      $db->setQuery($sql);
  38      $items = $db->loadObjectList();
  39  }
  40  
  41  $texts = array();
  42  
  43  foreach ($items as $item) {
  44      if (in_array($item->value, $value)) {
  45          $texts[] = $item->text;
  46      }
  47  }
  48  
  49  echo htmlentities(implode(', ', $texts));


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer