[ Index ]

PHP Cross Reference of phpBB-3.3.0-deutsch

title

Body

[close]

/phpbb/profilefields/ -> lang_helper.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\profilefields;
  15  
  16  /**
  17  * Custom Profile Fields
  18  */
  19  class lang_helper
  20  {
  21      /**
  22      * Array with the language option, grouped by field and language
  23      * @var array
  24      */
  25      protected $options_lang = array();
  26  
  27      /**
  28      * Database object
  29      * @var \phpbb\db\driver\driver_interface
  30      */
  31      protected $db;
  32  
  33      /**
  34      * Table where the language strings are stored
  35      * @var string
  36      */
  37      protected $language_table;
  38  
  39      /**
  40      * Construct
  41      *
  42      * @param    \phpbb\db\driver\driver_interface    $db        Database object
  43      * @param    string        $language_table        Table where the language strings are stored
  44      */
  45  	public function __construct($db, $language_table)
  46      {
  47          $this->db = $db;
  48          $this->language_table = $language_table;
  49      }
  50  
  51      /**
  52      * Loads preview options into language entries for options
  53      *
  54      * @param    int        $field_id
  55      * @param    int        $lang_id
  56      * @param    mixed    $preview_options
  57      */
  58  	public function load_preview_options($field_id, $lang_id, $preview_options)
  59      {
  60          $lang_options = (!is_array($preview_options)) ? explode("\n", $preview_options) : $preview_options;
  61  
  62          foreach ($lang_options as $num => $var)
  63          {
  64              if (!isset($this->options_lang[$field_id]))
  65              {
  66                  $this->options_lang[$field_id] = array();
  67              }
  68              if (!isset($this->options_lang[$field_id][$lang_id]))
  69              {
  70                  $this->options_lang[$field_id][$lang_id] = array();
  71              }
  72              $this->options_lang[$field_id][$lang_id][($num + 1)] = $var;
  73          }
  74      }
  75  
  76      /**
  77      * Fetches language entries for options from DB
  78      *
  79      * @param    int        $lang_id
  80      */
  81  	public function load_option_lang($lang_id)
  82      {
  83          $sql = 'SELECT field_id, option_id, lang_value
  84                  FROM ' . $this->language_table . '
  85                  WHERE lang_id = ' . (int) $lang_id . "
  86                  ORDER BY option_id";
  87  
  88          $result = $this->db->sql_query($sql);
  89  
  90          while ($row = $this->db->sql_fetchrow($result))
  91          {
  92              $this->options_lang[$row['field_id']][$lang_id][($row['option_id'] + 1)] = $row['lang_value'];
  93          }
  94  
  95          $this->db->sql_freeresult($result);
  96      }
  97  
  98      /**
  99      * Are language options set for this field?
 100      *
 101      * @param    int        $field_id        Database ID of the field
 102      * @param    int        $lang_id        ID of the language
 103      * @param    int        $field_value    Selected value of the field
 104      * @return boolean
 105      */
 106  	public function is_set($field_id, $lang_id = null, $field_value = null)
 107      {
 108          $is_set = isset($this->options_lang[$field_id]);
 109  
 110          if ($is_set && (!is_null($lang_id) || !is_null($field_value)))
 111          {
 112              $is_set = isset($this->options_lang[$field_id][$lang_id]);
 113          }
 114  
 115          if ($is_set && !is_null($field_value))
 116          {
 117              $is_set = isset($this->options_lang[$field_id][$lang_id][$field_value]);
 118          }
 119  
 120          return $is_set;
 121      }
 122  
 123      /**
 124      * Get the selected language string
 125      *
 126      * @param    int        $field_id        Database ID of the field
 127      * @param    int        $lang_id        ID of the language
 128      * @param    int        $field_value    Selected value of the field
 129      * @return string
 130      */
 131  	public function get($field_id, $lang_id, $field_value = null)
 132      {
 133          if (is_null($field_value))
 134          {
 135              return $this->options_lang[$field_id][$lang_id];
 136          }
 137  
 138          return $this->options_lang[$field_id][$lang_id][$field_value];
 139      }
 140  }


Generated: Tue Apr 7 19:44:41 2020 Cross-referenced by PHPXref 0.7.1