Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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_int.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.80 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_int extends type_base
017  {
018      /**
019      * Request object
020      * @var \phpbb\request\request
021      */
022      protected $request;
023   
024      /**
025      * Template object
026      * @var \phpbb\template\template
027      */
028      protected $template;
029   
030      /**
031      * User object
032      * @var \phpbb\user
033      */
034      protected $user;
035   
036      /**
037      * Construct
038      *
039      * @param    \phpbb\request\request        $request    Request object
040      * @param    \phpbb\template\template    $template    Template object
041      * @param    \phpbb\user                    $user        User object
042      */
043      public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user)
044      {
045          $this->request = $request;
046          $this->template = $template;
047          $this->user = $user;
048      }
049   
050      /**
051      * {@inheritDoc}
052      */
053      public function get_name_short()
054      {
055          return 'int';
056      }
057   
058      /**
059      * {@inheritDoc}
060      */
061      public function get_options($default_lang_id, $field_data)
062      {
063          $options = array(
064              0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'],        'FIELD' => '<input type="number" min="0" max="99999" name="field_length" size="5" value="' . $field_data['field_length'] . '" />'),
065              1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'],    'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" size="5" value="' . $field_data['field_minlen'] . '" />'),
066              2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'],    'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" size="5" value="' . $field_data['field_maxlen'] . '" />'),
067              3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'],        'FIELD' => '<input type="number" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'),
068          );
069   
070          return $options;
071      }
072   
073      /**
074      * {@inheritDoc}
075      */
076      public function get_default_option_values()
077      {
078          return array(
079              'field_length'        => 5,
080              'field_minlen'        => 0,
081              'field_maxlen'        => 100,
082              'field_validation'    => '',
083              'field_novalue'        => 0,
084              'field_default_value'    => 0,
085          );
086      }
087   
088      /**
089      * {@inheritDoc}
090      */
091      public function get_default_field_value($field_data)
092      {
093          if ($field_data['field_default_value'] === '')
094          {
095              // We cannot insert an empty string into an integer column.
096              return null;
097          }
098   
099          return $field_data['field_default_value'];
100      }
101   
102      /**
103      * {@inheritDoc}
104      */
105      public function get_profile_field($profile_row)
106      {
107          $var_name = 'pf_' . $profile_row['field_ident'];
108          if ($this->request->is_set($var_name) && $this->request->variable($var_name, '') === '')
109          {
110              return null;
111          }
112          else
113          {
114              return $this->request->variable($var_name, (int) $profile_row['field_default_value']);
115          }
116      }
117   
118      /**
119      * {@inheritDoc}
120      */
121      public function validate_profile_field(&$field_value, $field_data)
122      {
123          if (trim($field_value) === '' && !$field_data['field_required'])
124          {
125              return false;
126          }
127   
128          $field_value = (int) $field_value;
129   
130          if ($field_value < $field_data['field_minlen'])
131          {
132              return $this->user->lang('FIELD_TOO_SMALL', (int) $field_data['field_minlen'], $this->get_field_name($field_data['lang_name']));
133          }
134          else if ($field_value > $field_data['field_maxlen'])
135          {
136              return $this->user->lang('FIELD_TOO_LARGE', (int) $field_data['field_maxlen'], $this->get_field_name($field_data['lang_name']));
137          }
138   
139          return false;
140      }
141   
142      /**
143      * {@inheritDoc}
144      */
145      public function get_profile_value($field_value, $field_data)
146      {
147          if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
148          {
149              return null;
150          }
151          return (int) $field_value;
152      }
153   
154      /**
155      * {@inheritDoc}
156      */
157      public function get_profile_value_raw($field_value, $field_data)
158      {
159          if (($field_value === '' || $field_value === null) && !$field_data['field_show_novalue'])
160          {
161              return null;
162          }
163          return (int) $field_value;
164      }
165   
166      /**
167      * {@inheritDoc}
168      */
169      public function generate_field($profile_row, $preview_options = false)
170      {
171          $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident'];
172          $field_ident = $profile_row['field_ident'];
173          $default_value = $profile_row['field_default_value'];
174   
175          if ($this->request->is_set($field_ident))
176          {
177              $value = ($this->request->variable($field_ident, '') === '') ? null : $this->request->variable($field_ident, $default_value);
178          }
179          else
180          {
181              if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident]))
182              {
183                  $value = null;
184              }
185              else if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false)
186              {
187                  $value = $default_value;
188              }
189              else
190              {
191                  $value = $this->user->profile_fields[$field_ident];
192              }
193          }
194   
195          $profile_row['field_value'] = (is_null($value) || $value === '') ? '' : (int) $value;
196   
197          $this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER));
198      }
199   
200      /**
201      * {@inheritDoc}
202      */
203      public function get_field_ident($field_data)
204      {
205          return 'pf_' . $field_data['field_ident'];
206      }
207   
208      /**
209      * {@inheritDoc}
210      */
211      public function get_database_column_type()
212      {
213          return 'BINT';
214      }
215   
216      /**
217      * {@inheritDoc}
218      */
219      public function get_language_options($field_data)
220      {
221          $options = array(
222              'lang_name' => 'string',
223          );
224   
225          if ($field_data['lang_explain'])
226          {
227              $options['lang_explain'] = 'text';
228          }
229   
230          return $options;
231      }
232   
233      /**
234      * {@inheritDoc}
235      */
236      public function get_excluded_options($key, $action, $current_value, &$field_data, $step)
237      {
238          if ($step == 2 && $key == 'field_default_value')
239          {
240              // Permit an empty string
241              if ($action == 'create' && $this->request->variable('field_default_value', '') === '')
242              {
243                  return '';
244              }
245          }
246   
247          return parent::get_excluded_options($key, $action, $current_value, $field_data, $step);
248      }
249  }
250