From: Paul R. <pri...@us...> - 2004-08-20 23:00:51
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20221 Modified Files: custom_field_api.php filter_api.php Log Message: updates for #4009 from RJelinek Index: custom_field_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/custom_field_api.php,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- custom_field_api.php 3 Aug 2004 23:45:57 -0000 1.38 +++ custom_field_api.php 20 Aug 2004 23:00:39 -0000 1.39 @@ -686,7 +686,7 @@ custom_field_ensure_exists( $p_field_id ); $t_custom_field_table = config_get( 'mantis_custom_field_table' ); - $query = "SELECT access_level_r, default_value + $query = "SELECT access_level_r, default_value, type FROM $t_custom_field_table WHERE id='$c_field_id'"; $result = db_query( $query ); @@ -707,7 +707,7 @@ $result = db_query( $query ); if( db_num_rows( $result ) > 0 ) { - return db_result( $result ); + return custom_field_database_to_value( db_result( $result ) , $row['type'] ); } else { return $t_default_value; } @@ -750,7 +750,7 @@ $t_custom_field_table = config_get( 'mantis_custom_field_table' ); $t_custom_field_string_table = config_get( 'mantis_custom_field_string_table' ); - $query = "SELECT f.name, f.type, f.access_level_r, f.default_value, s.value + $query = "SELECT f.name, f.type, f.access_level_r, f.default_value, f.type, s.value FROM $t_custom_field_project_table AS p, $t_custom_field_table AS f LEFT JOIN $t_custom_field_string_table AS s ON p.field_id=s.field_id AND s.bug_id='$c_bug_id' @@ -769,7 +769,7 @@ if( is_null( $row['value'] ) ) { $t_value = $row['default_value']; } else { - $t_value = $row['value']; + $t_value = custom_field_database_to_value( $row['value'], $row['type'] ); } $t_custom_fields[$row['name']] = array( 'type' => $row['type'], @@ -913,13 +913,46 @@ # Data Modification #=================================== + # -------------------- + # Convert the value to save it into the database, depending of the type + # return value for database + function custom_field_value_to_database( $p_value, $p_type ) { + switch ($p_type) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + if ( '' == $p_value ) { + $result = ''; + } else { + $result = '|' . $p_value . '|'; + } + break; + default: + $result = $p_value; + } + return $result; + } + + # -------------------- + # Convert the database-value to value, depending of the type + # return value for further operation + function custom_field_database_to_value( $p_value, $p_type ) { + switch ($p_type) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + $result = str_replace( '||', '', '|' . $p_value . '|' ); + break; + default: + $result = $p_value; + } + return $result; + } + # -------------------- # Set the value of a custom field for a given bug # return true on success, false on failure function custom_field_set_value( $p_field_id, $p_bug_id, $p_value ) { $c_field_id = db_prepare_int( $p_field_id ); $c_bug_id = db_prepare_int( $p_bug_id ); - $c_value = db_prepare_string( $p_value ); custom_field_ensure_exists( $p_field_id ); @@ -940,6 +973,8 @@ $t_length_max = $row['length_max']; $t_default_value = $row['default_value']; + $c_value = db_prepare_string( custom_field_value_to_database( $p_value, $t_type ) ); + # check for valid value if ( !is_blank( $t_valid_regexp ) ) { if ( !ereg( $t_valid_regexp, $p_value ) ) { Index: filter_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/filter_api.php,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- filter_api.php 8 Aug 2004 15:19:37 -0000 1.54 +++ filter_api.php 20 Aug 2004 23:00:39 -0000 1.55 @@ -418,6 +418,7 @@ $t_any_found = true; } if ( !$t_any_found ) { + $t_def = custom_field_get_definition( $t_cfid ); $t_table_name = $t_custom_field_string_table . '_' . $t_cfid; array_push( $t_join_clauses, "LEFT JOIN $t_custom_field_string_table as $t_table_name ON $t_table_name.bug_id = $t_bug_table.id" ); foreach( $t_filter['custom_fields'][$t_cfid] as $t_filter_member ) { @@ -432,8 +433,19 @@ $t_custom_where_clause .= ' OR '; } - $t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value = '"; - $t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) ) . "' )"; + $t_custom_where_clause .= "( $t_table_name.field_id = $t_cfid AND $t_table_name.value "; + switch( $t_def['type'] ) { + case CUSTOM_FIELD_TYPE_MULTILIST: + case CUSTOM_FIELD_TYPE_CHECKBOX: + $t_custom_where_clause .= "LIKE '%"; + $t_custom_where_clause_closing = "%' )"; + break; + default: + $t_custom_where_clause .= "= '"; + $t_custom_where_clause_closing = "' )"; + } + $t_custom_where_clause .= db_prepare_string( trim( $t_filter_member ) ); + $t_custom_where_clause .= $t_custom_where_clause_closing; } } if ( !is_blank( $t_custom_where_clause ) ) { |