diff options
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Classification.pm | 28 | ||||
-rw-r--r-- | Bugzilla/Product.pm | 58 | ||||
-rw-r--r-- | Bugzilla/User.pm | 4 |
3 files changed, 31 insertions, 59 deletions
diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm index 50094df0a..fae932b85 100644 --- a/Bugzilla/Classification.pm +++ b/Bugzilla/Classification.pm @@ -21,6 +21,7 @@ package Bugzilla::Classification; use Bugzilla::Util; use Bugzilla::Error; +use Bugzilla::Product; ############################### #### Initialization #### @@ -92,6 +93,24 @@ sub product_count { return $self->{'product_count'}; } +sub products { + my $self = shift; + my $dbh = Bugzilla->dbh; + + if (!$self->{'products'}) { + my $product_ids = $dbh->selectcol_arrayref(q{ + SELECT id FROM products + WHERE classification_id = ?}, undef, $self->id); + + my @products; + foreach my $product_id (@$product_ids) { + push (@products, new Bugzilla::Product($product_id)); + } + $self->{'products'} = \@products; + } + return $self->{'products'}; +} + ############################### #### Accessors #### ############################### @@ -154,6 +173,7 @@ Bugzilla::Classification - Bugzilla classification class. my $name = $classification->name; my $description = $classification->description; my $product_count = $classification->product_count; + my $products = $classification->products; my $hash_ref = Bugzilla::Classification::get_all_classifications(); my $classification = $hash_ref->{1}; @@ -194,6 +214,14 @@ A Classification is a higher-level grouping of Products. Returns: Integer - The total of products inside the classification. +=item C<products> + + Description: Returns all products of the classification. + + Params: none. + + Returns: A reference to an array of Bugzilla::Product objects. + =back =head1 SUBROUTINES diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm index 94547476f..1bf1d4e56 100644 --- a/Bugzilla/Product.pm +++ b/Bugzilla/Product.pm @@ -19,7 +19,6 @@ use strict; package Bugzilla::Product; use Bugzilla::Component; -use Bugzilla::Classification; use Bugzilla::Version; use Bugzilla::Milestone; @@ -111,16 +110,6 @@ sub components { } return $self->{components}; } - -sub classification { - my $self = shift; - - if (!defined $self->{'classification'}) { - $self->{'classification'} = - new Bugzilla::Classification($self->classification_id); - } - return $self->{'classification'}; -} sub group_controls { my $self = shift; @@ -217,33 +206,6 @@ sub classification_id { return $_[0]->{'classification_id'}; } #### Subroutines ###### ############################### -sub get_products_by_classification { - my ($class_id) = @_; - my $dbh = Bugzilla->dbh; - $class_id ||= DEFAULT_CLASSIFICATION_ID; - - my $stored_class_id = $class_id; - unless (detaint_natural($class_id)) { - ThrowCodeError( - 'invalid_numeric_argument', - {argument => 'product_id', - value => $stored_class_id, - function => - 'Bugzilla::Product::get_classification_products'} - ); - } - - my $ids = $dbh->selectcol_arrayref(q{ - SELECT id FROM products - WHERE classification_id = ? ORDER by name}, undef, $class_id); - - my @products; - foreach my $id (@$ids) { - push @products, new Bugzilla::Product($id); - } - return @products; -} - sub get_all_products { my $dbh = Bugzilla->dbh; @@ -287,7 +249,6 @@ Bugzilla::Product - Bugzilla product class. my $product = new Bugzilla::Product('AcmeProduct'); my @components = $product->components(); - my $classification = $product->classification(); my $groups_controls = $product->group_controls(); my @milestones = $product->milestones(); my @versions = $product->versions(); @@ -304,8 +265,6 @@ Bugzilla::Product - Bugzilla product class. my $defaultmilestone = $product->default_milestone; my $classificationid = $product->classification_id; - my @products = Bugzilla::Product::get_products_by_classification(1); - =head1 DESCRIPTION Product.pm represents a product object. @@ -336,15 +295,6 @@ Product.pm represents a product object. Returns: An array of Bugzilla::Component object. -=item C<classification()> - - Description: Returns a Bugzilla::Classification object for - the product classification. - - Params: none. - - Returns: A Bugzilla::Classification object. - =item C<group_controls()> Description: Returns a hash (group id as key) with all product @@ -386,14 +336,6 @@ Product.pm represents a product object. =over -=item C<get_products_by_classification($class_id)> - - Description: Returns all products for a specific classification id. - - Params: $class_id - Integer with classification id. - - Returns: Bugzilla::Product object list. - =item C<get_all_products()> Description: Returns all products from the database. diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index a20f2e338..85584d70c 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -42,6 +42,7 @@ use Bugzilla::Util; use Bugzilla::Constants; use Bugzilla::User::Setting; use Bugzilla::Product; +use Bugzilla::Classification; use base qw(Exporter); @Bugzilla::User::EXPORT = qw(insert_new_user is_available_username @@ -469,7 +470,8 @@ sub get_selectable_classifications { my $class; foreach my $product (@$products) { - $class->{$product->classification_id} ||= $product->classification; + $class->{$product->classification_id} ||= + new Bugzilla::Classification($product->classification_id); } my @sorted_class = sort {lc($a->name) cmp lc($b->name)} (values %$class); $self->{selectable_classifications} = \@sorted_class; |