|
Lines 87-92
sub get_private_shelves {
Link Here
|
| 87 |
my $rows = $params->{rows}; |
87 |
my $rows = $params->{rows}; |
| 88 |
my $borrowernumber = $params->{borrowernumber} || 0; |
88 |
my $borrowernumber = $params->{borrowernumber} || 0; |
| 89 |
|
89 |
|
|
|
90 |
my $sort_by = $params->{sort_by}; |
| 91 |
my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); |
| 92 |
|
| 90 |
$self->search( |
93 |
$self->search( |
| 91 |
{ |
94 |
{ |
| 92 |
public => 0, |
95 |
public => 0, |
|
Lines 98-104
sub get_private_shelves {
Link Here
|
| 98 |
{ |
101 |
{ |
| 99 |
join => ['virtualshelfshares'], |
102 |
join => ['virtualshelfshares'], |
| 100 |
distinct => 'shelfnumber', |
103 |
distinct => 'shelfnumber', |
| 101 |
order_by => 'shelfname', |
104 |
order_by => $order_by, |
| 102 |
( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), |
105 |
( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), |
| 103 |
} |
106 |
} |
| 104 |
); |
107 |
); |
|
Lines 113-130
sub get_public_shelves {
Link Here
|
| 113 |
my $page = $params->{page}; |
116 |
my $page = $params->{page}; |
| 114 |
my $rows = $params->{rows}; |
117 |
my $rows = $params->{rows}; |
| 115 |
|
118 |
|
|
|
119 |
my $sort_by = $params->{sort_by}; |
| 120 |
my $order_by = _prepare_order_by_for_shelves( { sort_by => $sort_by } ); |
| 121 |
|
| 116 |
$self->search( |
122 |
$self->search( |
| 117 |
{ |
123 |
{ |
| 118 |
public => 1, |
124 |
public => 1, |
| 119 |
}, |
125 |
}, |
| 120 |
{ |
126 |
{ |
| 121 |
distinct => 'shelfnumber', |
127 |
distinct => 'shelfnumber', |
| 122 |
order_by => 'shelfname', |
128 |
order_by => $order_by, |
| 123 |
( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), |
129 |
( ( $page and $rows ) ? ( page => $page, rows => $rows ) : () ), |
| 124 |
} |
130 |
} |
| 125 |
); |
131 |
); |
| 126 |
} |
132 |
} |
| 127 |
|
133 |
|
|
|
134 |
=head3 _prepare_order_by_for_shelves |
| 135 |
|
| 136 |
Create an "order_by" statement when sorting lists of lists |
| 137 |
|
| 138 |
=cut |
| 139 |
|
| 140 |
sub _prepare_order_by_for_shelves { |
| 141 |
my ($args) = @_; |
| 142 |
my $sort_by = $args->{sort_by}; |
| 143 |
my $order_by_dir = '-asc'; |
| 144 |
my $order_by_col = 'shelfname'; |
| 145 |
if ($sort_by) { |
| 146 |
my $sortfield = $sort_by->{sortfield}; |
| 147 |
my $direction = $sort_by->{direction}; |
| 148 |
if ( $direction eq 'asc' || $direction eq 'desc' ) { |
| 149 |
$order_by_dir = '-' . $direction; |
| 150 |
} |
| 151 |
if ( $sortfield eq 'shelfname' || $sortfield eq 'lastmodified' ) { |
| 152 |
$order_by_col = $sortfield; |
| 153 |
} |
| 154 |
} |
| 155 |
my $order_by = { $order_by_dir => $order_by_col }; |
| 156 |
return $order_by; |
| 157 |
} |
| 158 |
|
| 128 |
=head3 get_some_shelves |
159 |
=head3 get_some_shelves |
| 129 |
|
160 |
|
| 130 |
=cut |
161 |
=cut |