summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorFrédéric Buclin <LpSolit@gmail.com>2012-08-21 00:51:06 +0200
committerFrédéric Buclin <LpSolit@gmail.com>2012-08-21 00:51:06 +0200
commitefa1199a1131ced709bf4ec1f38386104b14e0fa (patch)
tree6a393f202c9ca835b1c40e304b9757bbde1fa958 /Bugzilla
parent5a68f0998ca5015c621787b2c8982f2cea03c26d (diff)
downloadbugzilla-efa1199a1131ced709bf4ec1f38386104b14e0fa.tar.gz
bugzilla-efa1199a1131ced709bf4ec1f38386104b14e0fa.tar.xz
Bug 779747: The "Browse" link in the page header/footer doesn't sort products by classification
r=dkl a=LpSolit
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Classification.pm52
1 files changed, 51 insertions, 1 deletions
diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm
index 74719179a..2b35a8839 100644
--- a/Bugzilla/Classification.pm
+++ b/Bugzilla/Classification.pm
@@ -15,7 +15,8 @@ use Bugzilla::Util;
use Bugzilla::Error;
use Bugzilla::Product;
-use base qw(Bugzilla::Field::ChoiceInterface Bugzilla::Object);
+use base qw(Bugzilla::Field::ChoiceInterface Bugzilla::Object Exporter);
+@Bugzilla::Classification::EXPORT = qw(sort_products_by_classification);
###############################
#### Initialization ####
@@ -152,6 +153,38 @@ sub products {
sub description { return $_[0]->{'description'}; }
sub sortkey { return $_[0]->{'sortkey'}; }
+
+###############################
+#### Helpers ####
+###############################
+
+# This function is a helper to sort products to be listed
+# in global/choose-product.html.tmpl.
+
+sub sort_products_by_classification {
+ my $products = shift;
+ my $list;
+
+ if (Bugzilla->params->{'useclassification'}) {
+ my $class = {};
+ # Get all classifications with at least one product.
+ foreach my $product (@$products) {
+ $class->{$product->classification_id}->{'object'} ||=
+ new Bugzilla::Classification($product->classification_id);
+ # Nice way to group products per classification, without querying
+ # the DB again.
+ push(@{$class->{$product->classification_id}->{'products'}}, $product);
+ }
+ $list = [sort {$a->{'object'}->sortkey <=> $b->{'object'}->sortkey
+ || lc($a->{'object'}->name) cmp lc($b->{'object'}->name)}
+ (values %$class)];
+ }
+ else {
+ $list = [{object => undef, products => $products}];
+ }
+ return $list;
+}
+
1;
__END__
@@ -208,4 +241,21 @@ A Classification is a higher-level grouping of Products.
=back
+=head1 SUBROUTINES
+
+=over
+
+=item C<sort_products_by_classification>
+
+ Description: This is a helper which returns a list of products sorted
+ by classification in a form suitable to be passed to the
+ global/choose-product.html.tmpl template.
+
+ Params: An arrayref of product objects.
+
+ Returns: An arrayref of hashes suitable to be passed to
+ global/choose-product.html.tmpl.
+
+=back
+
=cut