2020-08-12 14:36:18 +03:00
|
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
|
use openvk\Web\Models\Repositories\Clubs as ClubsRepo;
|
2021-10-22 23:49:25 +03:00
|
|
|
|
use openvk\Web\Models\Repositories\Users as UsersRepo;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
|
|
final class Groups extends VKAPIRequestHandler
|
|
|
|
|
{
|
2021-10-22 23:49:25 +03:00
|
|
|
|
function get(int $user_id = 0, string $fields = "", int $offset = 0, int $count = 6, bool $online = false): object
|
2020-08-12 14:36:18 +03:00
|
|
|
|
{
|
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if($user_id == 0) {
|
|
|
|
|
foreach($this->getUser()->getClubs($offset+1) as $club)
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$clbs[] = $club;
|
|
|
|
|
$clbsCount = $this->getUser()->getClubCount();
|
|
|
|
|
} else {
|
|
|
|
|
$users = new UsersRepo;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
$user = $users->get($user_id);
|
|
|
|
|
|
|
|
|
|
if(is_null($user))
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$this->fail(15, "Access denied");
|
2022-07-21 22:13:09 +03:00
|
|
|
|
|
|
|
|
|
foreach($user->getClubs($offset+1) as $club)
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$clbs[] = $club;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$clbsCount = $user->getClubCount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rClubs;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
|
|
$ic = sizeof($clbs);
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if(sizeof($clbs) > $count)
|
|
|
|
|
$ic = $count;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if(!empty($clbs)) {
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$clbs = array_slice($clbs, $offset * $count);
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
for($i=0; $i < $ic; $i++) {
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$usr = $clbs[$i];
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if(is_null($usr)) {
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i] = (object)[
|
|
|
|
|
"id" => $clbs[$i],
|
|
|
|
|
"name" => "DELETED",
|
|
|
|
|
"deactivated" => "deleted"
|
|
|
|
|
];
|
2022-07-21 22:13:09 +03:00
|
|
|
|
} else if($clbs[$i] == NULL) {
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
} else {
|
|
|
|
|
$rClubs[$i] = (object) [
|
2022-07-21 00:37:31 +03:00
|
|
|
|
"id" => $usr->getId(),
|
|
|
|
|
"name" => $usr->getName(),
|
|
|
|
|
"screen_name" => $usr->getShortCode(),
|
|
|
|
|
"is_closed" => false,
|
|
|
|
|
"can_access_closed" => true,
|
|
|
|
|
];
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$flds = explode(',', $fields);
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
2022-07-21 00:37:31 +03:00
|
|
|
|
foreach($flds as $field) {
|
2022-07-21 22:13:09 +03:00
|
|
|
|
switch($field) {
|
|
|
|
|
case "verified":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->verified = intval($usr->isVerified());
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "has_photo":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_max_orig":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_max_orig = $usr->getAvatarURL();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_max":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_max = $usr->getAvatarURL("original"); // ORIGINAL ANDREI CHINITEL 🥵🥵🥵🥵
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_50":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_50 = $usr->getAvatarURL();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_100":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_100 = $usr->getAvatarURL("tiny");
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_200":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_200 = $usr->getAvatarURL("normal");
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_200_orig":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_200_orig = $usr->getAvatarURL("normal");
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_400_orig":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->photo_400_orig = $usr->getAvatarURL("normal");
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "members_count":
|
2022-07-21 00:37:31 +03:00
|
|
|
|
$rClubs[$i]->members_count = $usr->getFollowersCount();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-21 00:37:31 +03:00
|
|
|
|
} else {
|
|
|
|
|
$rClubs = [];
|
2020-08-12 14:36:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 23:49:25 +03:00
|
|
|
|
return (object) [
|
|
|
|
|
"count" => $clbsCount,
|
|
|
|
|
"items" => $rClubs
|
|
|
|
|
];
|
2020-08-12 14:36:18 +03:00
|
|
|
|
}
|
2022-03-21 17:15:51 +03:00
|
|
|
|
|
|
|
|
|
function getById(string $group_ids = "", string $group_id = "", string $fields = ""): ?array
|
|
|
|
|
{
|
|
|
|
|
$clubs = new ClubsRepo;
|
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if($group_ids == NULL && $group_id != NULL)
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$group_ids = $group_id;
|
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if($group_ids == NULL && $group_id == NULL)
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$this->fail(100, "One of the parameters specified was missing or invalid: group_ids is undefined");
|
|
|
|
|
|
|
|
|
|
$clbs = explode(',', $group_ids);
|
|
|
|
|
$response;
|
|
|
|
|
|
|
|
|
|
$ic = sizeof($clbs);
|
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
for($i=0; $i < $ic; $i++) {
|
2022-03-21 17:15:51 +03:00
|
|
|
|
if($i > 500)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if($clbs[$i] < 0)
|
|
|
|
|
$this->fail(100, "ты ошибся чутка, у айди группы убери минус");
|
|
|
|
|
|
|
|
|
|
$clb = $clubs->get((int) $clbs[$i]);
|
2022-07-21 22:13:09 +03:00
|
|
|
|
if(is_null($clb)) {
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
|
"id" => intval($clbs[$i]),
|
|
|
|
|
"name" => "DELETED",
|
2022-03-21 17:15:51 +03:00
|
|
|
|
"screen_name" => "club".intval($clbs[$i]),
|
2022-07-21 22:13:09 +03:00
|
|
|
|
"type" => "group",
|
2022-03-21 17:15:51 +03:00
|
|
|
|
"description" => "This group was deleted or it doesn't exist"
|
|
|
|
|
];
|
2022-07-21 22:13:09 +03:00
|
|
|
|
} else if($clbs[$i] == NULL) {
|
2022-03-21 17:15:51 +03:00
|
|
|
|
|
2022-07-21 22:13:09 +03:00
|
|
|
|
} else {
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i] = (object)[
|
2022-07-21 22:13:09 +03:00
|
|
|
|
"id" => $clb->getId(),
|
|
|
|
|
"name" => $clb->getName(),
|
|
|
|
|
"screen_name" => $clb->getShortCode() ?? "club".$clb->getId(),
|
|
|
|
|
"is_closed" => false,
|
|
|
|
|
"type" => "group",
|
2022-03-21 17:15:51 +03:00
|
|
|
|
"can_access_closed" => true,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$flds = explode(',', $fields);
|
|
|
|
|
|
|
|
|
|
foreach($flds as $field) {
|
2022-07-21 22:13:09 +03:00
|
|
|
|
switch($field) {
|
|
|
|
|
case "verified":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->verified = intval($clb->isVerified());
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "has_photo":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->has_photo = is_null($clb->getAvatarPhoto()) ? 0 : 1;
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_max_orig":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->photo_max_orig = $clb->getAvatarURL();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "photo_max":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->photo_max = $clb->getAvatarURL();
|
|
|
|
|
break;
|
2022-07-23 03:47:08 +03:00
|
|
|
|
case "photo_50":
|
|
|
|
|
$response[$i]->photo_50 = $clb->getAvatarURL();
|
|
|
|
|
break;
|
|
|
|
|
case "photo_100":
|
|
|
|
|
$response[$i]->photo_100 = $clb->getAvatarURL("tiny");
|
|
|
|
|
break;
|
|
|
|
|
case "photo_200":
|
|
|
|
|
$response[$i]->photo_200 = $clb->getAvatarURL("normal");
|
|
|
|
|
break;
|
|
|
|
|
case "photo_200_orig":
|
|
|
|
|
$response[$i]->photo_200_orig = $clb->getAvatarURL("normal");
|
|
|
|
|
break;
|
|
|
|
|
case "photo_400_orig":
|
|
|
|
|
$response[$i]->photo_400_orig = $clb->getAvatarURL("normal");
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "members_count":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->members_count = $clb->getFollowersCount();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "site":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->site = $clb->getWebsite();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "description":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->desctiption = $clb->getDescription();
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "contacts":
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$contacts;
|
|
|
|
|
$contactTmp = $clb->getManagers(1, true);
|
2022-07-21 22:13:09 +03:00
|
|
|
|
|
|
|
|
|
foreach($contactTmp as $contact)
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$contacts[] = array(
|
2022-07-21 22:13:09 +03:00
|
|
|
|
"user_id" => $contact->getUser()->getId(),
|
|
|
|
|
"desc" => $contact->getComment()
|
2022-03-21 17:15:51 +03:00
|
|
|
|
);
|
2022-07-21 22:13:09 +03:00
|
|
|
|
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$response[$i]->contacts = $contacts;
|
|
|
|
|
break;
|
2022-07-21 22:13:09 +03:00
|
|
|
|
case "can_post":
|
2022-07-21 19:57:03 +03:00
|
|
|
|
if(!is_null($this->getUser()))
|
|
|
|
|
if($clb->canBeModifiedBy($this->getUser()))
|
|
|
|
|
$response[$i]->can_post = true;
|
|
|
|
|
else
|
|
|
|
|
$response[$i]->can_post = $clb->canPost();
|
2022-03-21 17:15:51 +03:00
|
|
|
|
break;
|
2022-07-23 13:45:17 +03:00
|
|
|
|
case "is_member":
|
|
|
|
|
if(!is_null($this->getUser()))
|
|
|
|
|
$response[$i]->is_member = (int) $clb->getSubscriptionStatus($this->getUser());
|
|
|
|
|
break;
|
2022-03-21 17:15:51 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
|
}
|