1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-02-08 01:35:17 +01:00

[ticket/10965] Introduce a new profile field option to display no value

By default the 3.0.10 behaviour is kept, profile fields will not show up
if they have either not yet been selected or in case of an optional
dropdown field if the novalue option was selected.

PHPBB3-10965
This commit is contained in:
Nils Adermann 2012-07-17 18:48:10 +02:00
parent 55aaa596d7
commit 10172887fd
13 changed files with 46 additions and 13 deletions

View File

@ -63,6 +63,10 @@
<dt><label for="field_required">{L_REQUIRED_FIELD}:</label><br /><span>{L_REQUIRED_FIELD_EXPLAIN}</span></dt>
<dd><input type="checkbox" class="radio" id="field_required" name="field_required" value="1"<!-- IF S_FIELD_REQUIRED --> checked="checked"<!-- ENDIF --> /></dd>
</dl>
<dl>
<dt><label for="field_show_novalue">{L_SHOW_NOVALUE_FIELD}:</label><br /><span>{L_SHOW_NOVALUE_FIELD_EXPLAIN}</span></dt>
<dd><input type="checkbox" class="radio" id="field_show_novalue" name="field_show_novalue" value="1"<!-- IF S_FIELD_SHOW_NOVALUE --> checked="checked"<!-- ENDIF --> /></dd>
</dl>
<dl>
<dt><label for="field_hide">{L_HIDE_PROFILE_FIELD}:</label><br /><span>{L_HIDE_PROFILE_FIELD_EXPLAIN}</span></dt>
<dd><input type="checkbox" class="radio" id="field_hide" name="field_hide" value="1"<!-- IF S_FIELD_HIDE --> checked="checked"<!-- ENDIF --> /></dd>

View File

@ -1448,6 +1448,7 @@ function get_schema_struct()
'field_default_value' => array('VCHAR_UNI', ''),
'field_validation' => array('VCHAR_UNI:20', ''),
'field_required' => array('BOOL', 0),
'field_show_novalue' => array('BOOL', 0),
'field_show_on_reg' => array('BOOL', 0),
'field_show_on_vt' => array('BOOL', 0),
'field_show_profile' => array('BOOL', 0),

View File

