summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Field/ChoiceInterface.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Bugzilla/Field/ChoiceInterface.pm')
-rw-r--r--Bugzilla/Field/ChoiceInterface.pm227
1 files changed, 118 insertions, 109 deletions
diff --git a/Bugzilla/Field/ChoiceInterface.pm b/Bugzilla/Field/ChoiceInterface.pm
index bcfd75578..207ac9cb5 100644
--- a/Bugzilla/Field/ChoiceInterface.pm
+++ b/Bugzilla/Field/ChoiceInterface.pm
@@ -26,14 +26,19 @@ sub FIELD_NAME { return $_[0]->DB_TABLE; }
####################
sub _check_if_controller {
- my $self = shift;
- my $vis_fields = $self->controls_visibility_of_fields;
- my $values = $self->controlled_values_array;
- if (@$vis_fields || @$values) {
- ThrowUserError('fieldvalue_is_controller',
- { value => $self, fields => [map($_->name, @$vis_fields)],
- vals => $self->controlled_values });
- }
+ my $self = shift;
+ my $vis_fields = $self->controls_visibility_of_fields;
+ my $values = $self->controlled_values_array;
+ if (@$vis_fields || @$values) {
+ ThrowUserError(
+ 'fieldvalue_is_controller',
+ {
+ value => $self,
+ fields => [map($_->name, @$vis_fields)],
+ vals => $self->controlled_values
+ }
+ );
+ }
}
@@ -42,145 +47,149 @@ sub _check_if_controller {
#############
sub is_active { return $_[0]->{'isactive'}; }
-sub sortkey { return $_[0]->{'sortkey'}; }
+sub sortkey { return $_[0]->{'sortkey'}; }
sub bug_count {
- my $self = shift;
- return $self->{bug_count} if defined $self->{bug_count};
- my $dbh = Bugzilla->dbh;
- my $fname = $self->field->name;
- my $count;
- if ($self->field->type == FIELD_TYPE_MULTI_SELECT) {
- $count = $dbh->selectrow_array("SELECT COUNT(*) FROM bug_$fname
- WHERE value = ?", undef, $self->name);
- }
- else {
- $count = $dbh->selectrow_array("SELECT COUNT(*) FROM bugs
- WHERE $fname = ?",
- undef, $self->name);
- }
- $self->{bug_count} = $count;
- return $count;
+ my $self = shift;
+ return $self->{bug_count} if defined $self->{bug_count};
+ my $dbh = Bugzilla->dbh;
+ my $fname = $self->field->name;
+ my $count;
+ if ($self->field->type == FIELD_TYPE_MULTI_SELECT) {
+ $count = $dbh->selectrow_array(
+ "SELECT COUNT(*) FROM bug_$fname
+ WHERE value = ?", undef, $self->name
+ );
+ }
+ else {
+ $count = $dbh->selectrow_array(
+ "SELECT COUNT(*) FROM bugs
+ WHERE $fname = ?", undef, $self->name
+ );
+ }
+ $self->{bug_count} = $count;
+ return $count;
}
sub field {
- my $invocant = shift;
- my $class = ref $invocant || $invocant;
- my $cache = Bugzilla->request_cache;
- # This is just to make life easier for subclasses. Our auto-generated
- # subclasses from Bugzilla::Field::Choice->type() already have this set.
- $cache->{"field_$class"} ||=
- new Bugzilla::Field({ name => $class->FIELD_NAME });
- return $cache->{"field_$class"};
+ my $invocant = shift;
+ my $class = ref $invocant || $invocant;
+ my $cache = Bugzilla->request_cache;
+
+ # This is just to make life easier for subclasses. Our auto-generated
+ # subclasses from Bugzilla::Field::Choice->type() already have this set.
+ $cache->{"field_$class"} ||= new Bugzilla::Field({name => $class->FIELD_NAME});
+ return $cache->{"field_$class"};
}
sub is_default {
- my $self = shift;
- my $name = $self->DEFAULT_MAP->{$self->field->name};
- # If it doesn't exist in DEFAULT_MAP, then there is no parameter
- # related to this field.
- return 0 unless $name;
- return ($self->name eq Bugzilla->params->{$name}) ? 1 : 0;
+ my $self = shift;
+ my $name = $self->DEFAULT_MAP->{$self->field->name};
+
+ # If it doesn't exist in DEFAULT_MAP, then there is no parameter
+ # related to this field.
+ return 0 unless $name;
+ return ($self->name eq Bugzilla->params->{$name}) ? 1 : 0;
}
sub is_static {
- my $self = shift;
- # If we need to special-case Resolution for *anything* else, it should
- # get its own subclass.
- if ($self->field->name eq 'resolution') {
- return grep($_ eq $self->name, ('', 'FIXED', 'DUPLICATE'))
- ? 1 : 0;
- }
- elsif ($self->field->custom) {
- return $self->name eq '---' ? 1 : 0;
- }
- return 0;
+ my $self = shift;
+
+ # If we need to special-case Resolution for *anything* else, it should
+ # get its own subclass.
+ if ($self->field->name eq 'resolution') {
+ return grep($_ eq $self->name, ('', 'FIXED', 'DUPLICATE')) ? 1 : 0;
+ }
+ elsif ($self->field->custom) {
+ return $self->name eq '---' ? 1 : 0;
+ }
+ return 0;
}
sub controls_visibility_of_fields {
- my $self = shift;
- my $dbh = Bugzilla->dbh;
+ my $self = shift;
+ my $dbh = Bugzilla->dbh;
- if (!$self->{controls_visibility_of_fields}) {
- my $ids = $dbh->selectcol_arrayref(
- "SELECT id FROM fielddefs
+ if (!$self->{controls_visibility_of_fields}) {
+ my $ids = $dbh->selectcol_arrayref(
+ "SELECT id FROM fielddefs
INNER JOIN field_visibility
ON fielddefs.id = field_visibility.field_id
- WHERE value_id = ? AND visibility_field_id = ?", undef,
- $self->id, $self->field->id);
+ WHERE value_id = ? AND visibility_field_id = ?", undef, $self->id,
+ $self->field->id
+ );
- $self->{controls_visibility_of_fields} =
- Bugzilla::Field->new_from_list($ids);
- }
+ $self->{controls_visibility_of_fields} = Bugzilla::Field->new_from_list($ids);
+ }
- return $self->{controls_visibility_of_fields};
+ return $self->{controls_visibility_of_fields};
}
sub visibility_value {
- my $self = shift;
- if ($self->{visibility_value_id}) {
- require Bugzilla::Field::Choice;
- $self->{visibility_value} ||=
- Bugzilla::Field::Choice->type($self->field->value_field)->new(
- $self->{visibility_value_id});
- }
- return $self->{visibility_value};
+ my $self = shift;
+ if ($self->{visibility_value_id}) {
+ require Bugzilla::Field::Choice;
+ $self->{visibility_value}
+ ||= Bugzilla::Field::Choice->type($self->field->value_field)
+ ->new($self->{visibility_value_id});
+ }
+ return $self->{visibility_value};
}
sub controlled_values {
- my $self = shift;
- return $self->{controlled_values} if defined $self->{controlled_values};
- my $fields = $self->field->controls_values_of;
- my %controlled_values;
- require Bugzilla::Field::Choice;
- foreach my $field (@$fields) {
- $controlled_values{$field->name} =
- Bugzilla::Field::Choice->type($field)
- ->match({ visibility_value_id => $self->id });
- }
- $self->{controlled_values} = \%controlled_values;
- return $self->{controlled_values};
+ my $self = shift;
+ return $self->{controlled_values} if defined $self->{controlled_values};
+ my $fields = $self->field->controls_values_of;
+ my %controlled_values;
+ require Bugzilla::Field::Choice;
+ foreach my $field (@$fields) {
+ $controlled_values{$field->name} = Bugzilla::Field::Choice->type($field)
+ ->match({visibility_value_id => $self->id});
+ }
+ $self->{controlled_values} = \%controlled_values;
+ return $self->{controlled_values};
}
sub controlled_values_array {
- my ($self) = @_;
- my $values = $self->controlled_values;
- return [map { @{ $values->{$_} } } keys %$values];
+ my ($self) = @_;
+ my $values = $self->controlled_values;
+ return [map { @{$values->{$_}} } keys %$values];
}
sub is_visible_on_bug {
- my ($self, $bug) = @_;
+ my ($self, $bug) = @_;
- # Values currently set on the bug are always shown.
- return 1 if $self->is_set_on_bug($bug);
+ # Values currently set on the bug are always shown.
+ return 1 if $self->is_set_on_bug($bug);
- # Inactive values are, otherwise, never shown.
- return 0 if !$self->is_active;
+ # Inactive values are, otherwise, never shown.
+ return 0 if !$self->is_active;
- # Values without a visibility value are, otherwise, always shown.
- my $visibility_value = $self->visibility_value;
- return 1 if !$visibility_value;
+ # Values without a visibility value are, otherwise, always shown.
+ my $visibility_value = $self->visibility_value;
+ return 1 if !$visibility_value;
- # Values with a visibility value are only shown if the visibility
- # value is set on the bug.
- return $visibility_value->is_set_on_bug($bug);
+ # Values with a visibility value are only shown if the visibility
+ # value is set on the bug.
+ return $visibility_value->is_set_on_bug($bug);
}
sub is_set_on_bug {
- my ($self, $bug) = @_;
- my $field_name = $self->FIELD_NAME;
- # This allows bug/create/create.html.tmpl to pass in a hashref that
- # looks like a bug object.
- my $value = blessed($bug) ? $bug->$field_name : $bug->{$field_name};
- $value = $value->name if blessed($value);
- return 0 if !defined $value;
-
- if ($self->field->type == FIELD_TYPE_BUG_URLS
- or $self->field->type == FIELD_TYPE_MULTI_SELECT)
- {
- return grep($_ eq $self->name, @$value) ? 1 : 0;
- }
- return $value eq $self->name ? 1 : 0;
+ my ($self, $bug) = @_;
+ my $field_name = $self->FIELD_NAME;
+
+ # This allows bug/create/create.html.tmpl to pass in a hashref that
+ # looks like a bug object.
+ my $value = blessed($bug) ? $bug->$field_name : $bug->{$field_name};
+ $value = $value->name if blessed($value);
+ return 0 if !defined $value;
+
+ if ( $self->field->type == FIELD_TYPE_BUG_URLS
+ or $self->field->type == FIELD_TYPE_MULTI_SELECT)
+ {
+ return grep($_ eq $self->name, @$value) ? 1 : 0;
+ }
+ return $value eq $self->name ? 1 : 0;
}
1;