summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-07-29 23:14:40 +0200
committerlpsolit%gmail.com <>2005-07-29 23:14:40 +0200
commitab199bf568703d0c287d0f21ce1816e44183aa02 (patch)
tree41e9ffb1230afed4f0bfff0d463a3e9e025c26e4 /Bugzilla
parent966c262164d7dd68686862fa827d0dfde2132b69 (diff)
downloadbugzilla-ab199bf568703d0c287d0f21ce1816e44183aa02.tar.gz
bugzilla-ab199bf568703d0c287d0f21ce1816e44183aa02.tar.xz
Bug 286294: cleanup editclassifications.cgi and migrate the existent code to use Classification.pm - Patch by Tiago R. Mello <timello@gmail.com> r=LpSolit a=myk
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Classification.pm48
-rw-r--r--Bugzilla/Product.pm14
2 files changed, 45 insertions, 17 deletions
diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm
index fd011e6fe..c35c0ba9b 100644
--- a/Bugzilla/Classification.pm
+++ b/Bugzilla/Classification.pm
@@ -21,6 +21,7 @@ package Bugzilla::Classification;
use Bugzilla;
use Bugzilla::Util;
+use Bugzilla::Error;
###############################
#### Initialization ####
@@ -87,7 +88,7 @@ sub product_count {
if (!defined $self->{'product_count'}) {
$self->{'product_count'} = $dbh->selectrow_array(q{
SELECT COUNT(*) FROM products
- WHERE classification_id = ?}, undef, $self->id);
+ WHERE classification_id = ?}, undef, $self->id) || 0;
}
return $self->{'product_count'};
}
@@ -108,13 +109,31 @@ sub get_all_classifications () {
my $dbh = Bugzilla->dbh;
my $ids = $dbh->selectcol_arrayref(q{
- SELECT id FROM classifications});
+ SELECT id FROM classifications ORDER BY name});
- my $classifications;
+ my @classifications;
foreach my $id (@$ids) {
- $classifications->{$id} = new Bugzilla::Classification($id);
+ push @classifications, new Bugzilla::Classification($id);
}
- return $classifications;
+ return @classifications;
+}
+
+sub check_classification ($) {
+ my ($class_name) = @_;
+
+ unless ($class_name) {
+ ThrowUserError("classification_not_specified");
+ }
+
+ my $classification =
+ new Bugzilla::Classification({name => $class_name});
+
+ unless ($classification) {
+ ThrowUserError("classification_doesnt_exist",
+ { name => $class_name });
+ }
+
+ return $classification;
}
1;
@@ -140,11 +159,14 @@ Bugzilla::Classification - Bugzilla classification class.
my $hash_ref = Bugzilla::Classification::get_all_classifications();
my $classification = $hash_ref->{1};
+ my $classification =
+ Bugzilla::Classification::check_classification('AcmeClass');
+
=head1 DESCRIPTION
Classification.pm represents a Classification object.
-A Classification is a higher-level grouping of Bugzilla Products.
+A Classification is a higher-level grouping of Products.
=head1 METHODS
@@ -181,12 +203,20 @@ A Classification is a higher-level grouping of Bugzilla Products.
=item C<get_all_classifications()>
- Description: Returns all Bugzilla classifications.
+ Description: Returns all classifications.
Params: none.
- Returns: A hash with classification id as key and
- Bugzilla::Classification object as value.
+ Returns: Bugzilla::Classification object list.
+
+=item C<check_classification($classification_name)>
+
+ Description: Checks if the classification name passed in is a
+ valid classification.
+
+ Params: $classification_name - String with a classification name.
+
+ Returns: Bugzilla::Classification object.
=back
diff --git a/Bugzilla/Product.pm b/Bugzilla/Product.pm
index 37ef86a62..26c80103f 100644
--- a/Bugzilla/Product.pm
+++ b/Bugzilla/Product.pm
@@ -196,13 +196,13 @@ sub get_products_by_classification ($) {
my $ids = $dbh->selectcol_arrayref(q{
SELECT id FROM products
- WHERE classification_id = ?}, undef, $class_id);
+ WHERE classification_id = ? ORDER by name}, undef, $class_id);
- my $products;
+ my @products;
foreach my $id (@$ids) {
- $products->{$id} = new Bugzilla::Product($id);
+ push @products, new Bugzilla::Product($id);
}
- return $products;
+ return @products;
}
sub get_all_products () {
@@ -265,8 +265,7 @@ Bugzilla::Product - Bugzilla product class.
my $defaultmilestone = $product->default_milestone;
my $classificationid = $product->classification_id;
- my $hash_ref = Bugzilla::Product::get_products_by_classification(1);
- my $product = $hash_ref->{1};
+ my @products = Bugzilla::Product::get_products_by_classification(1);
=head1 DESCRIPTION
@@ -355,8 +354,7 @@ Product.pm represents a product object.
Params: $class_id - Integer with classification id.
- Returns: A hash with product id as key and a Bugzilla::Product
- object as value.
+ Returns: Bugzilla::Product object list.
=item C<get_all_products()>