-sub news_channels_by_category {
-
- my ($categories_count, @results) = &news_channels_categories();
- foreach my $row (@results) {
-
- my ($channels_count, @channels) = &news_channels('', $row->{'id_category'});
- $row->{'channels_count'} = $channels_count;
- $row->{'channels'} = \@channels;
- }
-
- my ($channels_count, @channels) = &news_channels('', '', 1);
- my %row;
- $row{'id_category'} = -1;
- $row{'unclassified'} = 1;
- $row{'channels_count'} = $channels_count;
- $row{'channels'} = \@channels;
- push @results, \%row;
-
- return (scalar(@results), @results);
-}
-
-sub get_new_channel {
- my ($id) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT * FROM news_channels WHERE id = ?");
- $sth->execute($id);
- my $channel = $sth->fetchrow_hashref;
- $sth->finish;
- return $channel;
-}
-
-sub del_channels {
- my ($ids) = @_;
- if ($ids ne '') {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("DELETE FROM news_channels WHERE id IN ($ids) ");
- $sth->execute();
- $sth->finish;
- return $ids;
- }
- return 0;
-}
-
-sub add_channel {
- my ($name, $url, $id_category, $notes) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("INSERT INTO news_channels (channel_name, url, id_category, notes) VALUES (?,?,?,?)");
- $sth->execute($name, $url, $id_category, $notes);
- $sth->finish;
- return 1;
-}
-
-sub update_channel {
- my ($id, $name, $url, $id_category, $notes) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("UPDATE news_channels SET channel_name = ?, url = ?, id_category = ?, notes = ? WHERE id = ?");
- $sth->execute($name, $url, $id_category, $notes, $id);
- $sth->finish;
- return 1;
-}
-
-sub news_channels_categories {
- my $dbh = C4::Context->dbh;
- my @categories;
- my $query = "SELECT * FROM news_channels_categories";
- my $sth = $dbh->prepare($query);
- $sth->execute();
- while (my $row = $sth->fetchrow_hashref) {
- push @categories, $row;
- }
- $sth->finish;
- return (scalar(@categories), @categories);
-
-}
-
-sub get_new_channel_category {
- my ($id) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT * FROM news_channels_categories WHERE id_category = ?");
- $sth->execute($id);
- my $category = $sth->fetchrow_hashref;
- $sth->finish;
- return $category;
-}
-
-sub del_channels_categories {
- my ($ids) = @_;
- if ($ids ne '') {
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("UPDATE news_channels SET id_category = NULL WHERE id_category IN ($ids) ");
- $sth->execute();
- $sth = $dbh->prepare("DELETE FROM news_channels_categories WHERE id_category IN ($ids) ");
- $sth->execute();
- $sth->finish;
- return $ids;
- }
- return 0;
-}
-
-sub add_channel_category {
- my ($name) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("INSERT INTO news_channels_categories (category_name) VALUES (?)");
- $sth->execute($name);
- $sth->finish;
- return 1;
-}
-
-sub update_channel_category {
- my ($id, $name) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("UPDATE news_channels_categories SET category_name = ? WHERE id_category = ?");
- $sth->execute($name, $id);
- $sth->finish;
- return 1;
-}
-