[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/HTML/Helpers/ -> ContentLanguage.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE.txt
   8   */
   9  
  10  namespace Joomla\CMS\HTML\Helpers;
  11  
  12  use Joomla\CMS\Factory;
  13  use Joomla\CMS\Language\Text;
  14  use Joomla\CMS\Object\CMSObject;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('JPATH_PLATFORM') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Utility class working with content language select lists
  22   *
  23   * @since  1.6
  24   */
  25  abstract class ContentLanguage
  26  {
  27      /**
  28       * Cached array of the content language items.
  29       *
  30       * @var    array
  31       * @since  1.6
  32       */
  33      protected static $items = null;
  34  
  35      /**
  36       * Get a list of the available content language items.
  37       *
  38       * @param   boolean  $all        True to include All (*)
  39       * @param   boolean  $translate  True to translate All
  40       *
  41       * @return  array
  42       *
  43       * @see     \Joomla\CMS\Form\Field\ContentlanguageField
  44       * @since   1.6
  45       */
  46      public static function existing($all = false, $translate = false)
  47      {
  48          if (empty(static::$items)) {
  49              // Get the database object and a new query object.
  50              $db    = Factory::getDbo();
  51              $query = $db->getQuery(true);
  52  
  53              // Build the query.
  54              $query->select(
  55                  [
  56                      $db->quoteName('a.lang_code', 'value'),
  57                      $db->quoteName('a.title', 'text'),
  58                      $db->quoteName('a.title_native'),
  59                  ]
  60              )
  61                  ->from($db->quoteName('#__languages', 'a'))
  62                  ->where($db->quoteName('a.published') . ' >= 0')
  63                  ->order($db->quoteName('a.title'));
  64  
  65              // Set the query and load the options.
  66              $db->setQuery($query);
  67              static::$items = $db->loadObjectList();
  68          }
  69  
  70          if ($all) {
  71              $all_option = array(new CMSObject(array('value' => '*', 'text' => $translate ? Text::alt('JALL', 'language') : 'JALL_LANGUAGE')));
  72  
  73              return array_merge($all_option, static::$items);
  74          } else {
  75              return static::$items;
  76          }
  77      }
  78  }


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