Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
type_text | |
0.00% |
0 / 59 |
|
0.00% |
0 / 12 |
552 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
get_name_short | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_options | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
get_default_option_values | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
get_profile_field | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
validate_profile_field | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
generate_field | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
30 | |||
get_database_column_type | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_language_options | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
get_excluded_options | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
prepare_hidden_fields | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
display_options | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 |
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_text extends type_string_common |
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 'text'; |
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="rows" value="' . $field_data['rows'] . '" /> ' . $this->user->lang['ROWS'] . '</dd><dd><input type="number" min="0" max="99999" name="columns" value="' . $field_data['columns'] . '" /> ' . $this->user->lang['COLUMNS'] . ' <input type="hidden" name="field_length" value="' . $field_data['field_length'] . '" />'), |
65 | 1 => array('TITLE' => $this->user->lang['MIN_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_minlen" value="' . $field_data['field_minlen'] . '" />'), |
66 | 2 => array('TITLE' => $this->user->lang['MAX_FIELD_CHARS'], 'FIELD' => '<input type="number" min="0" max="9999999999" name="field_maxlen" value="' . $field_data['field_maxlen'] . '" />'), |
67 | 3 => array('TITLE' => $this->user->lang['FIELD_VALIDATION'], 'FIELD' => '<select name="field_validation">' . $this->validate_options($field_data) . '</select>'), |
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', |
80 | 'field_minlen' => 0, |
81 | 'field_maxlen' => 1000, |
82 | 'field_validation' => '.*', |
83 | 'field_novalue' => '', |
84 | 'field_default_value' => '', |
85 | ); |
86 | } |
87 | |
88 | /** |
89 | * {@inheritDoc} |
90 | */ |
91 | public function get_profile_field($profile_row) |
92 | { |
93 | $var_name = 'pf_' . $profile_row['field_ident']; |
94 | return $this->request->variable($var_name, (string) $profile_row['field_default_value'], true); |
95 | } |
96 | |
97 | /** |
98 | * {@inheritDoc} |
99 | */ |
100 | public function validate_profile_field(&$field_value, $field_data) |
101 | { |
102 | return $this->validate_string_profile_field('text', $field_value, $field_data); |
103 | } |
104 | |
105 | /** |
106 | * {@inheritDoc} |
107 | */ |
108 | public function generate_field($profile_row, $preview_options = false) |
109 | { |
110 | $field_length = explode('|', $profile_row['field_length']); |
111 | $profile_row['field_rows'] = $field_length[0]; |
112 | $profile_row['field_cols'] = $field_length[1]; |
113 | $profile_row['field_ident'] = (isset($profile_row['var_name'])) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; |
114 | $field_ident = $profile_row['field_ident']; |
115 | $default_value = $profile_row['lang_default_value']; |
116 | |
117 | $profile_row['field_value'] = ($this->request->is_set($field_ident)) ? $this->request->variable($field_ident, $default_value, true) : ((!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) ? $default_value : $this->user->profile_fields[$field_ident]); |
118 | |
119 | $this->template->assign_block_vars('text', array_change_key_case($profile_row, CASE_UPPER)); |
120 | } |
121 | |
122 | /** |
123 | * {@inheritDoc} |
124 | */ |
125 | public function get_database_column_type() |
126 | { |
127 | return 'MTEXT'; |
128 | } |
129 | |
130 | /** |
131 | * {@inheritDoc} |
132 | */ |
133 | public function get_language_options($field_data) |
134 | { |
135 | $options = array( |
136 | 'lang_name' => 'string', |
137 | ); |
138 | |
139 | if ($field_data['lang_explain']) |
140 | { |
141 | $options['lang_explain'] = 'text'; |
142 | } |
143 | |
144 | if (strlen($field_data['lang_default_value'])) |
145 | { |
146 | $options['lang_default_value'] = 'text'; |
147 | } |
148 | |
149 | return $options; |
150 | } |
151 | |
152 | /** |
153 | * {@inheritDoc} |
154 | */ |
155 | public function get_excluded_options($key, $action, $current_value, &$field_data, $step) |
156 | { |
157 | if ($step == 2 && $key == 'field_length') |
158 | { |
159 | if ($this->request->is_set('rows')) |
160 | { |
161 | $field_data['rows'] = $this->request->variable('rows', 0); |
162 | $field_data['columns'] = $this->request->variable('columns', 0); |
163 | $current_value = $field_data['rows'] . '|' . $field_data['columns']; |
164 | } |
165 | else |
166 | { |
167 | $row_col = explode('|', $current_value); |
168 | $field_data['rows'] = $row_col[0]; |
169 | $field_data['columns'] = $row_col[1]; |
170 | } |
171 | |
172 | return $current_value; |
173 | } |
174 | |
175 | return parent::get_excluded_options($key, $action, $current_value, $field_data, $step); |
176 | } |
177 | |
178 | /** |
179 | * {@inheritDoc} |
180 | */ |
181 | public function prepare_hidden_fields($step, $key, $action, &$field_data) |
182 | { |
183 | if ($key == 'field_length' && $this->request->is_set('rows')) |
184 | { |
185 | $field_data['rows'] = $this->request->variable('rows', 0); |
186 | $field_data['columns'] = $this->request->variable('columns', 0); |
187 | return $field_data['rows'] . '|' . $field_data['columns']; |
188 | } |
189 | |
190 | return parent::prepare_hidden_fields($step, $key, $action, $field_data); |
191 | } |
192 | |
193 | /** |
194 | * {@inheritDoc} |
195 | */ |
196 | public function display_options(&$template_vars, &$field_data) |
197 | { |
198 | $template_vars = array_merge($template_vars, array( |
199 | 'S_TEXT' => true, |
200 | 'L_DEFAULT_VALUE_EXPLAIN' => $this->user->lang['TEXT_DEFAULT_VALUE_EXPLAIN'], |
201 | 'LANG_DEFAULT_VALUE' => $field_data['lang_default_value'], |
202 | )); |
203 | } |
204 | } |