Revision 670

Date:
2017/12/07 11:41:06
Author:
ahitrov
Revision Log:
Filters next_to and prev_to can use parameter with or without _

Files:

Legend:

 
Added
 
Removed
 
Modified
  • utf8/core/lib/SQL/CommonFilters.pm

     
    151 151
    152 152 sub _prev_to_filter {
    153 153 my ($self, %opts)=@_;
    154 return undef unless ( exists $opts{prevto} );
    154 return undef unless ( exists $opts{prevto} || exists $opts{prev_to} );
    155 my $prevto = exists $opts{prevto} ? 'prevto' : 'prev_to';
    155 156 my ($wheres, $values) = ([],[]);
    156 157 my $field = exists $opts{use_id} ? 'id' : exists $opts{use_ctime} ? 'ctime' : exists $opts{use_mtime} ? 'mtime' : 'dtime';
    157 158 push @$wheres, " d.$field < ? ";
    158 if ( ref $opts{prevto} ) {
    159 my $ctime = $opts{prevto};
    159 if ( ref $opts{$prevto} ) {
    160 my $ctime = $opts{$prevto};
    160 161 push @$values, $ctime->ymd('-').' '.$ctime->hms.'.'.$ctime->nanosecond;
    161 162 } else {
    162 push @$values, $opts{prevto};
    163 push @$values, $opts{$prevto};
    163 164 }
    164 165 return ($wheres, $values);
    165 166 }
    166 167
    167 168 sub _next_to_filter {
    168 169 my ($self, %opts)=@_;
    169 return undef unless ( exists $opts{nextto} );
    170 return undef unless ( exists $opts{nextto} || exists $opts{next_to} );
    171 my $nextto = exists $opts{nextto} ? 'nextto' : 'next_to';
    170 172 my ($wheres, $values) = ([],[]);
    171 173 my $field = exists $opts{use_id} ? 'id' : exists $opts{use_ctime} ? 'ctime' : exists $opts{use_mtime} ? 'mtime' : 'dtime';
    172 174 push @$wheres, " d.$field > ? ";
    173 if ( ref $opts{nextto} ) {
    174 my $ctime = $opts{nextto};
    175 if ( ref $opts{$nextto} ) {
    176 my $ctime = $opts{$nextto};
    175 177 push @$values, $ctime->ymd('-').' '.$ctime->hms.'.'.$ctime->nanosecond;
    176 178 } else {
    177 push @$values, $opts{nextto};
    179 push @$values, $opts{$nextto};
    178 180 }
    179 181 return ($wheres, $values);
    180 182 }