VKAPI: Add new method Groups.Search

This commit is contained in:
veselcraft 2022-10-09 18:06:43 +03:00
parent b3aa8e41b1
commit 13606493b6
No known key found for this signature in database
GPG key ID: AED66BC1AC628A4E

View file

@ -102,23 +102,32 @@ final class Groups extends VKAPIRequestHandler
]; ];
} }
function getById(string $group_ids = "", string $group_id = "", string $fields = ""): ?array function getById(string $group_ids = "", string $group_id = "", string $fields = "", int $offset = 0, int $count = 500): ?array
{ {
/* Both offset and count SHOULD be used only in OpenVK code,
not in your app or script, since it's not oficially documented by VK */
$clubs = new ClubsRepo; $clubs = new ClubsRepo;
if($group_ids == NULL && $group_id != NULL) if(empty($group_ids) && !empty($group_id))
$group_ids = $group_id; $group_ids = $group_id;
if($group_ids == NULL && $group_id == NULL) if(empty($group_ids) && empty($group_id))
$this->fail(100, "One of the parameters specified was missing or invalid: group_ids is undefined"); $this->fail(100, "One of the parameters specified was missing or invalid: group_ids is undefined");
$clbs = explode(',', $group_ids); $clbs = explode(',', $group_ids);
$response; $response = array();
$ic = sizeof($clbs); $ic = sizeof($clbs);
if(sizeof($clbs) > $count)
$ic = $count;
$clbs = array_slice($clbs, $offset * $count);
for($i=0; $i < $ic; $i++) { for($i=0; $i < $ic; $i++) {
if($i > 500) if($i > 500 || $clbs[$i] == 0)
break; break;
if($clbs[$i] < 0) if($clbs[$i] < 0)
@ -215,4 +224,24 @@ final class Groups extends VKAPIRequestHandler
return $response; return $response;
} }
function search(string $q, int $offset = 0, int $count = 100)
{
$clubs = new ClubsRepo;
$array = [];
$find = $clubs->find($q);
foreach ($find as $group)
$array[] = $group->getId();
return (object) [
"count" => $find->size(),
"items" => $this->getById(implode(',', $array), "", "is_admin,is_member,is_advertiser,photo_50,photo_100,photo_200", $offset, $count)
/*
* As there is no thing as "fields" by the original documentation
* i'll just bake this param by the example shown here: https://dev.vk.com/method/groups.search
*/
];
}
} }