[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
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_int extends type_base 17 { 18 /** 19 * Request object 20 * @var \phpbb\request\request 21 */ 22 protected $request; 23 24 /** 25 * Template object 26 * @var \phpbb\template\template 27 */ 28 protected $template; 29 30 /** 31 * User object 32 * @var \phpbb\user 33 */ 34 protected $user; 35 36 /** 37 * Construct 38 * 39 * @param \phpbb\request\request $request Request object 40 * @param \phpbb\template\template $template Template object 41 * @param \phpbb\user $user User object 42 */ 43 public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user) 44 { 45 $this->request = $request; 46 $this->template = $template; 47 $this->user = $user; 48 } 49 50 /** 51 * {@inheritDoc} 52 */ 53 public function get_name_short() 54 { 55 return 'int'; 56 } 57 58 /** 59 * {@inheritDoc} 60 */ 61 public function get_options($default_lang_id, $field_data) 62 { 63 $options = array( 64 0 => array('TITLE' => $this->user->lang['FIELD_LENGTH'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_length" value="' . $field_data['field_length'] . '" />'), 65 1 => array('TITLE' => $this->user->lang['MIN_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_minlen" value="' . $field_data['field_minlen'] . '" />'), 66 2 => array('TITLE' => $this->user->lang['MAX_FIELD_NUMBER'], 'FIELD' => '<input type="number" min="0" max="99999" name="field_maxlen" value="' . $field_data['field_maxlen'] . '" />'), 67 3 => array('TITLE' => $this->user->lang['DEFAULT_VALUE'], 'FIELD' => '<input type="number" name="field_default_value" value="' . $field_data['field_default_value'] . '" />'), 68 ); 69 70 return $options; 71 } 72 73 /** 74 * {@inheritDoc} 75 */ 76 public function get_default_option_values() 77 { 78 return array( 79 'field_length' => 5, 80 'field_minlen' => 0, 81 'field_maxlen' => 100, 82 'field_validation' => '', 83 'field_novalue' => 0, 84 'field_default_value' => 0, 85 ); 86 } 87 88 /** 89 * {@inheritDoc} 90 */ 91 public function get_default_field_value($field_data) 92 { 93 if ($field_data['field_default_value'] === '') 94 { 95 // We cannot insert an empty string into an integer column. 96 return null; 97 } 98 99 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 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |