Commit 4587cba8 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 306601: Bugzilla::Classification needs a products() method - Patch by André…

Bug 306601: Bugzilla::Classification needs a products() method - Patch by André Batosti <batosti@async.com.br> r=LpSolit a=justdave
parent 727410cc
...@@ -21,6 +21,7 @@ package Bugzilla::Classification; ...@@ -21,6 +21,7 @@ package Bugzilla::Classification;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Product;
############################### ###############################
#### Initialization #### #### Initialization ####
...@@ -92,6 +93,24 @@ sub product_count { ...@@ -92,6 +93,24 @@ sub product_count {
return $self->{'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 #### #### Accessors ####
############################### ###############################
...@@ -154,6 +173,7 @@ Bugzilla::Classification - Bugzilla classification class. ...@@ -154,6 +173,7 @@ Bugzilla::Classification - Bugzilla classification class.
my $name = $classification->name; my $name = $classification->name;
my $description = $classification->description; my $description = $classification->description;
my $product_count = $classification->product_count; my $product_count = $classification->product_count;
my $products = $classification->products;
my $hash_ref = Bugzilla::Classification::get_all_classifications(); my $hash_ref = Bugzilla::Classification::get_all_classifications();
my $classification = $hash_ref->{1}; my $classification = $hash_ref->{1};
...@@ -194,6 +214,14 @@ A Classification is a higher-level grouping of Products. ...@@ -194,6 +214,14 @@ A Classification is a higher-level grouping of Products.
Returns: Integer - The total of products inside the classification. 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 =back
=head1 SUBROUTINES =head1 SUBROUTINES
......
...@@ -19,7 +19,6 @@ use strict; ...@@ -19,7 +19,6 @@ use strict;
package Bugzilla::Product; package Bugzilla::Product;
use Bugzilla::Component; use Bugzilla::Component;
use Bugzilla::Classification;
use Bugzilla::Version; use Bugzilla::Version;
use Bugzilla::Milestone; use Bugzilla::Milestone;
...@@ -111,16 +110,6 @@ sub components { ...@@ -111,16 +110,6 @@ sub components {
} }
return $self->{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 { sub group_controls {
my $self = shift; my $self = shift;
...@@ -217,33 +206,6 @@ sub classification_id { return $_[0]->{'classification_id'}; } ...@@ -217,33 +206,6 @@ sub classification_id { return $_[0]->{'classification_id'}; }
#### Subroutines ###### #### 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 { sub get_all_products {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
...@@ -287,7 +249,6 @@ Bugzilla::Product - Bugzilla product class. ...@@ -287,7 +249,6 @@ Bugzilla::Product - Bugzilla product class.
my $product = new Bugzilla::Product('AcmeProduct'); my $product = new Bugzilla::Product('AcmeProduct');
my @components = $product->components(); my @components = $product->components();
my $classification = $product->classification();
my $groups_controls = $product->group_controls(); my $groups_controls = $product->group_controls();
my @milestones = $product->milestones(); my @milestones = $product->milestones();
my @versions = $product->versions(); my @versions = $product->versions();
...@@ -304,8 +265,6 @@ Bugzilla::Product - Bugzilla product class. ...@@ -304,8 +265,6 @@ Bugzilla::Product - Bugzilla product class.
my $defaultmilestone = $product->default_milestone; my $defaultmilestone = $product->default_milestone;
my $classificationid = $product->classification_id; my $classificationid = $product->classification_id;
my @products = Bugzilla::Product::get_products_by_classification(1);
=head1 DESCRIPTION =head1 DESCRIPTION
Product.pm represents a product object. Product.pm represents a product object.
...@@ -336,15 +295,6 @@ Product.pm represents a product object. ...@@ -336,15 +295,6 @@ Product.pm represents a product object.
Returns: An array of Bugzilla::Component 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()> =item C<group_controls()>
Description: Returns a hash (group id as key) with all product Description: Returns a hash (group id as key) with all product
...@@ -386,14 +336,6 @@ Product.pm represents a product object. ...@@ -386,14 +336,6 @@ Product.pm represents a product object.
=over =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()> =item C<get_all_products()>
Description: Returns all products from the database. Description: Returns all products from the database.
......
...@@ -42,6 +42,7 @@ use Bugzilla::Util; ...@@ -42,6 +42,7 @@ use Bugzilla::Util;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::User::Setting; use Bugzilla::User::Setting;
use Bugzilla::Product; use Bugzilla::Product;
use Bugzilla::Classification;
use base qw(Exporter); use base qw(Exporter);
@Bugzilla::User::EXPORT = qw(insert_new_user is_available_username @Bugzilla::User::EXPORT = qw(insert_new_user is_available_username
...@@ -469,7 +470,8 @@ sub get_selectable_classifications { ...@@ -469,7 +470,8 @@ sub get_selectable_classifications {
my $class; my $class;
foreach my $product (@$products) { 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); my @sorted_class = sort {lc($a->name) cmp lc($b->name)} (values %$class);
$self->{selectable_classifications} = \@sorted_class; $self->{selectable_classifications} = \@sorted_class;
......
...@@ -29,7 +29,6 @@ use Bugzilla::Util; ...@@ -29,7 +29,6 @@ use Bugzilla::Util;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Config qw($datadir); use Bugzilla::Config qw($datadir);
use Bugzilla::Classification; use Bugzilla::Classification;
use Bugzilla::Product;
require "globals.pl"; require "globals.pl";
...@@ -119,6 +118,8 @@ if ($action eq 'new') { ...@@ -119,6 +118,8 @@ if ($action eq 'new') {
# Make versioncache flush # Make versioncache flush
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
$vars->{'classification'} = $class_name;
LoadTemplate($action); LoadTemplate($action);
} }
...@@ -141,8 +142,7 @@ if ($action eq 'del') { ...@@ -141,8 +142,7 @@ if ($action eq 'del') {
ThrowUserError("classification_has_products"); ThrowUserError("classification_has_products");
} }
$vars->{'description'} = $classification->description; $vars->{'classification'} = $classification;
$vars->{'classification'} = $classification->name;
LoadTemplate($action); LoadTemplate($action);
} }
...@@ -175,7 +175,7 @@ if ($action eq 'delete') { ...@@ -175,7 +175,7 @@ if ($action eq 'delete') {
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
$vars->{'classification'} = $classification->name; $vars->{'classification'} = $classification;
LoadTemplate($action); LoadTemplate($action);
} }
...@@ -191,13 +191,7 @@ if ($action eq 'edit') { ...@@ -191,13 +191,7 @@ if ($action eq 'edit') {
my $classification = my $classification =
Bugzilla::Classification::check_classification($class_name); Bugzilla::Classification::check_classification($class_name);
my @products = $vars->{'classification'} = $classification;
Bugzilla::Product::get_products_by_classification(
$classification->id);
$vars->{'description'} = $classification->description;
$vars->{'classification'} = $classification->name;
$vars->{'products'} = \@products;
LoadTemplate($action); LoadTemplate($action);
} }
...@@ -259,8 +253,6 @@ if ($action eq 'reclassify') { ...@@ -259,8 +253,6 @@ if ($action eq 'reclassify') {
my $classification = my $classification =
Bugzilla::Classification::check_classification($class_name); Bugzilla::Classification::check_classification($class_name);
$vars->{'description'} = $classification->description;
my $sth = $dbh->prepare("UPDATE products SET classification_id = ? my $sth = $dbh->prepare("UPDATE products SET classification_id = ?
WHERE name = ?"); WHERE name = ?");
...@@ -280,22 +272,10 @@ if ($action eq 'reclassify') { ...@@ -280,22 +272,10 @@ if ($action eq 'reclassify') {
} }
} }
my @selected_products = (); my @classifications =
my @unselected_products = (); Bugzilla::Classification::get_all_classifications;
$vars->{'classifications'} = \@classifications;
my @products = Bugzilla::Product::get_all_products(); $vars->{'classification'} = $classification;
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;
LoadTemplate($action); LoadTemplate($action);
} }
......
...@@ -298,23 +298,7 @@ $vars->{'product'} = \@products; ...@@ -298,23 +298,7 @@ $vars->{'product'} = \@products;
# Create data structures representing each classification # Create data structures representing each classification
if (Param('useclassification')) { if (Param('useclassification')) {
my @classifications = (); $vars->{'classification'} = $user->get_selectable_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;
} }
# We use 'component_' because 'component' is a Template Toolkit reserved word. # We use 'component_' because 'component' is a Template Toolkit reserved word.
......
...@@ -30,13 +30,13 @@ ...@@ -30,13 +30,13 @@
</tr><tr> </tr><tr>
<td valign="top">Classification:</td> <td valign="top">Classification:</td>
<td valign="top">[% classification FILTER html %]</td> <td valign="top">[% classification.name FILTER html %]</td>
</tr><tr> </tr><tr>
<td valign="top">Description:</td> <td valign="top">Description:</td>
<td valign="top"> <td valign="top">
[% IF description %] [% IF classification.description %]
[% description %] [% classification.description FILTER none %]
[% ELSE %] [% ELSE %]
<font color="red">description missing</font> <font color="red">description missing</font>
[% END %] [% END %]
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<form method=post action="editclassifications.cgi"> <form method=post action="editclassifications.cgi">
<input type=submit value="Yes, delete"> <input type=submit value="Yes, delete">
<input type=hidden name="action" value="delete"> <input type=hidden name="action" value="delete">
<input type=hidden name="classification" value="[% classification FILTER html %]"> <input type=hidden name="classification" value="[% classification.name FILTER html %]">
</form> </form>
<p>Back to the <a href="./">main [% terms.bugs %] page</a> <p>Back to the <a href="./">main [% terms.bugs %] page</a>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
title = "Classification deleted" title = "Classification deleted"
%] %]
Classification [% classification FILTER html %] deleted.<br> Classification [% classification.name FILTER html %] deleted.<br>
<p>Back to the <a href="./">main [% terms.bugs %] page</a> <p>Back to the <a href="./">main [% terms.bugs %] page</a>
or <a href="editclassifications.cgi"> edit</a> more classifications. or <a href="editclassifications.cgi"> edit</a> more classifications.
......
...@@ -27,18 +27,24 @@ ...@@ -27,18 +27,24 @@
<table border=0 cellpadding=4 cellspacing=0> <table border=0 cellpadding=4 cellspacing=0>
<tr> <tr>
<th align="right">Classification:</th> <th align="right">Classification:</th>
<td><input size=64 maxlength=64 name="classification" value="[% classification FILTER html %]"></TD> <td><input size=64 maxlength=64 name="classification"
value="[% classification.name FILTER html %]"></td>
</tr> </tr>
<tr> <tr>
<th align="right">Description:</th> <th align="right">Description:</th>
<td><textarea rows=4 cols=64 name="description">[% description %]</textarea></TD> <td><textarea rows=4 cols=64 name="description">
[% classification.description FILTER none %]</textarea>
</td>
</tr> </tr>
<tr valign=top> <tr valign=top>
<th align="right"><a href="editproducts.cgi?classification=[% classification FILTER url_quote %]">Edit products</a></th> <th align="right">
<a href="editproducts.cgi?classification=[% classification.name FILTER url_quote %]">
Edit products</a>
</th>
<td> <td>
[% IF products AND products.size > 0 %] [% IF classification.products.size > 0 %]
<table> <table>
[% FOREACH product = products %] [% FOREACH product = classification.products %]
<tr> <tr>
<th align=right valign=top>[% product.name FILTER html %]</th> <th align=right valign=top>[% product.name FILTER html %]</th>
<td valign=top> <td valign=top>
...@@ -58,7 +64,8 @@ ...@@ -58,7 +64,8 @@
</tr> </tr>
</table> </table>
<input type=hidden name="classificationold" value="[% classification FILTER html %]"> <input type=hidden name="classificationold"
value="[% classification.name FILTER html %]">
<input type=hidden name="action" value="update"> <input type=hidden name="action" value="update">
<input type=submit value="Update"> <input type=submit value="Update">
</form> </form>
......
...@@ -23,19 +23,17 @@ ...@@ -23,19 +23,17 @@
title = "Reclassify products" title = "Reclassify products"
%] %]
[% main_classification = classification %]
<form method=post action="editclassifications.cgi"> <form method=post action="editclassifications.cgi">
<table border=0 cellpadding=4 cellspacing=0> <table border=0 cellpadding=4 cellspacing=0>
<tr> <tr>
<td valign="top">Classification:</td> <td valign="top">Classification:</td>
<td valign="top" colspan=3>[% main_classification FILTER html %]</td> <td valign="top" colspan=3>[% classification.name FILTER html %]</td>
</tr><tr> </tr><tr>
<td valign="top">Description:</td> <td valign="top">Description:</td>
<td valign="top" colspan=3> <td valign="top" colspan=3>
[% IF description %] [% IF classification.description %]
[% description %] [% classification.description FILTER none %]
[% ELSE %] [% ELSE %]
<font color="red">description missing</font> <font color="red">description missing</font>
[% END %] [% END %]
...@@ -45,16 +43,20 @@ ...@@ -45,16 +43,20 @@
<td valign="top">Products:</td> <td valign="top">Products:</td>
<td valign="top">Products</td> <td valign="top">Products</td>
<td></td> <td></td>
<td valign="top">[% main_classification FILTER html %] Products</td> <td valign="top">[% classification.name FILTER html %] Products</td>
</tr><tr> </tr><tr>
<td></td> <td></td>
<td valign="top"> <td valign="top">
<select name="prodlist" id="prodlist" multiple="multiple" size="20"> <select name="prodlist" id="prodlist" multiple="multiple" size="20">
[% FOREACH product = unselected_products %] [% FOREACH class = classifications %]
<option value="[% product.name FILTER html %]"> [% IF class.id != classification.id %]
[[% product.classification.name FILTER html %]]&nbsp;[% product.name FILTER html %] [% FOREACH product = class.products %]
</option> <option value="[% product.name FILTER html %]">
[[% class.name FILTER html %]]&nbsp;[% product.name FILTER html %]
</option>
[% END %]
[% END %]
[% END %] [% END %]
</select></td> </select></td>
...@@ -65,7 +67,7 @@ ...@@ -65,7 +67,7 @@
<td valign="middle" rowspan=2> <td valign="middle" rowspan=2>
<select name="myprodlist" id="myprodlist" multiple="multiple" size="20"> <select name="myprodlist" id="myprodlist" multiple="multiple" size="20">
[% FOREACH product = selected_products %] [% FOREACH product = classification.products %]
<option value="[% product.name FILTER html %]"> <option value="[% product.name FILTER html %]">
[% product.name FILTER html %] [% product.name FILTER html %]
</option> </option>
...@@ -75,10 +77,11 @@ ...@@ -75,10 +77,11 @@
</table> </table>
<input type=hidden name="action" value="reclassify"> <input type=hidden name="action" value="reclassify">
<input type=hidden name="classification" value="[% main_classification FILTER html %]"> <input type=hidden name="classification" value="[% classification.name FILTER html %]">
</form> </form>
<p>Back to the <a href="./">main [% terms.bugs %] page</a>, <p>Back to the <a href="./">main [% terms.bugs %] page</a>,
or <a href="editclassifications.cgi"> edit</a> more classifications. or <a href="editclassifications.cgi"> edit</a> more classifications.
[% PROCESS global/footer.html.tmpl %] [% PROCESS global/footer.html.tmpl %]
...@@ -497,18 +497,6 @@ ...@@ -497,18 +497,6 @@
'link_uri' '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' => [ 'admin/classifications/select.html.tmpl' => [
'cl.description', 'cl.description',
], ],
......
...@@ -43,7 +43,7 @@ var tms = new Array(); ...@@ -43,7 +43,7 @@ var tms = new Array();
[% nclass = 0 %] [% nclass = 0 %]
[% FOREACH c = classification %] [% FOREACH c = classification %]
prods[[% nclass FILTER js %]] = [ 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 %] [% nclass = nclass+1 %]
[% END %] [% END %]
......
...@@ -74,9 +74,9 @@ for "crash secure SSL flash". ...@@ -74,9 +74,9 @@ for "crash secure SSL flash".
[% FOREACH c = classification %] [% FOREACH c = classification %]
<optgroup label="[% c.name FILTER html %]"> <optgroup label="[% c.name FILTER html %]">
[% FOREACH p = c.products %] [% FOREACH p = c.products %]
<option value="[% p FILTER html %]" <option value="[% p.name FILTER html %]"
[% " selected" IF lsearch(default.product, p) != -1 %]> [% " selected" IF lsearch(default.product, p.name) != -1 %]>
[% p FILTER html %] [% p.name FILTER html %]
</option> </option>
[% END %] [% END %]
</optgroup> </optgroup>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment