Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

type_dropdown.php

Zuletzt modifiziert: 02.04.2025, 15:02 - Dateigröße: 7.95 KiB


001  <?php
002  /**
003  *
004  * This file is part of the phpBB Forum Software package.
005  *
006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
007  * @license GNU General Public License, version 2 (GPL-2.0)
008  *
009  * For full copyright and license information, please see
010  * the docs/CREDITS.txt file.
011  *
012  */
013   
014  namespace phpbb\profilefields\type;
015   
016  class type_dropdown extends type_base
017  {
018      /**
019      * Profile fields language helper
020      * @var \phpbb\profilefields\lang_helper
021      */
022      protected $lang_helper;
023   
024      /**
025      * Request object
026      * @var \phpbb\request\request
027      */
028      protected $request;
029   
030      /**
031      * Template object
032      * @var \phpbb\template\template
033      */
034      protected $template;
035   
036      /**
037      * User object
038      * @var \phpbb\user
039      */
040      protected $user;
041   
042      /**
043      * Construct
044      *
045      * @param    \phpbb\profilefields\lang_helper        $lang_helper    Profile fields language helper
046      * @param    \phpbb\request\request        $request    Request object
047      * @param    \phpbb\template\template    $template    Template object
048      * @param    \phpbb\user                    $user        User object
049      */
050      public function __construct(\phpbb\profilefields\lang_helper $lang_helper, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
051      {
052          $this->lang_helper = $lang_helper;
053          $this->request = $request;
054          $this->template = $template;
055          $this->user = $user;
056      }
057   
058      /**
059      * {@inheritDoc}
060      */
061      public function get_name_short()
062      {
063          return 'dropdown';
064      }
065   
066      /**
067      * {@inheritDoc}
068      */
069      public function get_options($default_lang_id, $field_data)
070      {
071          $profile_row[0] = array(
072              'var_name'                => 'field_default_value',
073              'field_id'                => 1,
074              'lang_name'                => $field_data['lang_name'],
075              'lang_explain'            => $field_data['lang_explain'],
076              'lang_id'                => $default_lang_id,
077              'field_default_value'    => $field_data['field_default_value'],
078              'field_ident'            => 'field_default_value',
079              'field_type'            => $this->get_service_name(),
080              'lang_options'            => $field_data['lang_options'],
081          );
082   
083          $profile_row[1] = $profile_row[0];
084          $profile_row[1]['var_name'] = 'field_novalue';
085          $profile_row[1]['field_ident'] = 'field_novalue';
086          $profile_row[1]['field_default_value']    = $field_data['field_novalue'];
087   
088          $options = array(
089              0 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => $this->process_field_row('preview', $profile_row[0])),
090              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])),
091          );
092   
093          return $options;
094      }
095   
096      /**
097      * {@inheritDoc}
098      */
099      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  }
326