mirror of
https://github.com/openvk/openvk
synced 2024-12-23 09:01:15 +03:00
VKAPI: Little bit of refactoring
This commit is contained in:
parent
cb8038590c
commit
aef39f3102
2 changed files with 108 additions and 74 deletions
|
@ -3,19 +3,35 @@ namespace openvk\VKAPI\Handlers;
|
||||||
use openvk\Web\Models\Entities\User;
|
use openvk\Web\Models\Entities\User;
|
||||||
use openvk\Web\Models\Entities\Clubs;
|
use openvk\Web\Models\Entities\Clubs;
|
||||||
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
||||||
|
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
||||||
use openvk\Web\Models\Entities\Post;
|
use openvk\Web\Models\Entities\Post;
|
||||||
use openvk\Web\Models\Entities\Postable;
|
use openvk\Web\Models\Entities\Postable;
|
||||||
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
||||||
|
|
||||||
final class Groups extends VKAPIRequestHandler
|
final class Groups extends VKAPIRequestHandler
|
||||||
{
|
{
|
||||||
function get(string $group_ids, string $fields = "", int $offset = 0, int $count = 100, bool $online = false): array
|
function get(int $user_id = 0, string $fields = "", int $offset = 0, int $count = 6, bool $online = false): object
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
|
|
||||||
$clubs = new ClubsRepo;
|
if ($user_id == 0) {
|
||||||
$clbs = explode(',', $group_ids);
|
foreach($this->getUser()->getClubs($offset+1) as $club) {
|
||||||
$response;
|
$clbs[] = $club;
|
||||||
|
}
|
||||||
|
$clbsCount = $this->getUser()->getClubCount();
|
||||||
|
} else {
|
||||||
|
$users = new UsersRepo;
|
||||||
|
$user = $users->get($user_id);
|
||||||
|
if (is_null($user)) {
|
||||||
|
$this->fail(15, "Access denied");
|
||||||
|
}
|
||||||
|
foreach($user->getClubs($offset+1) as $club) {
|
||||||
|
$clbs[] = $club;
|
||||||
|
}
|
||||||
|
$clbsCount = $user->getClubCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
$rClubs;
|
||||||
|
|
||||||
$ic = sizeof($clbs);
|
$ic = sizeof($clbs);
|
||||||
|
|
||||||
|
@ -24,22 +40,21 @@ final class Groups extends VKAPIRequestHandler
|
||||||
$clbs = array_slice($clbs, $offset * $count);
|
$clbs = array_slice($clbs, $offset * $count);
|
||||||
|
|
||||||
for ($i=0; $i < $ic; $i++) {
|
for ($i=0; $i < $ic; $i++) {
|
||||||
$usr = $clubs->get((int) $clbs[$i]);
|
$usr = $clbs[$i];
|
||||||
if(is_null($usr))
|
if(is_null($usr))
|
||||||
{
|
{
|
||||||
$response[$i] = (object)[
|
$rClubs[$i] = (object)[
|
||||||
"id" => $clbs[$i],
|
"id" => $clbs[$i],
|
||||||
"first_name" => "DELETED",
|
"name" => "DELETED",
|
||||||
"last_name" => "",
|
|
||||||
"deactivated" => "deleted"
|
"deactivated" => "deleted"
|
||||||
];
|
];
|
||||||
}else if($clbs[$i] == null){
|
}else if($clbs[$i] == null){
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
$response[$i] = (object)[
|
$rClubs[$i] = (object)[
|
||||||
"id" => $usr->getId(),
|
"id" => $usr->getId(),
|
||||||
"first_name" => $usr->getFirstName(),
|
"name" => $usr->getName(),
|
||||||
"last_name" => $usr->getLastName(),
|
"screen_name" => $usr->getShortCode(),
|
||||||
"is_closed" => false,
|
"is_closed" => false,
|
||||||
"can_access_closed" => true,
|
"can_access_closed" => true,
|
||||||
];
|
];
|
||||||
|
@ -49,34 +64,28 @@ final class Groups extends VKAPIRequestHandler
|
||||||
foreach($flds as $field) {
|
foreach($flds as $field) {
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'verified':
|
case 'verified':
|
||||||
$response[$i]->verified = intval($usr->isVerified());
|
$rClubs[$i]->verified = intval($usr->isVerified());
|
||||||
break;
|
|
||||||
case 'sex':
|
|
||||||
$response[$i]->sex = $this->getUser()->isFemale() ? 1 : 2;
|
|
||||||
break;
|
break;
|
||||||
case 'has_photo':
|
case 'has_photo':
|
||||||
$response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
$rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
||||||
break;
|
break;
|
||||||
case 'photo_max_orig':
|
case 'photo_max_orig':
|
||||||
$response[$i]->photo_max_orig = $usr->getAvatarURL();
|
$rClubs[$i]->photo_max_orig = $usr->getAvatarURL();
|
||||||
break;
|
break;
|
||||||
case 'photo_max':
|
case 'photo_max':
|
||||||
$response[$i]->photo_max = $usr->getAvatarURL();
|
$rClubs[$i]->photo_max = $usr->getAvatarURL();
|
||||||
break;
|
break;
|
||||||
|
case 'members_count':
|
||||||
|
$rClubs[$i]->members_count = $usr->getFollowersCount();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// НУЖЕН фикс - либо из-за моего дебилизма, либо из-за сегментации котлеток некоторые пользовали отображаются как онлайн, хотя лол, если зайти на страницу, то оный уже офлайн
|
|
||||||
if($online == true && $usr->getOnline()->timestamp() + 2505600 > time()) {
|
|
||||||
$response[$i]->online = 1;
|
|
||||||
}else{
|
|
||||||
$response[$i]->online = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $response;
|
return (object) [
|
||||||
|
"count" => $clbsCount,
|
||||||
|
"items" => $rClubs
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,14 @@ use openvk\Web\Models\Repositories\Users as UsersRepo;
|
||||||
|
|
||||||
final class Users extends VKAPIRequestHandler
|
final class Users extends VKAPIRequestHandler
|
||||||
{
|
{
|
||||||
function get(string $user_ids, string $fields = "", int $offset = 0, int $count = 100): array
|
function get(string $user_ids = "0", string $fields = "", int $offset = 0, int $count = 100): array
|
||||||
{
|
{
|
||||||
$this->requireUser();
|
$this->requireUser();
|
||||||
|
|
||||||
$users = new UsersRepo;
|
$users = new UsersRepo;
|
||||||
|
if($user_ids == "0")
|
||||||
|
$user_ids = (string) $this->getUser()->getId();
|
||||||
|
|
||||||
$usrs = explode(',', $user_ids);
|
$usrs = explode(',', $user_ids);
|
||||||
$response;
|
$response;
|
||||||
|
|
||||||
|
@ -44,54 +47,76 @@ final class Users extends VKAPIRequestHandler
|
||||||
|
|
||||||
foreach($flds as $field) {
|
foreach($flds as $field) {
|
||||||
switch ($field) {
|
switch ($field) {
|
||||||
case 'verified':
|
case 'verified':
|
||||||
$response[$i]->verified = intval($usr->isVerified());
|
$response[$i]->verified = intval($usr->isVerified());
|
||||||
break;
|
break;
|
||||||
case 'sex':
|
case 'sex':
|
||||||
$response[$i]->sex = $this->getUser()->isFemale() ? 1 : 2;
|
$response[$i]->sex = $this->getUser()->isFemale() ? 1 : 2;
|
||||||
break;
|
break;
|
||||||
case 'has_photo':
|
case 'has_photo':
|
||||||
$response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
$response[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
||||||
break;
|
break;
|
||||||
case 'photo_max_orig':
|
case 'photo_max_orig':
|
||||||
$response[$i]->photo_max_orig = $usr->getAvatarURL();
|
$response[$i]->photo_max_orig = $usr->getAvatarURL();
|
||||||
break;
|
break;
|
||||||
case 'photo_max':
|
case 'photo_max':
|
||||||
$response[$i]->photo_max = $usr->getAvatarURL();
|
$response[$i]->photo_max = $usr->getAvatarURL();
|
||||||
break;
|
break;
|
||||||
case 'status':
|
case 'status':
|
||||||
$response[$i]->status = $usr->getStatus();
|
if($usr->getStatus() != null)
|
||||||
break;
|
$response[$i]->status = $usr->getStatus();
|
||||||
case 'screen_name':
|
break;
|
||||||
$response[$i]->screen_name = $usr->getShortCode();
|
case 'screen_name':
|
||||||
break;
|
if($usr->getShortCode() != null)
|
||||||
case 'music':
|
$response[$i]->screen_name = $usr->getShortCode();
|
||||||
$response[$i]->music = $usr->getFavoriteMusic();
|
break;
|
||||||
break;
|
case 'friend_status':
|
||||||
case 'movies':
|
switch($usr->getSubscriptionStatus($this->getUser())) {
|
||||||
$response[$i]->movies = $usr->getFavoriteFilms();
|
case 3:
|
||||||
break;
|
case 0:
|
||||||
case 'tv':
|
$response[$i]->friend_status = $usr->getSubscriptionStatus($this->getUser());
|
||||||
$response[$i]->tv = $usr->getFavoriteShows();
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 'books':
|
$response[$i]->friend_status = 2;
|
||||||
$response[$i]->books = $usr->getFavoriteBooks();
|
break;
|
||||||
break;
|
case 2:
|
||||||
case 'city':
|
$response[$i]->friend_status = 1;
|
||||||
$response[$i]->city = $usr->getCity();
|
break;
|
||||||
break;
|
}
|
||||||
case 'interests':
|
break;
|
||||||
$response[$i]->interests = $usr->getInterests();
|
case 'last_seen':
|
||||||
break;
|
if ($usr->onlineStatus() == 0) {
|
||||||
|
$response[$i]->last_seen = (object) [
|
||||||
|
"platform" => 1,
|
||||||
|
"time" => $usr->getOnline()->timestamp()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
case 'music':
|
||||||
|
$response[$i]->music = $usr->getFavoriteMusic();
|
||||||
|
break;
|
||||||
|
case 'movies':
|
||||||
|
$response[$i]->movies = $usr->getFavoriteFilms();
|
||||||
|
break;
|
||||||
|
case 'tv':
|
||||||
|
$response[$i]->tv = $usr->getFavoriteShows();
|
||||||
|
break;
|
||||||
|
case 'books':
|
||||||
|
$response[$i]->books = $usr->getFavoriteBooks();
|
||||||
|
break;
|
||||||
|
case 'city':
|
||||||
|
$response[$i]->city = $usr->getCity();
|
||||||
|
break;
|
||||||
|
case 'interests':
|
||||||
|
$response[$i]->interests = $usr->getInterests();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// НУЖЕН фикс - либо из-за моего дебилизма, либо из-за сегментации котлеток некоторые пользовали отображаются как онлайн, хотя лол, если зайти на страницу, то оный уже офлайн
|
if($usr->getOnline()->timestamp() + 300 > time()) {
|
||||||
if($usr->getOnline()->timestamp() + 2505600 > time()) {
|
$response[$i]->online = 1;
|
||||||
$response[$i]->online = 1;
|
}else{
|
||||||
}else{
|
$response[$i]->online = 0;
|
||||||
$response[$i]->online = 0;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue