Skip to content

Commit

Permalink
allow an explicit limit as well
Browse files Browse the repository at this point in the history
simple browse is weird
  • Loading branch information
lachlan-00 committed May 14, 2024
1 parent 2365006 commit f7db6e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Module/Api/Method/ArtistSongsMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public static function artist_songs(array $input, User $user): bool
$browse->reset_filters();
$browse->set_type('song');
if (array_key_exists('top50', $input) && (int)$input['top50'] == 1) {
$browse->set_start(0);
$browse->set_offset(50);
$browse->set_is_simple(true);
$browse->set_limit(50);
$browse->set_sort('object_count', 'DESC');
$type = 'top50';
} else {
Expand Down
18 changes: 18 additions & 0 deletions src/Repository/Model/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Query
'join' => null,
'mashup' => null,
'offset' => 0,
'limit' => 0,
'song_artist' => null, // Used by $browse->set_type() to filter artists
'select' => array(),
'simple' => false,
Expand Down Expand Up @@ -709,6 +710,16 @@ public function set_offset($offset): void
$this->_state['offset'] = abs($offset);
}

/**
* set_limit
* This sets the current offset of this query
* @param int $limit
*/
public function set_limit($limit): void
{
$this->_state['limit'] = abs($limit);
}

/**
* set_catalog
* @param int $catalog_number
Expand Down Expand Up @@ -1056,6 +1067,13 @@ private function _get_limit_sql(): string
{
$start = $this->get_start();
$offset = $this->get_offset();
if ($this->_state['limit'] > 0) {
if ($offset > 0) {
return ' LIMIT ' . (string)($this->_state['limit']) . ', ' . (string)($offset);
} else {
return ' LIMIT ' . (string)($this->_state['limit']);
}
}
if (!$this->is_simple() || $start < 0 || ($start == 0 && $offset == 0)) {
return '';
}
Expand Down

0 comments on commit f7db6e6

Please sign in to comment.