Konstrukt
view release on metacpan or search on metacpan
lib/Konstrukt/Plugin/calendar/DBI.pm view on Meta::CPAN
((($start_year = $end_year AND $start_month + 1 = $end_month) OR ($start_year + 1 = $end_year AND YEAR(date) = 0 AND $start_month = 12 AND $end_month = 1)) AND DAYOFMONTH(date) BETWEEN $end_day + 1 AND $start_day - 1) OR
#range over 2 years, but at most one full month per year, when year > 0. so either the start- or endmonth is directly at the year turn
($start_year + 1 = $end_year AND YEAR(date) > 0 AND (($start_year = YEAR(date) AND $start_month = 12 AND DAYOFMONTH(date) < $start_day) OR ($end_year = YEAR(date) AND $end_month = 1 AND DAYOFMONTH(date) > $end_day)))
))
)
) OR DAYOFMONTH(date) = 0)
ORDER BY
date, start ASC
QUERY
#warn $query;
return $dbh->selectall_arrayref($query, { Columns=>{} });
}
#= /get_range
=head2 get_all
Returns all events as an Array reference of hash references:
[ { id => .., year => .., month => .., day => ..,
start_hour => .., start_minute => .., end_hour => .., end_minute => ..,
description => .., author => .., private => .. },
{ id => .., ... },
...
]
=cut
sub get_all {
my ($self) = @_;
my $dbh = $Konstrukt::DBI->get_connection(@{$self->{db_settings}}) or return [];
my $query = "SELECT id, description, author, private, YEAR(date) AS year, MONTH(date) AS month, DAYOFMONTH(date) AS day, HOUR(start) AS start_hour, MINUTE(start) AS start_minute, HOUR(end) AS end_hour, MINUTE(end) AS end_minute FROM calendar_event O...
return $dbh->selectall_arrayref($query, { Columns=>{} });
}
#= /get_all
=head2 update_entry
Updates an existing event.
B<Parameters>:
=over
=item * $id - The id of the event, which should be updated
=item * $year, $month, $day - The date of this entry
=item * $start_hour, $start_minute - The start time
=item * $end_hour, $end_minute - The ending time
=item * $description - What's this event about?
=item * $private - Is this entry only visible to the author?
=back
=cut
sub update_entry {
my ($self, $id, $year, $month, $day, $start_hour, $start_minute, $end_hour, $end_minute, $description, $private) = @_;
my $dbh = $Konstrukt::DBI->get_connection(@{$self->{db_settings}}) or return undef;
#quoting
$description = $dbh->quote($description || '');
$private ||= 0;
#update event
my $query = "UPDATE calendar_event SET date = '$year-$month-$day', start = '$start_hour:$start_minute', end = '$end_hour:$end_minute', description = $description, private = $private WHERE id = $id";
warn $query;
return $dbh->do($query);
}
#= /update_entry
=head2 delete_entry
Removes an existing entry.
B<Parameters>:
=over
=item * $id - The id of the entry, which should be removed
=back
=cut
sub delete_entry {
my ($self, $id) = @_;
my $dbh = $Konstrukt::DBI->get_connection(@{$self->{db_settings}}) or return undef;
return $dbh->do("DELETE FROM calendar_event WHERE id = $id");
}
#= /delete_entry
1;
=head1 AUTHOR
Copyright 2006 Thomas Wittek (mail at gedankenkonstrukt dot de). All rights reserved.
This document is free software.
It is distributed under the same terms as Perl itself.
=head1 SEE ALSO
L<Konstrukt>
=cut
__DATA__
-- 8< -- dbi: create -- >8 --
CREATE TABLE IF NOT EXISTS calendar_event
(
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
#entry
( run in 0.524 second using v1.01-cache-2.11-cpan-97f6503c9c8 )