+=head3 C4::ItemCirculationAlertPreference->grid({ branchcode => $c, notification => $type })
+
+Return a 2D arrayref for the grid view in F<admin/item_circulation_alert_preferences.pl>.
+Each row represents a category (like 'Patron' or 'Young Adult') and
+each column represents an itemtype (like 'Book' or 'Music').
+
+Each cell contains...
+
+B<Example>:
+
+ use Data::Dump 'pp';
+ my $grid = C4::ItemCirculationAlertPreference->grid({
+ branchcode => 'CPL',
+ notification => 'CHECKOUT',
+ });
+ warn pp($grid);
+
+See F<admin/item_circulation_alerts.pl> to see how this method is used.
+
+=cut
+
+sub grid {
+ my ($class, $where) = @_;
+ my @branch_prefs = $class->find($where);
+ my @default_prefs = $class->find({ branchcode => '*', notification => $where->{notification} });
+ my @cc = C4::Category->all;
+ my @it = C4::ItemType->all;
+ my $notification = $where->{notification};
+ my %disabled = map {
+ my $key = $_->categorycode . "-" . $_->item_type . "-" . $notification;
+ $key =~ s/\*/_/g;
+ ($key => 1);
+ } @branch_prefs;
+ my %default = map {
+ my $key = $_->categorycode . "-" . $_->item_type . "-" . $notification;
+ $key =~ s/\*/_/g;
+ ($key => 1);
+ } @default_prefs;
+ my @grid;
+ for my $c (@cc) {
+ my $row = { description => $c->description, items => [] };
+ push @grid, $row;
+ for my $i (@it) {
+ my $key = $c->categorycode . "-" . $i->itemtype . "-" . $notification;
+ $key =~ s/\*/_/g;
+ my @classes;
+ my $text = " ";
+ if ($disabled{$key}) {
+ push @classes, 'disabled';
+ $text = "Disabled for $where->{branchcode}";
+ }
+ if ($default{$key}) {
+ push @classes, 'default';
+ $text = "Disabled for all";
+ }
+ push @{$row->{items}}, {
+ class => join(' ', @classes),
+ id => $key,
+ text => $text,
+ };
+ }
+ }
+ return \@grid;
+}
+
+
+
+