mirror of
https://github.com/openvk/openvk
synced 2024-11-14 02:59:12 +03:00
VKAPI: Add ovk.aboutInstance
This commit is contained in:
parent
8ce8355784
commit
a578dca41f
1 changed files with 52 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
|||
<?php declare(strict_types=1);
|
||||
namespace openvk\VKAPI\Handlers;
|
||||
use openvk\Web\Models\Repositories\{Users as UsersRepo, Clubs as ClubsRepo, Posts as PostsRepo};
|
||||
|
||||
|
||||
final class Ovk extends VKAPIRequestHandler
|
||||
{
|
||||
|
@ -21,4 +23,54 @@ final class Ovk extends VKAPIRequestHandler
|
|||
{
|
||||
return "крылышки";
|
||||
}
|
||||
|
||||
function aboutInstance(string $fields = "statistics,administrators,popular_groups,links", string $admin_fields = "", string $group_fields = ""): object
|
||||
{
|
||||
$fields = explode(',', $fields);
|
||||
$response = (object) [];
|
||||
|
||||
if(in_array("statistics", $fields)) {
|
||||
$usersStats = (new UsersRepo)->getStatistics();
|
||||
$clubsCount = (new ClubsRepo)->getCount();
|
||||
$postsCount = (new PostsRepo)->getCount();
|
||||
$response->statistics = (object) [
|
||||
"users_count" => $usersStats->all,
|
||||
"online_users_count" => $usersStats->online,
|
||||
"active_users_count" => $usersStats->active,
|
||||
"groups_count" => $clubsCount,
|
||||
"wall_posts_count" => $postsCount
|
||||
];
|
||||
}
|
||||
|
||||
if(in_array("administrators", $fields)) {
|
||||
$admins = iterator_to_array((new UsersRepo)->getInstanceAdmins());
|
||||
$adminsResponse = (new Users($this->getUser()))->get(implode(',', array_map(function($admin) {
|
||||
return $admin->getId();
|
||||
}, $admins)), $admin_fields, 0, sizeof($admins));
|
||||
$response->administrators = (object) [
|
||||
"count" => sizeof($admins),
|
||||
"items" => $adminsResponse
|
||||
];
|
||||
}
|
||||
|
||||
if(in_array("popular_groups", $fields)) {
|
||||
$popularClubs = iterator_to_array((new ClubsRepo)->getPopularClubs());
|
||||
$clubsResponse = (new Groups($this->getUser()))->getById(implode(',', array_map(function($entry) {
|
||||
return $entry->club->getId();
|
||||
}, $popularClubs)), "", "members_count, " . $group_fields);
|
||||
|
||||
$response->popular_groups = (object) [
|
||||
"count" => sizeof($popularClubs),
|
||||
"items" => $clubsResponse
|
||||
];
|
||||
}
|
||||
|
||||
if(in_array("links", $fields))
|
||||
$response->links = (object) [
|
||||
"count" => sizeof(OPENVK_ROOT_CONF['openvk']['preferences']['about']['links']),
|
||||
"items" => is_null(OPENVK_ROOT_CONF['openvk']['preferences']['about']['links']) ? [] : OPENVK_ROOT_CONF['openvk']['preferences']['about']['links']
|
||||
];
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue