+ return ( \%shelflist, $total );
+}
+
+=item GetShelvesSummary
+
+ ($shelves, $total) = GetShelvesSummary($mincategory, $row_count, $offset, $owner)
+
+Returns the number of shelves specified by C<$row_count> and C<$offset> as well as the total
+number of shelves that meet the C<$owner> and/or C<$mincategory> criteria. C<$mincategory>,
+C<$row_count>, and C<$offset> are required. C<$owner> must be supplied when C<$mincategory> == 1.
+When C<$mincategory> is 2 or 3, supply undef as argument for C<$owner>.
+
+=cut
+
+sub GetShelvesSummary ($$$$) {
+ my ($mincategory, $row_count, $offset, $owner) = @_;
+ my @params = ($owner, $mincategory, ($offset ? $offset : 0), $row_count);
+ my @params1 = ($owner, $mincategory);
+ if ($mincategory > 1) {
+ shift @params;
+ shift @params1;
+ }
+ my $total = _shelf_count($owner, $mincategory);
+ # grab only the shelves meeting the row_count/offset spec...
+ my $query = qq(
+ SELECT
+ virtualshelves.shelfnumber,
+ virtualshelves.shelfname,
+ owner,
+ CONCAT(firstname, ' ', surname) AS name,
+ virtualshelves.category,
+ count(virtualshelfcontents.biblionumber) AS count
+ FROM virtualshelves
+ LEFT JOIN virtualshelfcontents ON virtualshelves.shelfnumber = virtualshelfcontents.shelfnumber
+ LEFT JOIN borrowers ON virtualshelves.owner = borrowers.borrowernumber );
+ $query .= ($mincategory == 1) ? "WHERE owner=? AND category=?" : "WHERE category>=?";
+ $query .= qq(
+ GROUP BY virtualshelves.shelfnumber
+ ORDER BY virtualshelves.category
+ DESC
+ LIMIT ?, ?);
+ my $sth2 = $dbh->prepare($query);
+ $sth2->execute(@params);
+ my $shelves = $sth2->fetchall_arrayref({});
+ return ($shelves, $total);
+
+ # Probably NOT the final implementation since it is still bulky (repeated hash keys).
+ # might like an array of rows of delimited values:
+ # 1|2||0|blacklist|112
+ # 2|6|Josh Ferraro|51|en_fuego|106
+}
+
+=item GetRecentShelves
+
+ ($shelflist) = GetRecentShelves(1, $limit, $owner)
+
+This function returns a references to an array of hashrefs containing specified shelves sorted
+by the date the shelf was last modified in descending order limited to the number of records
+specified by C<$row_count>. If calling with C<$mincategory> other than 1, use undef as C<$owner>.
+
+This function is intended to return a dataset reflecting the most recently active shelves for
+the submitted parameters.
+
+=cut
+
+sub GetRecentShelves ($$$) {
+ my ($mincategory, $row_count, $owner) = @_;
+ my (@shelflist);
+ my $total = _shelf_count($owner, $mincategory);
+ my @params = ($owner, $mincategory, 0, $row_count); #FIXME: offset is hardcoded here, but could be passed in for enhancements
+ shift @params if (not defined $owner);
+ my $query = "SELECT * FROM virtualshelves";
+ $query .= ((defined $owner) ? " WHERE owner = ? AND category = ?" : " WHERE category >= ? ");
+ $query .= " ORDER BY lastmodified DESC LIMIT ?, ?";
+ my $sth = $dbh->prepare($query);
+ $sth->execute(@params);
+ @shelflist = $sth->fetchall_arrayref({});
+ return ( \@shelflist, $total );