separate time conditions
This commit is contained in:
@@ -349,7 +349,8 @@ sub modify_results {
|
||||
$counter++;
|
||||
|
||||
if ( ( defined $params->{template} )
|
||||
&& ( $params->{template} =~ /(list|details)/ ) ){
|
||||
&& ( $params->{template} =~ /(list|details)/ ) )
|
||||
{
|
||||
if ( ( defined $result->{excerpt} ) && ( length( $result->{excerpt} ) > 250 ) ) {
|
||||
$result->{excerpt} = substr( $result->{excerpt}, 0, 250 ) . '...';
|
||||
}
|
||||
@@ -577,6 +578,7 @@ sub add_recordings{
|
||||
|
||||
my @ids = ();
|
||||
my $eventsById = {};
|
||||
|
||||
#my $events = $results;
|
||||
|
||||
for my $event (@$events) {
|
||||
@@ -585,7 +587,6 @@ sub add_recordings{
|
||||
$eventsById->{$eventId} = $event;
|
||||
}
|
||||
|
||||
|
||||
my $qms = join( ', ', ( map { '?' } @$events ) );
|
||||
my $bindValues = join( ', ', ( map { $_->{event_id} } @$events ) );
|
||||
|
||||
@@ -598,6 +599,7 @@ sub add_recordings{
|
||||
|
||||
$dbh = db::connect($config) unless defined $dbh;
|
||||
my $recordings = db::get( $dbh, $query, $bindValues );
|
||||
|
||||
#print STDERR Dumper($recordings);
|
||||
|
||||
for my $entry (@$recordings) {
|
||||
@@ -609,6 +611,186 @@ sub add_recordings{
|
||||
return $events;
|
||||
}
|
||||
|
||||
sub getDateRange {
|
||||
my $config = shift;
|
||||
$config->{date}->{day_starting_hour};
|
||||
}
|
||||
|
||||
sub getDateQueryConditions {
|
||||
my $config = shift;
|
||||
my $params = shift;
|
||||
my $bind_values = shift;
|
||||
|
||||
# conditions by date
|
||||
my $date_conds = [];
|
||||
|
||||
#date, today, tomorrow, yesterday
|
||||
my $date = '';
|
||||
$date = time::date_cond( $params->{date} ) if ( $params->{date} ne '' );
|
||||
|
||||
my $from_date = '';
|
||||
$from_date = time::date_cond( $params->{from_date} )
|
||||
if ( $params->{from_date} ne '' );
|
||||
|
||||
my $till_date = '';
|
||||
$till_date = time::date_cond( $params->{till_date} )
|
||||
if ( $params->{till_date} ne '' );
|
||||
|
||||
my $from_time = '';
|
||||
$from_time = time::time_cond( $params->{from_time} )
|
||||
if ( $params->{from_time} ne '' );
|
||||
|
||||
my $till_time = '';
|
||||
$till_time = time::time_cond( $params->{till_time} )
|
||||
if ( $params->{till_time} ne '' );
|
||||
|
||||
my $date_range_include = $params->{date_range_include};
|
||||
|
||||
#from_time is defined
|
||||
if ( ( $params->{from_date} ne '' ) && ( $params->{from_time} ne '' ) ) {
|
||||
my $datetime = time::datetime_cond( $from_date . 'T' . $from_time );
|
||||
if ( $datetime ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
push @$date_conds, ' end > ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$from_date = '';
|
||||
} else {
|
||||
push @$date_conds, ' start >= ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$from_date = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#till_time is defined
|
||||
if ( ( $params->{till_date} ne '' ) && ( $params->{till_time} ne '' ) ) {
|
||||
my $datetime = time::datetime_cond( $till_date . 'T' . $till_time );
|
||||
if ( $datetime ne '' ) {
|
||||
push @$date_conds, ' start < ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$till_date = '';
|
||||
}
|
||||
}
|
||||
|
||||
#time is defined
|
||||
if ( ( defined $params->{time} )
|
||||
&& ( $params->{time} ne '' )
|
||||
&& ( $params->{time} ne 'now' )
|
||||
&& ( $params->{time} ne 'future' ) )
|
||||
{
|
||||
my $time = time::time_cond( $params->{time} );
|
||||
if ( $time ne '' ) {
|
||||
push @$date_conds, ' time(start) = ? ';
|
||||
push @$bind_values, $time;
|
||||
}
|
||||
return $date_conds;
|
||||
}
|
||||
|
||||
#event is not over
|
||||
elsif ( ( defined $params->{time} ) && ( $params->{time} eq 'now' ) ) {
|
||||
push @$date_conds, qq{
|
||||
(
|
||||
( unix_timestamp(end) > unix_timestamp(now() ) )
|
||||
and
|
||||
( unix_timestamp(start) <= unix_timestamp(now() ) )
|
||||
)
|
||||
};
|
||||
return $date_conds;
|
||||
} elsif ( ( defined $params->{time} ) && ( $params->{time} eq 'future' ) ) {
|
||||
push @$date_conds, qq{
|
||||
(
|
||||
( unix_timestamp(end) > unix_timestamp(now() ) )
|
||||
and
|
||||
( unix_timestamp(end) - unix_timestamp(now() ) ) < 7*24*3600
|
||||
)
|
||||
};
|
||||
return $date_conds;
|
||||
} elsif ( $date ne '' ) {
|
||||
if ( $date eq 'today' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @$date_conds, ' ( start_date = ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
#push @$date_conds, ' ( start_date = ? ) ';
|
||||
#push @$bind_values, $date;
|
||||
my $start = time::datetime_cond( $date . 'T00:00:00' );
|
||||
if ( $start ne '' ) {
|
||||
$start = time::add_hours_to_datetime( $start, $config->{date}->{day_starting_hour} );
|
||||
my $end = time::add_hours_to_datetime( $start, 24 );
|
||||
|
||||
if ( $date_range_include eq '1' ) {
|
||||
push @$date_conds, ' end > ? ';
|
||||
push @$bind_values, $start;
|
||||
} else {
|
||||
push @$date_conds, ' start >= ? ';
|
||||
push @$bind_values, $start;
|
||||
}
|
||||
|
||||
if ( $end ne '' ) {
|
||||
push @$date_conds, ' start < ? ';
|
||||
push @$bind_values, $end;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $date_conds;
|
||||
} else {
|
||||
if ( $from_date ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
|
||||
# end is after start
|
||||
push @$date_conds, ' ( end_date >= ? )';
|
||||
push @$bind_values, $from_date;
|
||||
} else {
|
||||
push @$date_conds, ' ( start_date >= ? ) ';
|
||||
push @$bind_values, $from_date;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $till_date ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
|
||||
# start is before end
|
||||
push @$date_conds, ' ( start_date <= ? )';
|
||||
push @$bind_values, $till_date;
|
||||
} else {
|
||||
push @$date_conds, ' ( end_date <= ? ) ';
|
||||
push @$bind_values, $till_date;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $params->{weekday} ne '' ) {
|
||||
my $weekday = $params->{weekday};
|
||||
$weekday += 1;
|
||||
$weekday -= 7 if ( $weekday > 7 );
|
||||
push @$date_conds, ' (dayofweek(start_date)= ?) ';
|
||||
push @$bind_values, $weekday;
|
||||
}
|
||||
|
||||
if ( $params->{archive} eq 'past' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @$date_conds, ' ( start_date < ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
|
||||
} elsif ( $params->{archive} eq 'future' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @$date_conds, ' ( start_date >= ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $date_conds;
|
||||
|
||||
}
|
||||
|
||||
# if recordings is set in params, recordings date and path will be included
|
||||
sub get_query {
|
||||
my $dbh = shift;
|
||||
@@ -646,162 +828,9 @@ sub get_query {
|
||||
|
||||
} else {
|
||||
|
||||
# conditions by date
|
||||
my @date_conds = ();
|
||||
my $date_conds = getDateQueryConditions( $config, $params, $bind_values );
|
||||
my $date_cond = join " and ", @$date_conds;
|
||||
|
||||
#date, today, tomorrow, yesterday
|
||||
my $date = '';
|
||||
$date = time::date_cond( $params->{date} ) if ( $params->{date} ne '' );
|
||||
|
||||
my $from_date = '';
|
||||
$from_date = time::date_cond( $params->{from_date} )
|
||||
if ( $params->{from_date} ne '' );
|
||||
|
||||
my $till_date = '';
|
||||
$till_date = time::date_cond( $params->{till_date} )
|
||||
if ( $params->{till_date} ne '' );
|
||||
|
||||
my $from_time = '';
|
||||
$from_time = time::time_cond( $params->{from_time} )
|
||||
if ( $params->{from_time} ne '' );
|
||||
|
||||
my $till_time = '';
|
||||
$till_time = time::time_cond( $params->{till_time} )
|
||||
if ( $params->{till_time} ne '' );
|
||||
|
||||
my $date_range_include = $params->{date_range_include};
|
||||
|
||||
#from_time is defined
|
||||
if ( ( $params->{from_date} ne '' ) && ( $params->{from_time} ne '' ) ) {
|
||||
my $datetime = time::datetime_cond( $from_date . 'T' . $from_time );
|
||||
if ( $datetime ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
push @date_conds, ' end > ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$from_date = '';
|
||||
} else {
|
||||
push @date_conds, ' start >= ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$from_date = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#till_time is defined
|
||||
if ( ( $params->{till_date} ne '' ) && ( $params->{till_time} ne '' ) ) {
|
||||
my $datetime = time::datetime_cond( $till_date . 'T' . $till_time );
|
||||
if ( $datetime ne '' ) {
|
||||
push @date_conds, ' start < ? ';
|
||||
push @$bind_values, $datetime;
|
||||
$till_date = '';
|
||||
}
|
||||
}
|
||||
|
||||
#time is defined
|
||||
if ( ( defined $params->{time} )
|
||||
&& ( $params->{time} ne '' )
|
||||
&& ( $params->{time} ne 'now' )
|
||||
&& ( $params->{time} ne 'future' ) )
|
||||
{
|
||||
my $time = time::time_cond( $params->{time} );
|
||||
if ( $time ne '' ) {
|
||||
push @date_conds, ' time(start) = ? ';
|
||||
push @$bind_values, $time;
|
||||
}
|
||||
}
|
||||
|
||||
#event is not over
|
||||
if ( ( defined $params->{time} ) && ( $params->{time} eq 'now' ) ) {
|
||||
push @date_conds, qq{
|
||||
(
|
||||
( unix_timestamp(end) > unix_timestamp(now() ) )
|
||||
and
|
||||
( unix_timestamp(start) <= unix_timestamp(now() ) )
|
||||
)
|
||||
};
|
||||
|
||||
} elsif ( ( defined $params->{time} ) && ( $params->{time} eq 'future' ) ) {
|
||||
push @date_conds, qq{
|
||||
(
|
||||
( unix_timestamp(end) > unix_timestamp(now() ) )
|
||||
and
|
||||
( unix_timestamp(end) - unix_timestamp(now() ) ) < 7*24*3600
|
||||
)
|
||||
};
|
||||
|
||||
} elsif ( $date ne '' ) {
|
||||
if ( $date eq 'today' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @date_conds, ' ( start_date = ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
|
||||
} else {
|
||||
if ( $date ne '' ) {
|
||||
push @date_conds, ' ( start_date = ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $from_date ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
|
||||
# end is after start
|
||||
push @date_conds, ' ( end_date >= ? )';
|
||||
push @$bind_values, $from_date;
|
||||
} else {
|
||||
push @date_conds, ' ( start_date >= ? ) ';
|
||||
push @$bind_values, $from_date;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $till_date ne '' ) {
|
||||
if ( $date_range_include eq '1' ) {
|
||||
|
||||
# start is before end
|
||||
push @date_conds, ' ( start_date <= ? )';
|
||||
push @$bind_values, $till_date;
|
||||
} else {
|
||||
push @date_conds, ' ( end_date <= ? ) ';
|
||||
push @$bind_values, $till_date;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $params->{weekday} ne '' ) {
|
||||
my $weekday = $params->{weekday};
|
||||
$weekday += 1;
|
||||
$weekday -= 7 if ( $weekday > 7 );
|
||||
push @date_conds, ' (dayofweek(start_date)= ?) ';
|
||||
push @$bind_values, $weekday;
|
||||
}
|
||||
|
||||
if ( $params->{archive} eq 'past' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @date_conds, ' ( start_date < ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
|
||||
} elsif ( $params->{archive} eq 'future' ) {
|
||||
my $date = time::get_event_date($config);
|
||||
if ( $date ne '' ) {
|
||||
push @date_conds, ' ( start_date >= ? ) ';
|
||||
push @$bind_values, $date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( ( defined $params->{time_of_day} )
|
||||
&& ( $params->{time_of_day} ne '' ) )
|
||||
{
|
||||
push @date_conds, ' ( time_of_day = ? ) ';
|
||||
push @$bind_values, $params->{time_of_day};
|
||||
|
||||
}
|
||||
|
||||
my $date_cond = join " and ", @date_conds;
|
||||
push @$where_cond, $date_cond if ( $date_cond ne '' );
|
||||
}
|
||||
|
||||
@@ -923,6 +952,7 @@ sub get_query {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#print STDERR $search_cond."\n";
|
||||
|
||||
my $project_cond = '';
|
||||
@@ -1083,6 +1113,7 @@ sub get_query {
|
||||
push @$bind_values, $params->{studio_id};
|
||||
$query .= ', se.studio_id';
|
||||
}
|
||||
|
||||
#push @$where_cond, 'se.event_id=e.id';
|
||||
}
|
||||
|
||||
@@ -1092,6 +1123,7 @@ sub get_query {
|
||||
$query .= ', ar.size';
|
||||
$query .= ', ar.created_by uploaded_by';
|
||||
$query .= ', ar.modified_at uploaded_at';
|
||||
|
||||
#push @$where_cond, 'e.id=ar.event_id';
|
||||
}
|
||||
|
||||
@@ -1099,6 +1131,7 @@ sub get_query {
|
||||
|
||||
# add tables
|
||||
if ( ( $params->{project_id} ne '' ) || ( $params->{studio_id} ne '' ) ) {
|
||||
|
||||
# prepent series_events
|
||||
$query .= "\n calcms_series_events se inner join calcms_events e on se.event_id=e.id";
|
||||
} else {
|
||||
@@ -1211,7 +1244,8 @@ sub render {
|
||||
if ( $project->{name} ne '' );
|
||||
|
||||
$template_parameters->{controllers} = $config->{controllers};
|
||||
$template_parameters->{hide_event_images}=1 if (defined $config->{permissions}->{hide_event_images}) && ($config->{permissions}->{hide_event_images} == 1);
|
||||
$template_parameters->{hide_event_images} = 1
|
||||
if ( defined $config->{permissions}->{hide_event_images} ) && ( $config->{permissions}->{hide_event_images} == 1 );
|
||||
|
||||
# use Data::Dumper;print STDERR Dumper($template_parameters)."\n";
|
||||
template::process( $_[0], $params->{template}, $template_parameters );
|
||||
@@ -1254,8 +1288,7 @@ sub setDefaultEventConditions {
|
||||
$options = {} unless defined $options;
|
||||
|
||||
# exclude projects
|
||||
if (
|
||||
( defined $options->{exclude_projects} )
|
||||
if ( ( defined $options->{exclude_projects} )
|
||||
&& ( $options->{exclude_projects} == 1 )
|
||||
&& ( defined $config->{filter} )
|
||||
&& ( defined $config->{filter}->{projects_to_exclude} ) )
|
||||
@@ -1269,8 +1302,7 @@ sub setDefaultEventConditions {
|
||||
}
|
||||
|
||||
# exclude locations
|
||||
if (
|
||||
( defined $options->{exclude_locations} )
|
||||
if ( ( defined $options->{exclude_locations} )
|
||||
&& ( $options->{exclude_locations} == 1 )
|
||||
&& ( defined $config->{filter} )
|
||||
&& ( defined $config->{filter}->{locations_to_exclude} ) )
|
||||
@@ -1390,6 +1422,7 @@ sub get_previous_event_of_series {
|
||||
return $events->[0]->{id};
|
||||
}
|
||||
|
||||
# used by calendar
|
||||
sub get_by_date_range {
|
||||
my $dbh = shift;
|
||||
my $config = shift;
|
||||
@@ -1515,11 +1548,13 @@ sub get_duration {
|
||||
my $timezone = $config->{date}->{time_zone};
|
||||
my $start = time::get_datetime( $event->{start}, $timezone );
|
||||
my $end = time::get_datetime( $event->{end}, $timezone );
|
||||
|
||||
#my $seconds = $end->subtract($start)->in_units("minutes");
|
||||
#return $seconds;
|
||||
return undef unless defined $start;
|
||||
return undef unless defined $end;
|
||||
my $duration = $end->epoch() - $start->epoch();
|
||||
|
||||
#print STDERR "duration=$duration, end=".$end->datetime()." start=".$start->datetime()."\n";
|
||||
return $duration / 60;
|
||||
}
|
||||
@@ -1647,7 +1682,6 @@ sub check_params {
|
||||
$projects_to_exclude =~ s/\s+/ /g;
|
||||
}
|
||||
|
||||
|
||||
#enable exclude locations filter
|
||||
my $exclude_locations = 0;
|
||||
$exclude_locations = 1 if ( defined $params->{exclude_locations} ) && ( $params->{exclude_locations} eq '1' );
|
||||
|
||||
Reference in New Issue
Block a user