[ Index ]

PHP Cross Reference of phpBB-3.3.3-deutsch

title

Body

[close]

/phpbb/profilefields/type/ -> type_dropdown.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\type;
  15  
  16  class type_dropdown extends type_base
  17  {
  18      /**
  19      * Profile fields language helper
  20      * @var \phpbb\profilefields\lang_helper
  21      */
  22      protected $lang_helper;
  23  
  24      /**
  25      * Request object
  26      * @var \phpbb\request\request
  27      */
  28      protected $request;
  29  
  30      /**
  31      * Template object
  32      * @var \phpbb\template\template
  33      */
  34      protected $template;
  35  
  36      /**
  37      * User object
  38      * @var \phpbb\user
  39      */
  40      protected $user;
  41  
  42      /**
  43      * Construct
  44      *
  45      * @param    \phpbb\profilefields\lang_helper        $lang_helper    Profile fields language helper
  46      * @param    \phpbb\request\request        $request    Request object
  47      * @param    \phpbb\template\template    $template    Template object
  48      * @param    \phpbb\user                    $user        User object
  49      */
  50  	public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
  51      {
  52          $this->lang_helper = $lang_helper;
  53          $this->request = $request;
  54          $this->template = $template;
  55          $this->user = $user;
  56      }
  57  
  58      /**
  59      * {@inheritDoc}
  60      */
  61  	public function get_name_short()
  62      {
  63          return 'dropdown';
  64      }
  65  
  66      /**
  67      * {@inheritDoc}
  68      */
  69  	public function get_options($default_lang_id, $field_data)
  70      {
  71          $profile_row[0] = array(
  72              'var_name'                => 'field_default_value',
  73              'field_id'                => 1,
  74              'lang_name'                => $field_data['lang_name'],
  75              'lang_explain'            => $field_data['lang_explain'],
  76              'lang_id'                => $default_lang_id,
  77              'field_default_value'    => $field_data['field_default_value'],
  78              'field_ident'            => 'field_default_value',
  79              'field_type'            => $this->get_service_name(),
  80              'lang_options'            => $field_data['lang_options'],
  81          );
  82  
  83          $profile_row[1] = $profile_row[0];
  84          $profile_row[1]['var_name'] = 'field_novalue';
  85          $profile_row[1]['field_ident'] = 'field_novalue';
  86          $profile_row[1]['field_default_value']    = $field_data['field_novalue'];
  87  
  88          $options = array(
  89              0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
  90              1 => array('TITLE' => $this->user->lang['NO_VALUE_OPTION'], 'EXPLAIN' => $this->user->lang['NO_VALUE_OPTION_EXPLAIN'], 'FIELD' => $this->process_field_row('preview', $profile_row[1])),
  91          );
  92  
  93          return $options;
  94      }
  95  
  96      /**
  97      * {@inheritDoc}
  98      */
  99  	public function get_default_option_values()
 100      {
 101          return array(
 102              'field_length'        => 0,
 103              'field_minlen'        => 0,
 104              'field_maxlen'        => 5,
 105              'field_validation'    => '',
 106              'field_novalue'        => 0,
 107              'field_default_value'    => 0,
 108          );
 109      }
 110  
 111      /**
 112      * {@inheritDoc}
 113      */
 114  	public function get_default_field_value($field_data)
 115      {
 116          return $field_data['field_default_value'];
 117      }
 118  
 119      /**
 120      * {@inheritDoc}
 121      */
 122  	public function get_profile_field($profile_row)
 123      {
 124          $var_name = 'pf_' . $profile_row['field_ident'];
 125          return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
 126      }
 127  
 128      /**
 129      * {@inheritDoc}
 130      */
 131  	public function validate_profile_field(&$field_value, $field_data)
 132      {
 133          $field_value = (int) $field_value;
 134  
 135          // retrieve option lang data if necessary
 136          if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], 1))
 137          {
 138              $this->lang_helper->load_option_lang($field_data['lang_id']);
 139          }
 140  
 141          if (!$this->lang_helper->is_set($field_data['field_id'], $field_data['lang_id'], $field_value))
 142          {
 143              return $this->user->lang('FIELD_INVALID_VALUE', $this->get_field_name($field_data['lang_name']));
 144          }
 145  
 146          if ($field_value == $field_data['field_novalue'] && $field_data['field_required'])
 147          {
 148              return $this->user->lang('FIELD_REQUIRED', $this->get_field_name($field_data['lang_name']));
 149          }
 150  
 151          return false;
 152      }
 153  
 154      /**
 155      * {@inheritDoc}
 156      */
 157  	public function get_profile_value($field_value, $field_data)
 158      {
 159          $field_id = $field_data['field_id'];
 160          $lang_id = $field_data['lang_id'];
 161          if (!$this->lang_helper->is_set($field_id, $lang_id))
 162          {
 163              $this->lang_helper->load_option_lang($lang_id);
 164          }
 165  
 166          if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
 167          {
 168              return null;
 169          }
 170  
 171          $field_value = (int) $field_value;
 172  
 173          // User not having a value assigned
 174          if (!$this->lang_helper->is_set($field_id, $lang_id, $field_value))
 175          {
 176              if ($field_data['field_show_novalue'])
 177              {
 178                  $field_value = $field_data['field_novalue'];
 179              }
 180              else
 181              {
 182                  return null;
 183              }
 184          }
 185  
 186          return $this->lang_helper->get($field_id, $lang_id, $field_value);
 187      }
 188  
 189      /**
 190      * {@inheritDoc}
 191      */
 192  	public function get_profile_value_raw($field_value, $field_data)
 193      {
 194          if ($field_value == $field_data['field_novalue'] && !$field_data['field_show_novalue'])
 195          {
 196              return null;
 197          }
 198  
 199          if (!$field_value && $field_data['field_show_novalue'])
 200          {
 201              $field_value = $field_data['field_novalue'];
 202          }
 203  
 204          return $field_value;
 205      }
 206  
 207      /**
 208      * {@inheritDoc}
 209      */
 210  	public function generate_field($profile_row, $preview_options = false)
 211      {
 212          $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
 213          $field_ident = $profile_row['field_ident'];
 214          $default_value = $profile_row['field_default_value'];
 215  
 216          $value = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]);
 217  
 218          if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1))
 219          {
 220              if ($preview_options)
 221              {
 222                  $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options);
 223              }
 224              else
 225              {
 226                  $this->lang_helper->load_option_lang($profile_row['lang_id']);
 227              }
 228          }
 229  
 230          $profile_row['field_value'] = (int) $value;
 231          $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER));
 232  
 233          $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']);
 234          foreach ($options as $option_id => $option_value)
 235          {
 236              $this->template->assign_block_vars('dropdown.options', array(
 237                  'OPTION_ID'    => $option_id,
 238                  'SELECTED'    => ($value == $option_id) ? ' selected="selected"' : '',
 239                  'VALUE'        => $option_value,
 240              ));
 241          }
 242      }
 243  
 244      /**
 245      * {@inheritDoc}
 246      */
 247  	public function get_database_column_type()
 248      {
 249          return 'UINT';
 250      }
 251  
 252      /**
 253      * {@inheritDoc}
 254      */
 255  	public function get_language_options($field_data)
 256      {
 257          $options = array(
 258              'lang_name'        => 'string',
 259              'lang_options'    => 'optionfield',
 260          );
 261  
 262          if ($field_data['lang_explain'])
 263          {
 264              $options['lang_explain'] = 'text';
 265          }
 266  
 267          return $options;
 268      }
 269  
 270      /**
 271      * {@inheritDoc}
 272      */
 273  	public function prepare_options_form(&$exclude_options, &$visibility_options)
 274      {
 275          $exclude_options[1][] = 'lang_options';
 276  
 277          return $this->request->variable('lang_options', '', true);
 278      }
 279  
 280      /**
 281      * {@inheritDoc}
 282      */
 283  	public function validate_options_on_submit($error, $field_data)
 284      {
 285          if (!count($field_data['lang_options']))
 286          {
 287              $error[] = $this->user->lang['NO_FIELD_ENTRIES'];
 288          }
 289  
 290          return $error;
 291      }
 292  
 293      /**
 294      * {@inheritDoc}
 295      */
 296  	public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
 297      {
 298          if ($step == 2 && $key == 'field_maxlen')
 299          {
 300              // Get the number of options if this key is 'field_maxlen'
 301              return count(explode("\n", $this->request->variable('lang_options', '', true)));
 302          }
 303  
 304          return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
 305      }
 306  
 307      /**
 308      * {@inheritDoc}
 309      */
 310  	public function display_options(&$template_vars, &$field_data)
 311      {
 312          // Initialize these array elements if we are creating a new field
 313          if (!count($field_data['lang_options']))
 314          {
 315              // No options have been defined for the dropdown menu
 316              $field_data['lang_options'] = array();
 317          }
 318  
 319          $template_vars = array_merge($template_vars, array(
 320              'S_DROPDOWN'                => true,
 321              'L_LANG_OPTIONS_EXPLAIN'    => $this->user->lang['DROPDOWN_ENTRIES_EXPLAIN'],
 322              'LANG_OPTIONS'                => implode("\n", $field_data['lang_options']),
 323          ));
 324      }
 325  }


Generated: Sun Feb 14 20:08:31 2021 Cross-referenced by PHPXref 0.7.1