2020-08-12 14:36:18 +03:00
|
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
namespace openvk\VKAPI\Handlers;
|
|
|
|
|
use openvk\Web\Models\Entities\User;
|
|
|
|
|
use openvk\Web\Models\Entities\Clubs;
|
|
|
|
|
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
|
|
|
|
use openvk\Web\Models\Entities\Post;
|
|
|
|
|
use openvk\Web\Models\Entities\Postable;
|
|
|
|
|
use openvk\Web\Models\Repositories\Posts as PostsRepo;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2021-10-22 23:49:25 +03:00
|
|
|
|
if ($user_id == 0) {
|
|
|
|
|
foreach($this->getUser()->getClubs($offset+1) as $club) {
|
|
|
|
|
$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;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
|
|
$ic = sizeof($clbs);
|
|
|
|
|
|
|
|
|
|
if(sizeof($clbs) > $count) $ic = $count;
|
|
|
|
|
|
|
|
|
|
$clbs = array_slice($clbs, $offset * $count);
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i < $ic; $i++) {
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$usr = $clbs[$i];
|
2020-08-12 14:36:18 +03:00
|
|
|
|
if(is_null($usr))
|
|
|
|
|
{
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i] = (object)[
|
2020-08-12 14:36:18 +03:00
|
|
|
|
"id" => $clbs[$i],
|
2021-10-22 23:49:25 +03:00
|
|
|
|
"name" => "DELETED",
|
2020-08-12 14:36:18 +03:00
|
|
|
|
"deactivated" => "deleted"
|
|
|
|
|
];
|
2022-05-08 13:06:26 +03:00
|
|
|
|
}else if($clbs[$i] == NULL){
|
2020-08-12 14:36:18 +03:00
|
|
|
|
|
|
|
|
|
}else{
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i] = (object)[
|
2020-08-12 14:36:18 +03:00
|
|
|
|
"id" => $usr->getId(),
|
2021-10-22 23:49:25 +03:00
|
|
|
|
"name" => $usr->getName(),
|
|
|
|
|
"screen_name" => $usr->getShortCode(),
|
2020-08-12 14:36:18 +03:00
|
|
|
|
"is_closed" => false,
|
|
|
|
|
"can_access_closed" => true,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$flds = explode(',', $fields);
|
|
|
|
|
|
|
|
|
|
foreach($flds as $field) {
|
|
|
|
|
switch ($field) {
|
|
|
|
|
case 'verified':
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i]->verified = intval($usr->isVerified());
|
2020-08-12 14:36:18 +03:00
|
|
|
|
break;
|
|
|
|
|
case 'has_photo':
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i]->has_photo = is_null($usr->getAvatarPhoto()) ? 0 : 1;
|
2020-08-12 14:36:18 +03:00
|
|
|
|
break;
|
|
|
|
|
case 'photo_max_orig':
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i]->photo_max_orig = $usr->getAvatarURL();
|
2020-08-12 14:36:18 +03:00
|
|
|
|
break;
|
|
|
|
|
case 'photo_max':
|
2021-10-22 23:49:25 +03:00
|
|
|
|
$rClubs[$i]->photo_max = $usr->getAvatarURL();
|
2020-08-12 14:36:18 +03:00
|
|
|
|
break;
|
2021-10-22 23:49:25 +03:00
|
|
|
|
case 'members_count':
|
|
|
|
|
$rClubs[$i]->members_count = $usr->getFollowersCount();
|
|
|
|
|
break;
|
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
|
|
|
|
|
{
|
|
|
|
|
$this->requireUser();
|
|
|
|
|
|
|
|
|
|
$clubs = new ClubsRepo;
|
|
|
|
|
|
2022-05-08 13:06:26 +03:00
|
|
|
|
if ($group_ids == NULL && $group_id != NULL)
|
2022-03-21 17:15:51 +03:00
|
|
|
|
$group_ids = $group_id;
|
|
|
|
|
|
2022-05-08 13:06:26 +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);
|
|
|
|
|
|
|
|
|
|
for ($i=0; $i < $ic; $i++) {
|
|
|
|
|
if($i > 500)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if($clbs[$i] < 0)
|
|
|
|
|
$this->fail(100, "ты ошибся чутка, у айди группы убери минус");
|
|
|
|
|
|
|
|
|
|
$clb = $clubs->get((int) $clbs[$i]);
|
|
|
|
|
if(is_null($clb))
|
|
|
|
|
{
|
|
|
|
|
$response[$i] = (object)[
|
|
|
|
|
"id" => intval($clbs[$i]),
|
|
|
|
|
"name" => "DELETED",
|
|
|
|
|
"screen_name" => "club".intval($clbs[$i]),
|
|
|
|
|
"type" => "group",
|
|
|
|
|
"description" => "This group was deleted or it doesn't exist"
|
|
|
|
|
];
|
2022-05-08 13:06:26 +03:00
|
|
|
|
}else if($clbs[$i] == NULL){
|
2022-03-21 17:15:51 +03:00
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
$response[$i] = (object)[
|
|
|
|
|
"id" => $clb->getId(),
|
|
|
|
|
"name" => $clb->getName(),
|
|
|
|
|
"screen_name" => $clb->getShortCode() ?? "club".$clb->getId(),
|
|
|
|
|
"is_closed" => false,
|
|
|
|
|
"type" => "group",
|
|
|
|
|
"can_access_closed" => true,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$flds = explode(',', $fields);
|
|
|
|
|
|
|
|
|
|
foreach($flds as $field) {
|
|
|
|
|
switch ($field) {
|
|
|
|
|
case 'verified':
|
|
|
|
|
$response[$i]->verified = intval($clb->isVerified());
|
|
|
|
|
break;
|
|
|
|
|
case 'has_photo':
|
|
|
|
|
$response[$i]->has_photo = is_null($clb->getAvatarPhoto()) ? 0 : 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'photo_max_orig':
|
|
|
|
|
$response[$i]->photo_max_orig = $clb->getAvatarURL();
|
|
|
|
|
break;
|
|
|
|
|
case 'photo_max':
|
|
|
|
|
$response[$i]->photo_max = $clb->getAvatarURL();
|
|
|
|
|
break;
|
|
|
|
|
case 'members_count':
|
|
|
|
|
$response[$i]->members_count = $clb->getFollowersCount();
|
|
|
|
|
break;
|
|
|
|
|
case 'site':
|
|
|
|
|
$response[$i]->site = $clb->getWebsite();
|
|
|
|
|
break;
|
|
|
|
|
case 'description':
|
|
|
|
|
$response[$i]->desctiption = $clb->getDescription();
|
|
|
|
|
break;
|
|
|
|
|
case 'contacts':
|
|
|
|
|
$contacts;
|
|
|
|
|
$contactTmp = $clb->getManagers(1, true);
|
|
|
|
|
foreach($contactTmp as $contact) {
|
|
|
|
|
$contacts[] = array(
|
|
|
|
|
'user_id' => $contact->getUser()->getId(),
|
|
|
|
|
'desc' => $contact->getComment()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$response[$i]->contacts = $contacts;
|
|
|
|
|
break;
|
|
|
|
|
case 'can_post':
|
|
|
|
|
if($clb->canBeModifiedBy($this->getUser()))
|
|
|
|
|
$response[$i]->can_post = true;
|
|
|
|
|
else
|
|
|
|
|
$response[$i]->can_post = $clb->canPost();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
2020-08-12 14:36:18 +03:00
|
|
|
|
}
|