From 4587cba89586ff3e00ed863748857ecf56a41532 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 14 Oct 2005 06:42:32 +0000 Subject: Bug 306601: Bugzilla::Classification needs a products() method - Patch by André Batosti r=LpSolit a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Classification.pm | 28 +++++++++++ Bugzilla/Product.pm | 58 ---------------------- Bugzilla/User.pm | 4 +- editclassifications.cgi | 38 ++++---------- query.cgi | 18 +------ .../en/default/admin/classifications/del.html.tmpl | 8 +-- .../default/admin/classifications/delete.html.tmpl | 2 +- .../default/admin/classifications/edit.html.tmpl | 19 ++++--- .../admin/classifications/reclassify.html.tmpl | 29 ++++++----- template/en/default/filterexceptions.pl | 12 ----- template/en/default/search/form.html.tmpl | 2 +- .../en/default/search/search-specific.html.tmpl | 6 +-- 12 files changed, 79 insertions(+), 145 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 + + 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 - - Description: Returns a Bugzilla::Classification object for - the product classification. - - Params: none. - - Returns: A Bugzilla::Classification object. - =item C Description: Returns a hash (group id as key) with all product @@ -386,14 +336,6 @@ Product.pm represents a product object. =over -=item C - - Description: Returns all products for a specific classification id. - - Params: $class_id - Integer with classification id. - - Returns: Bugzilla::Product object list. - =item C 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; diff --git a/editclassifications.cgi b/editclassifications.cgi index e70d256c1..352d7816b 100755 --- a/editclassifications.cgi +++ b/editclassifications.cgi @@ -29,7 +29,6 @@ use Bugzilla::Util; use Bugzilla::Error; use Bugzilla::Config qw($datadir); use Bugzilla::Classification; -use Bugzilla::Product; require "globals.pl"; @@ -119,6 +118,8 @@ if ($action eq 'new') { # Make versioncache flush unlink "$datadir/versioncache"; + $vars->{'classification'} = $class_name; + LoadTemplate($action); } @@ -141,8 +142,7 @@ if ($action eq 'del') { ThrowUserError("classification_has_products"); } - $vars->{'description'} = $classification->description; - $vars->{'classification'} = $classification->name; + $vars->{'classification'} = $classification; LoadTemplate($action); } @@ -175,7 +175,7 @@ if ($action eq 'delete') { unlink "$datadir/versioncache"; - $vars->{'classification'} = $classification->name; + $vars->{'classification'} = $classification; LoadTemplate($action); } @@ -191,13 +191,7 @@ if ($action eq 'edit') { my $classification = Bugzilla::Classification::check_classification($class_name); - my @products = - Bugzilla::Product::get_products_by_classification( - $classification->id); - - $vars->{'description'} = $classification->description; - $vars->{'classification'} = $classification->name; - $vars->{'products'} = \@products; + $vars->{'classification'} = $classification; LoadTemplate($action); } @@ -259,8 +253,6 @@ if ($action eq 'reclassify') { my $classification = Bugzilla::Classification::check_classification($class_name); - $vars->{'description'} = $classification->description; - my $sth = $dbh->prepare("UPDATE products SET classification_id = ? WHERE name = ?"); @@ -280,22 +272,10 @@ if ($action eq 'reclassify') { } } - my @selected_products = (); - my @unselected_products = (); - - my @products = Bugzilla::Product::get_all_products(); - - foreach my $product (@products) { - if ($product->classification_id == $classification->id) { - push @selected_products, $product; - } else { - push @unselected_products, $product; - } - } - - $vars->{'selected_products'} = \@selected_products; - $vars->{'unselected_products'} = \@unselected_products; - $vars->{'classification'} = $classification->name; + my @classifications = + Bugzilla::Classification::get_all_classifications; + $vars->{'classifications'} = \@classifications; + $vars->{'classification'} = $classification; LoadTemplate($action); } diff --git a/query.cgi b/query.cgi index 4a414d46c..986e2350b 100755 --- a/query.cgi +++ b/query.cgi @@ -298,23 +298,7 @@ $vars->{'product'} = \@products; # Create data structures representing each classification if (Param('useclassification')) { - my @classifications = (); - - my $class = $user->get_selectable_classifications; - foreach my $c (@$class) { - # Extract the name of products being in this classification. - my @prod_in_class - = grep { $_->classification_id == $c->id } @selectable_product_objects; - @prod_in_class = map { $_->name } @prod_in_class; - # Create hash to hold attributes for each classification. - my %classification = ( - 'name' => $c->name, - 'products' => \@prod_in_class - ); - # Assign hash back to classification array. - push @classifications, \%classification; - } - $vars->{'classification'} = \@classifications; + $vars->{'classification'} = $user->get_selectable_classifications; } # We use 'component_' because 'component' is a Template Toolkit reserved word. diff --git a/template/en/default/admin/classifications/del.html.tmpl b/template/en/default/admin/classifications/del.html.tmpl index 1430e093d..c32e46b4d 100644 --- a/template/en/default/admin/classifications/del.html.tmpl +++ b/template/en/default/admin/classifications/del.html.tmpl @@ -30,13 +30,13 @@ Classification: - [% classification FILTER html %] + [% classification.name FILTER html %] Description: - [% IF description %] - [% description %] + [% IF classification.description %] + [% classification.description FILTER none %] [% ELSE %] description missing [% END %] @@ -51,7 +51,7 @@
- +

Back to the main [% terms.bugs %] page diff --git a/template/en/default/admin/classifications/delete.html.tmpl b/template/en/default/admin/classifications/delete.html.tmpl index b2ec26cbb..046c1469f 100644 --- a/template/en/default/admin/classifications/delete.html.tmpl +++ b/template/en/default/admin/classifications/delete.html.tmpl @@ -23,7 +23,7 @@ title = "Classification deleted" %] -Classification [% classification FILTER html %] deleted.
+Classification [% classification.name FILTER html %] deleted.

Back to the main [% terms.bugs %] page or edit more classifications. diff --git a/template/en/default/admin/classifications/edit.html.tmpl b/template/en/default/admin/classifications/edit.html.tmpl index 65299df22..b38f4d6aa 100644 --- a/template/en/default/admin/classifications/edit.html.tmpl +++ b/template/en/default/admin/classifications/edit.html.tmpl @@ -27,18 +27,24 @@ - + - + - +
Classification:
Description: +
Edit products + + Edit products + - [% IF products AND products.size > 0 %] + [% IF classification.products.size > 0 %] - [% FOREACH product = products %] + [% FOREACH product = classification.products %]
[% product.name FILTER html %] @@ -58,7 +64,8 @@
- + diff --git a/template/en/default/admin/classifications/reclassify.html.tmpl b/template/en/default/admin/classifications/reclassify.html.tmpl index 3f7982bb3..127aeea87 100644 --- a/template/en/default/admin/classifications/reclassify.html.tmpl +++ b/template/en/default/admin/classifications/reclassify.html.tmpl @@ -23,19 +23,17 @@ title = "Reclassify products" %] -[% main_classification = classification %] -
- + - + @@ -65,7 +67,7 @@
Classification:[% main_classification FILTER html %][% classification.name FILTER html %]
Description: - [% IF description %] - [% description %] + [% IF classification.description %] + [% classification.description FILTER none %] [% ELSE %] description missing [% END %] @@ -45,16 +43,20 @@ Products: Products [% main_classification FILTER html %] Products[% classification.name FILTER html %] Products
- +

Back to the main [% terms.bugs %] page, or edit more classifications. -[% PROCESS global/footer.html.tmpl %] +[% PROCESS global/footer.html.tmpl %] + diff --git a/template/en/default/filterexceptions.pl b/template/en/default/filterexceptions.pl index d03a772c4..e0a811a48 100644 --- a/template/en/default/filterexceptions.pl +++ b/template/en/default/filterexceptions.pl @@ -497,18 +497,6 @@ 'link_uri' ], -'admin/classifications/del.html.tmpl' => [ - 'description', -], - -'admin/classifications/edit.html.tmpl' => [ - 'description', -], - -'admin/classifications/reclassify.html.tmpl' => [ - 'description', -], - 'admin/classifications/select.html.tmpl' => [ 'cl.description', ], diff --git a/template/en/default/search/form.html.tmpl b/template/en/default/search/form.html.tmpl index a8905cc09..80bf0a2b9 100644 --- a/template/en/default/search/form.html.tmpl +++ b/template/en/default/search/form.html.tmpl @@ -43,7 +43,7 @@ var tms = new Array(); [% nclass = 0 %] [% FOREACH c = classification %] prods[[% nclass FILTER js %]] = [ - [%- FOREACH item = c.products %]'[% item FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%] ]; + [%- FOREACH item = c.products %]'[% item.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%] ]; [% nclass = nclass+1 %] [% END %] diff --git a/template/en/default/search/search-specific.html.tmpl b/template/en/default/search/search-specific.html.tmpl index a36be340c..1ff6f17ac 100644 --- a/template/en/default/search/search-specific.html.tmpl +++ b/template/en/default/search/search-specific.html.tmpl @@ -74,9 +74,9 @@ for "crash secure SSL flash". [% FOREACH c = classification %] [% FOREACH p = c.products %] - [% END %] -- cgit v1.2.3-24-g4f1b