I have a situation where I have a very long list of categories that I allow users to select multiple options from. There are certain directories that I want to prevent people from adding links to. I want those directories to NOT appear in the select box list.
What I've done is create an Enum(Yes,No) column in the Categories table called "AllowLinks".
It is default to "Yes". If can be set to "No" by the admin.
I am trying to edit sub get_all_categories in Link.pm to recognize that attribute. Here's where I've gotten to so far -- but it doesn't work.
Many thanks to anyone who can set me straight here.
Mike
sub get_all_categories {
# -------------------------------------------------------------------
# Returns a select box of all categories.
#
my $self = shift;
my $id = shift;
my $name = shift || 'CatLinks.CategoryID';
my $mult = shift || 5;
my $db = $DB->table ('Category');
# my $sth = $db->select ( ['ID', 'Full_Name'] );
my $sth = $db->select ( ['ID', 'Full_Name', 'AllowLinks'] ); # my mod.
my %res = ();
# while (my ($id, $name) = $sth->fetchrow_array) {
# $res{$id} = $name;
# }
while (my ($id, $name) = $sth->fetchrow_array) { # my mod.
if ($sth [2] == "Yes"){
$res{$id} = $name;
}
}
return $self->select ( { name => $name, values => \%res, value => $id, multiple => $mult, sort => sub { lc $_[0] cmp lc $_[1] } } );
What I've done is create an Enum(Yes,No) column in the Categories table called "AllowLinks".
It is default to "Yes". If can be set to "No" by the admin.
I am trying to edit sub get_all_categories in Link.pm to recognize that attribute. Here's where I've gotten to so far -- but it doesn't work.
Many thanks to anyone who can set me straight here.
Mike
sub get_all_categories {
# -------------------------------------------------------------------
# Returns a select box of all categories.
#
my $self = shift;
my $id = shift;
my $name = shift || 'CatLinks.CategoryID';
my $mult = shift || 5;
my $db = $DB->table ('Category');
# my $sth = $db->select ( ['ID', 'Full_Name'] );
my $sth = $db->select ( ['ID', 'Full_Name', 'AllowLinks'] ); # my mod.
my %res = ();
# while (my ($id, $name) = $sth->fetchrow_array) {
# $res{$id} = $name;
# }
while (my ($id, $name) = $sth->fetchrow_array) { # my mod.
if ($sth [2] == "Yes"){
$res{$id} = $name;
}
}
return $self->select ( { name => $name, values => \%res, value => $id, multiple => $mult, sort => sub { lc $_[0] cmp lc $_[1] } } );