VKAPI: Make ACTUALLY work 'count' arg in Friends methods

This commit is contained in:
veselcraft 2022-03-27 16:43:20 +03:00
parent 0a78fc2ad0
commit 8caecbe362
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E

View file

@ -31,11 +31,11 @@ class User extends RowModel
const NSFW_TOLERANT = 1; const NSFW_TOLERANT = 1;
const NSFW_FULL_TOLERANT = 2; const NSFW_FULL_TOLERANT = 2;
protected function _abstractRelationGenerator(string $filename, int $page = 1): \Traversable protected function _abstractRelationGenerator(string $filename, int $page = 1, int $limit = 6): \Traversable
{ {
$id = $this->getId(); $id = $this->getId();
$query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql"); $query = "SELECT id FROM\n" . file_get_contents(__DIR__ . "/../sql/$filename.tsql");
$query .= "\n LIMIT 6 OFFSET " . ( ($page - 1) * 6 ); $query .= "\n LIMIT " . $limit . " OFFSET " . ( ($page - 1) * $limit );
$rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id); $rels = DatabaseConnection::i()->getConnection()->query($query, $id, $id);
foreach($rels as $rel) { foreach($rels as $rel) {
@ -443,9 +443,9 @@ class User extends RowModel
]; ];
} }
function getFriends(int $page = 1): \Traversable function getFriends(int $page = 1, int $limit = 6): \Traversable
{ {
return $this->_abstractRelationGenerator("get-friends", $page); return $this->_abstractRelationGenerator("get-friends", $page, $limit);
} }
function getFriendsCount(): int function getFriendsCount(): int
@ -453,9 +453,9 @@ class User extends RowModel
return $this->_abstractRelationCount("get-friends"); return $this->_abstractRelationCount("get-friends");
} }
function getFollowers(int $page = 1): \Traversable function getFollowers(int $page = 1, int $limit = 6): \Traversable
{ {
return $this->_abstractRelationGenerator("get-followers", $page); return $this->_abstractRelationGenerator("get-followers", $page, $limit);
} }
function getFollowersCount(): int function getFollowersCount(): int
@ -463,9 +463,9 @@ class User extends RowModel
return $this->_abstractRelationCount("get-followers"); return $this->_abstractRelationCount("get-followers");
} }
function getSubscriptions(int $page = 1): \Traversable function getSubscriptions(int $page = 1, int $limit = 6): \Traversable
{ {
return $this->_abstractRelationGenerator("get-subscriptions-user", $page); return $this->_abstractRelationGenerator("get-subscriptions-user", $page, $limit);
} }
function getSubscriptionsCount(): int function getSubscriptionsCount(): int