Changeset 106 in bookmarks for trunk/lib/Bookmarks.pm
- Timestamp:
- 10/19/15 21:16:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Bookmarks.pm
r92 r106 99 99 } 100 100 101 sub get_count { 102 my $self = shift; 103 my $search = shift; 104 105 my ($sql, @bind) = sql_interp( 106 'select count(*) from resources join bookmarks on resources.uri = bookmarks.uri', 107 $self->_sql_where_clause($search), 108 ); 109 my $sth = $self->dbh->prepare($sql); 110 $sth->execute(@bind); 111 my ($count) = $sth->fetchrow_array; 112 return $count; 113 } 114 101 115 sub search { 102 116 my $self = shift; 103 117 my $params = shift || {}; 104 118 my $search = Bookmarks::Search->new($params); 119 120 my ($limit, $offset); 121 if ($search->page) { 122 my $count = $self->get_count($search); 123 use Data::Pageset; 124 my $pages = Data::Pageset->new({ 125 total_entries => $count, 126 current_page => $search->page, 127 entries_per_page => 15, 128 mode => 'slide', 129 }); 130 $search->pages($pages); 131 $limit = $pages->entries_per_page; 132 $offset = $pages->skipped; 133 } else { 134 $limit = $search->limit; 135 $offset = $search->offset; 136 } 105 137 106 138 # build the query … … 110 142 push @sql, $self->_sql_where_clause($search); 111 143 push @sql, 'order by ctime desc'; 112 push @sql, ('limit', \$ search->limit) if $search->limit;144 push @sql, ('limit', \$limit) if $limit; 113 145 # an offset is only allowed if we have a limit clause 114 push @sql, ('offset', \$ search->offset) if $search->limit && $search->offset;146 push @sql, ('offset', \$offset) if $limit && $offset; 115 147 116 148 my ($sql, @bind) = sql_interp(@sql);
Note: See TracChangeset
for help on using the changeset viewer.