@ -365,6 +365,7 @@ class acp_profile
$field_row = array_merge($default_values[$field_type], array(
'field_ident' => str_replace(' ', '_', utf8_clean_string(request_var('field_ident', '', true))),
'field_required' => 0,
'field_show_novalue'=> 0,
'field_hide' => 0,
'field_show_profile'=> 0,
'field_no_view' => 0,
@ -380,7 +381,7 @@ class acp_profile
// $exclude contains the data we gather in each step
$exclude = array(
1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_vt', 'field_required', 'field_hide', 'field_show_profile', 'field_no_view'),
1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_vt', 'field_required', 'field_show_novalue', 'field_hide', 'field_show_profile', 'field_no_view'),
2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
);
@ -405,6 +406,7 @@ class acp_profile
// Visibility Options...
$visibility_ary = array(
'field_required',
'field_show_novalue',
'field_show_on_reg',
'field_show_on_vt',
'field_show_profile',
@ -757,6 +759,7 @@ class acp_profile
$template->assign_vars(array(
'S_STEP_ONE' => true,
'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
'S_FIELD_SHOW_NOVALUE'=> ($cp->vars['field_show_novalue']) ? true : false,
'S_SHOW_ON_REG' => ($cp->vars['field_show_on_reg']) ? true : false,
'S_SHOW_ON_VT' => ($cp->vars['field_show_on_vt']) ? true : false,
'S_FIELD_HIDE' => ($cp->vars['field_hide']) ? true : false,
@ -1073,6 +1076,7 @@ class acp_profile
'field_default_value' => $cp->vars['field_default_value'],
'field_validation' => $cp->vars['field_validation'],
'field_required' => $cp->vars['field_required'],
'field_show_novalue' => $cp->vars['field_show_novalue'],
'field_show_on_reg' => $cp->vars['field_show_on_reg'],
'field_show_on_vt' => $cp->vars['field_show_on_vt'],
'field_hide' => $cp->vars['field_hide'],

View File

@ -122,7 +122,7 @@ class custom_profile
case FIELD_BOOL:
$field_value = (bool) $field_value;
if (!$field_value && $field_data['field_required'])
{
return 'FIELD_REQUIRED';
@ -134,7 +134,7 @@ class custom_profile
{
return false;
}
$field_value = (int) $field_value;
if ($field_value < $field_data['field_minlen'])
@ -521,7 +521,7 @@ class custom_profile
switch ($this->profile_types[$field_type])
{
case 'int':
if ($value === '')
if ($value === '' && !$ident_ary['data']['field_show_novalue'])
{
return NULL;
}
@ -530,7 +530,7 @@ class custom_profile
case 'string':
case 'text':
if (!$value)
if (!$value && !$ident_ary['data']['field_show_novalue'])
{
return NULL;
}
@ -548,7 +548,7 @@ class custom_profile
$month = (isset($date[1])) ? (int) $date[1] : 0;
$year = (isset($date[2])) ? (int) $date[2] : 0;
if (!$day && !$month && !$year)
if (!$day && !$month && !$year && !$ident_ary['data']['field_show_novalue'])
{
return NULL;
}
@ -571,12 +571,7 @@ class custom_profile
$this->get_option_lang($field_id, $lang_id, FIELD_DROPDOWN, false);
}
// If a dropdown field is required, users
// cannot choose the "no value" option.
// They must choose one of the other options.
// Therefore, here we treat a value equal to
// the "no value" as a lack of value, i.e. NULL.
if ($value == $ident_ary['data']['field_novalue'] && $ident_ary['data']['field_required'])
if ($value == $ident_ary['data']['field_novalue'] && !$ident_ary['data']['field_show_novalue'])
{
return NULL;
}
@ -586,7 +581,14 @@ class custom_profile
// User not having a value assigned
if (!isset($this->options_lang[$field_id][$lang_id][$value]))
{
return NULL;
if ($ident_ary['data']['field_show_novalue'])
{
$value = $ident_ary['data']['field_novalue'];
}
else
{
return NULL;
}
}
return $this->options_lang[$field_id][$lang_id][$value];
@ -600,6 +602,11 @@ class custom_profile
$this->get_option_lang($field_id, $lang_id, FIELD_BOOL, false);
}
if (!$value && $ident_ary['data']['field_show_novalue'])
{
$value = $ident_ary['data']['field_default_value'];
}
if ($ident_ary['data']['field_length'] == 1)
{
return (isset($this->options_lang[$field_id][$lang_id][(int) $value])) ? $this->options_lang[$field_id][$lang_id][(int) $value] : NULL;

View File

@ -995,6 +995,14 @@ function database_update_info()
'3.0.10-RC3' => array(),
// No changes from 3.0.10 to 3.0.11-RC1
'3.0.10' => array(),
// Changes from 3.0.11-RC1 to 3.0.11-RC2
'3.0.5' => array(
'add_columns' => array(
PROFILE_FIELDS_TABLE => array(
'field_show_novalue' => array('BOOL', 0),
),
),
),
/** @todo DROP LOGIN_ATTEMPT_TABLE.attempt_id in 3.0.12-RC1 */
);

View File

@ -807,6 +807,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value VARCHAR(255) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE,
field_validation VARCHAR(20) CHARACTER SET UTF8 DEFAULT '' NOT NULL COLLATE UNICODE,
field_required INTEGER DEFAULT 0 NOT NULL,
field_show_novalue INTEGER DEFAULT 0 NOT NULL,
field_show_on_reg INTEGER DEFAULT 0 NOT NULL,
field_show_on_vt INTEGER DEFAULT 0 NOT NULL,
field_show_profile INTEGER DEFAULT 0 NOT NULL,

View File

@ -974,6 +974,7 @@ CREATE TABLE [phpbb_profile_fields] (
[field_default_value] [varchar] (255) DEFAULT ('') NOT NULL ,
[field_validation] [varchar] (20) DEFAULT ('') NOT NULL ,
[field_required] [int] DEFAULT (0) NOT NULL ,
[field_show_novalue] [int] DEFAULT (0) NOT NULL ,
[field_show_on_reg] [int] DEFAULT (0) NOT NULL ,
[field_show_on_vt] [int] DEFAULT (0) NOT NULL ,
[field_show_profile] [int] DEFAULT (0) NOT NULL ,

View File

@ -571,6 +571,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value blob NOT NULL,
field_validation varbinary(60) DEFAULT '' NOT NULL,
field_required tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_novalue tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_on_reg tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_on_vt tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_profile tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,

View File

@ -571,6 +571,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value varchar(255) DEFAULT '' NOT NULL,
field_validation varchar(20) DEFAULT '' NOT NULL,
field_required tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_novalue tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_on_reg tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_on_vt tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,
field_show_profile tinyint(1) UNSIGNED DEFAULT '0' NOT NULL,

View File

@ -1085,6 +1085,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value varchar2(765) DEFAULT '' ,
field_validation varchar2(60) DEFAULT '' ,
field_required number(1) DEFAULT '0' NOT NULL,
field_show_novalue number(1) DEFAULT '0' NOT NULL,
field_show_on_reg number(1) DEFAULT '0' NOT NULL,
field_show_on_vt number(1) DEFAULT '0' NOT NULL,
field_show_profile number(1) DEFAULT '0' NOT NULL,

View File

@ -761,6 +761,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value varchar(255) DEFAULT '' NOT NULL,
field_validation varchar(20) DEFAULT '' NOT NULL,
field_required INT2 DEFAULT '0' NOT NULL CHECK (field_required >= 0),
field_show_novalue INT2 DEFAULT '0' NOT NULL CHECK (field_show_novalue >= 0),
field_show_on_reg INT2 DEFAULT '0' NOT NULL CHECK (field_show_on_reg >= 0),
field_show_on_vt INT2 DEFAULT '0' NOT NULL CHECK (field_show_on_vt >= 0),
field_show_profile INT2 DEFAULT '0' NOT NULL CHECK (field_show_profile >= 0),

View File

@ -554,6 +554,7 @@ CREATE TABLE phpbb_profile_fields (
field_default_value varchar(255) NOT NULL DEFAULT '',
field_validation varchar(20) NOT NULL DEFAULT '',
field_required INTEGER UNSIGNED NOT NULL DEFAULT '0',
field_show_novalue INTEGER UNSIGNED NOT NULL DEFAULT '0',
field_show_on_reg INTEGER UNSIGNED NOT NULL DEFAULT '0',
field_show_on_vt INTEGER UNSIGNED NOT NULL DEFAULT '0',
field_show_profile INTEGER UNSIGNED NOT NULL DEFAULT '0',

View File

@ -131,6 +131,8 @@ $lang = array_merge($lang, array(
'SAVE' => 'Save',
'SECOND_OPTION' => 'Second option',
'SHOW_NOVALUE_FIELD' => 'Show field if no value was selected',
'SHOW_NOVALUE_FIELD_EXPLAIN' => 'Determines if the profile field should be displayed if no value was selected for optional fields or if no value has been selected yet for required fields.',
'STEP_1_EXPLAIN_CREATE' => 'Here you can enter the first basic parameters of your new profile field. This information is needed for the second step where youll be able to set remaining options and tweak your profile field further.',
'STEP_1_EXPLAIN_EDIT' => 'Here you can change the basic parameters of your profile field. The relevant options are re-calculated within the second step.',
'STEP_1_TITLE_CREATE' => 'Add profile field',