Skip to content

Commit

Permalink
Fix #6626 - Add text area custom field type. Add column to handle long
Browse files Browse the repository at this point in the history
text input.  If the custom field type is TEXTAREA values are inserted into
the text field.  Otherwise they are inserted into the existing value field.
Filters for TEXTAREA custom fields are not populated with existing data. A
text box is provided and a LIKE query is performed.
  • Loading branch information
Daryn Warriner committed Aug 25, 2010
1 parent 6b5e037 commit 839f1d6
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
2 changes: 2 additions & 0 deletions admin/schema.php
Expand Up @@ -609,3 +609,5 @@ function installer_db_now() {
$upgrade[] = Array( 'CreateIndexSQL', Array( 'idx_email_id', db_get_table( 'email' ), 'email_id', array( 'DROP' ) ), Array( 'db_index_exists', Array( db_get_table( 'email' ), 'idx_email_id') ) );
$upgrade[] = Array( 'UpdateFunction', 'correct_multiselect_custom_fields_db_format' );
$upgrade[] = Array( 'UpdateFunction', "stored_filter_migrate" );
$upgrade[] = Array( 'AddColumnSQL', Array( db_get_table( 'custom_field_string' ), "
text XL NULL DEFAULT NULL " ) );
2 changes: 1 addition & 1 deletion config_defaults_inc.php
Expand Up @@ -3041,7 +3041,7 @@
*
* @global string $g_custom_field_type_enum_string
*/
$g_custom_field_type_enum_string = '0:string,1:numeric,2:float,3:enum,4:email,5:checkbox,6:list,7:multiselection list,8:date,9:radio';
$g_custom_field_type_enum_string = '0:string,1:numeric,2:float,3:enum,4:email,5:checkbox,6:list,7:multiselection list,8:date,9:radio,10:textarea';

/*********************************
* MantisBT Javascript Variables *
Expand Down
24 changes: 24 additions & 0 deletions core/cfdefs/cfdef_standard.php
Expand Up @@ -31,6 +31,20 @@
'#function_string_value_for_email' => null,
);

$g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_TEXTAREA] = array (
'#display_possible_values' => TRUE,
'#display_valid_regexp' => TRUE,
'#display_length_min' => TRUE,
'#display_length_max' => TRUE,
'#display_default_value' => TRUE,
'#function_return_distinct_values' => null,
'#function_value_to_database' => null,
'#function_database_to_value' => null,
'#function_print_input' => 'cfdef_input_textarea',
'#function_string_value' => null,
'#function_string_value_for_email' => null,
);

$g_custom_field_type_definition[ CUSTOM_FIELD_TYPE_NUMERIC ] = array (
'#display_possible_values' => TRUE,
'#display_valid_regexp' => TRUE,
Expand Down Expand Up @@ -300,6 +314,16 @@ function cfdef_input_textbox($p_field_def, $t_custom_field_value) {
echo ' value="' . string_attribute( $t_custom_field_value ) .'"></input>';
}

function cfdef_input_textarea($p_field_def, $t_custom_field_value) {
echo '<textarea ', helper_get_tab_index(), ' name="custom_field_' . $p_field_def['id'] . '"';
if( 0 < $p_field_def['length_max'] ) {
echo ' maxlength="' . $p_field_def['length_max'] . '"';
} else {
echo ' maxlength="255"';
}
echo 'cols="70" rows="8">' . $t_custom_field_value .'</textarea>';
}

/**
* Prints the controls for the date selector.
*
Expand Down
1 change: 1 addition & 0 deletions core/constant_inc.php
Expand Up @@ -419,6 +419,7 @@
define( 'CUSTOM_FIELD_TYPE_MULTILIST', 7 );
define( 'CUSTOM_FIELD_TYPE_DATE', 8 );
define( 'CUSTOM_FIELD_TYPE_RADIO', 9 );
define( 'CUSTOM_FIELD_TYPE_TEXTAREA', 10 );

# Meta filter values
define( 'META_FILTER_MYSELF', -1 );
Expand Down
15 changes: 10 additions & 5 deletions core/custom_field_api.php
Expand Up @@ -62,6 +62,7 @@
# *******************************************

$g_custom_field_types[CUSTOM_FIELD_TYPE_STRING] = 'standard';
$g_custom_field_types[CUSTOM_FIELD_TYPE_TEXTAREA] = 'standard';
$g_custom_field_types[CUSTOM_FIELD_TYPE_NUMERIC] = 'standard';
$g_custom_field_types[CUSTOM_FIELD_TYPE_FLOAT] = 'standard';
$g_custom_field_types[CUSTOM_FIELD_TYPE_ENUM] = 'standard';
Expand Down Expand Up @@ -1008,8 +1009,10 @@ function custom_field_get_value( $p_field_id, $p_bug_id ) {
return false;
}

$t_value_field = ( $row['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value' );

$t_custom_field_string_table = db_get_table( 'custom_field_string' );
$query = "SELECT value
$query = "SELECT $t_value_field
FROM $t_custom_field_string_table
WHERE bug_id=" . db_param() . " AND
field_id=" . db_param();
Expand Down Expand Up @@ -1351,25 +1354,27 @@ function custom_field_set_value( $p_field_id, $p_bug_id, $p_value, $p_log_insert
$t_type = custom_field_get_field( $p_field_id, 'type' );
$t_custom_field_string_table = db_get_table( 'custom_field_string' );

$t_value_field = ( $t_type == CUSTOM_FIELD_TYPE_TEXTAREA ) ? 'text' : 'value';

# Determine whether an existing value needs to be updated or a new value inserted
$query = "SELECT value
$query = "SELECT $t_value_field
FROM $t_custom_field_string_table
WHERE field_id=" . db_param() . " AND
bug_id=" . db_param();
$result = db_query_bound( $query, Array( $c_field_id, $c_bug_id ) );

if( db_num_rows( $result ) > 0 ) {
$query = "UPDATE $t_custom_field_string_table
SET value=" . db_param() . "
SET $t_value_field=" . db_param() . "
WHERE field_id=" . db_param() . " AND
bug_id=" . db_param();
db_query_bound( $query, Array( custom_field_value_to_database( $p_value, $t_type ), $c_field_id, $c_bug_id ) );

$row = db_fetch_array( $result );
history_log_event_direct( $c_bug_id, $t_name, custom_field_database_to_value( $row['value'], $t_type ), $p_value );
history_log_event_direct( $c_bug_id, $t_name, custom_field_database_to_value( $row[$t_value_field], $t_type ), $p_value );
} else {
$query = "INSERT INTO $t_custom_field_string_table
( field_id, bug_id, value )
( field_id, bug_id, $t_value_field )
VALUES
( " . db_param() . ', ' . db_param() . ', ' . db_param() . ')';
db_query_bound( $query, Array( $c_field_id, $c_bug_id, custom_field_value_to_database( $p_value, $t_type ) ) );
Expand Down
11 changes: 9 additions & 2 deletions core/filter_api.php
Expand Up @@ -938,10 +938,11 @@ function filter_get_query_sort_data( &$p_filter, $p_show_sticky, $p_query_clause
if( strpos( $c_sort, 'custom_' ) === 0 ) {
$t_custom_field = utf8_substr( $c_sort, utf8_strlen( 'custom_' ) );
$t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );

$t_def = custom_field_get_definition( $t_custom_field_id );
$t_value_field = ( $t_def['type'] == CUSTOM_FIELD_TYPE_TEXTAREA ? 'text' : 'value' );
$c_cf_alias = str_replace( ' ', '_', $t_custom_field );
$t_cf_table_alias = $t_custom_field_string_table . '_' . $t_custom_field_id;
$t_cf_select = "$t_cf_table_alias.value $c_cf_alias";
$t_cf_select = "$t_cf_table_alias.$t_value_field $c_cf_alias";

# check to be sure this field wasn't already added to the query.
if( !in_array( $t_cf_select, $p_query_clauses['select'] ) ) {
Expand Down Expand Up @@ -1924,6 +1925,10 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p
$t_where_params[] = '%|' . $t_filter_member . '|%';
array_push( $t_filter_array, db_helper_like( "$t_table_name.value" ) );
break;
case CUSTOM_FIELD_TYPE_TEXTAREA:
$t_where_params[] = '%' . $t_filter_member . '%';
array_push( $t_filter_array, db_helper_like( "$t_table_name.text" ) );
break;
default:
array_push( $t_filter_array, "$t_table_name.value = '" . db_prepare_string( $t_filter_member ) . "'" );
}
Expand Down Expand Up @@ -4029,6 +4034,8 @@ function print_filter_custom_field( $p_field_id ) {
} else if( isset( $t_accessible_custom_fields_names[$j] ) ) {
if( $t_accessible_custom_fields_types[$j] == CUSTOM_FIELD_TYPE_DATE ) {
print_filter_custom_field_date( $j, $p_field_id );
} else if( $t_accessible_custom_fields_types[$j] == CUSTOM_FIELD_TYPE_TEXTAREA ) {
echo '<input type="text" name="custom_field_', $p_field_id, '" size="10" value="" />';
} else {
echo '<select ' . $t_select_modifier . ' name="custom_field_' . $p_field_id . '[]">';
echo '<option value="' . META_FILTER_ANY . '" ';
Expand Down
2 changes: 1 addition & 1 deletion lang/strings_english.txt
Expand Up @@ -1227,7 +1227,7 @@ If you requested this verification, visit the following URL to change your passw
'linked_projects_label' => 'Linked Projects:',
'custom_field_sequence' => 'Sequence',
'custom_field_sequence_label' => 'Sequence:',
'custom_field_type_enum_string' => '0:String,1:Numeric,2:Float,3:Enumeration,4:E-mail,5:Checkbox,6:List,7:Multiselection list,8:Date,9:Radio',
'custom_field_type_enum_string' => '0:String,1:Numeric,2:Float,3:Enumeration,4:E-mail,5:Checkbox,6:List,7:Multiselection list,8:Date,9:Radio,10:Textarea',
'confirm_used_custom_field_deletion' => 'This field is currently linked to at least one project. If you continue all values for this field will be permanently deleted. This action cannot be undone. If you do not want to delete this field, hit the Back button in your browser. To proceed, click the button below',
'confirm_custom_field_deletion' => 'Are you sure you want to delete this custom field and all associated values?',
'field_delete_button' => 'Delete Field',
Expand Down

0 comments on commit 839f1d6

Please sign in to comment.