Skip to content
Extraits de code Groupes Projets
Valider d312f965 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Sam::commands::list uses ORM

parent ad63ff4c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package Sam::commands::list;
use strict;
use DateTime;
use Sam::Event::Manager;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
......@@ -12,67 +17,43 @@ sub exec {
my $chan = shift;
my $sth;
if ($chan->[0] =~ /^#/) {
$sth = $dbh->prepare_cached('SELECT id, title, DATE_FORMAT(date, "%d/%m/%Y"), place, description, link
FROM sam
WHERE date > NOW()
ORDER BY date
LIMIT 2'
);
} else {
$sth = $dbh->prepare_cached('SELECT id, title, DATE_FORMAT(date, "%d/%m/%Y"), place, description, link
FROM sam
WHERE date > NOW()
ORDER BY date'
);
}
unless (defined $sth) {
$log->error("Couldn't prepare querie; aborting");
return;
}
$sth->execute()
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
my $events = Sam::Event::Manager->get_events(
query =>
[
date => { 'gt' => DateTime->now() },
],
sort_by => 'date',
limit => ($chan->[0] =~ /^#/) ? 2 : 10,
);
if (!$sth->rows) {
if (scalar @{$events} == 0) {
$irc->yield(privmsg => $chan => "Aucune soirée à venir enregistrée, on se fait bien chier…");
return;
}
while ($row = $sth->fetch) {
$msg = "[".$row->[0]."] ".$row->[1]." le ".$row->[2];
$msg .= " @ ".$row->[3] if ($row->[3]);
$msg .= " : ".$row->[4] if ($row->[4]);
$msg .= " <".$row->[5].">" if ($row->[5]);
foreach (@{$events}) {
my $msg = "[".$_->id."] ".$_->title;
$msg .=" le ".$_->date->strftime('%d/%m/%Y');
$msg .= " @ ".$_->place if ($_->place);
$msg .= " : ".$_->description if ($_->description);
$msg .= " <".$_->link.">" if ($_->link);
$irc->yield(privmsg => $chan => $msg);
}
if ($chan->[0] =~ /^#/) {
$sth = $dbh->prepare_cached('SELECT count(*)
FROM sam
where date > ?'
);
unless (defined $sth) {
$log->error("Couldn't prepare querie; aborting");
return;
}
my $events_nb = Sam::Event::Manager->get_events_count(
query => [ date => { 'gt' => DateTime->now() } ]
);
$sth->execute(scalar time)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
$events_nb -= 2;
$events_nb -= 8 if ($chan->[0] !~ /^#/); # query
$row = $sth->fetch;
$events = $row->[0] - 2;
if ($events > 0) {
$msg = $events . " autre";
$msg .= "s" if ($events > 1);
$msg .= " soirée";
$msg .= "s" if ($events > 1);
$msg .= " sur http://nightiies.iiens.net/sam/";
$irc->yield(privmsg => $chan => $msg);
}
if ($events_nb > 0) {
my $msg = $events_nb . " autre";
$msg .= "s" if ($events_nb > 1);
$msg .= " soirée";
$msg .= "s" if ($events_nb > 1);
$msg .= " sur http://nightiies.iiens.net/sam/";
$irc->yield(privmsg => $chan => $msg);
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter