mirror of
https://github.com/openvk/openvk
synced 2024-12-23 00:51:03 +03:00
VKAPI: Add new method Groups.Search
This commit is contained in:
parent
b3aa8e41b1
commit
13606493b6
1 changed files with 34 additions and 5 deletions
|
@ -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
|
||||||
|
*/
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue