mirror of
https://github.com/openvk/openvk
synced 2025-06-06 22:47:01 +03:00
fix(api): simplification
This commit is contained in:
parent
a16734648c
commit
5a41f3b1b3
9 changed files with 215 additions and 520 deletions
|
@ -183,7 +183,7 @@ final class Account extends VKAPIRequestHandler
|
|||
{
|
||||
$this->requireUser();
|
||||
if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) {
|
||||
$this->fail(105, "Commerce is disabled on this instance");
|
||||
$this->fail(-105, "Commerce is disabled on this instance");
|
||||
}
|
||||
|
||||
return (object) ['votes' => $this->getUser()->getCoins()];
|
||||
|
|
|
@ -14,7 +14,7 @@ use openvk\Web\Models\Entities\{Topic, Comment, User, Photo, Video};
|
|||
|
||||
final class Board extends VKAPIRequestHandler
|
||||
{
|
||||
public function addTopic(int $group_id, string $title, string $text = "", bool $from_group = true)
|
||||
public function addTopic(int $group_id, string $title, string $text = null, bool $from_group = true)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
@ -30,6 +30,7 @@ final class Board extends VKAPIRequestHandler
|
|||
}
|
||||
|
||||
$flags = 0;
|
||||
|
||||
if ($from_group == true && $club->canBeModifiedBy($this->getUser())) {
|
||||
$flags |= 0b10000000;
|
||||
}
|
||||
|
@ -40,17 +41,23 @@ final class Board extends VKAPIRequestHandler
|
|||
$topic->setTitle(ovk_proc_strtr($title, 127));
|
||||
$topic->setCreated(time());
|
||||
$topic->setFlags($flags);
|
||||
|
||||
$topic->save();
|
||||
|
||||
if (!empty($text)) {
|
||||
$comment = new Comment();
|
||||
$comment->setOwner($this->getUser()->getId());
|
||||
$comment->setModel(get_class($topic));
|
||||
$comment->setTarget($topic->getId());
|
||||
$comment->setContent($text);
|
||||
$comment->setCreated(time());
|
||||
$comment->setFlags($flags);
|
||||
$comment->save();
|
||||
try {
|
||||
if (!empty($text)) {
|
||||
$comment = new Comment();
|
||||
$comment->setOwner($this->getUser()->getId());
|
||||
$comment->setModel(get_class($topic));
|
||||
$comment->setTarget($topic->getId());
|
||||
$comment->setContent($text);
|
||||
$comment->setCreated(time());
|
||||
$comment->setFlags($flags);
|
||||
|
||||
$comment->save();
|
||||
}
|
||||
} catch(\Throwable $e) {
|
||||
return $topic->getId();
|
||||
}
|
||||
|
||||
return $topic->getId();
|
||||
|
@ -75,32 +82,35 @@ final class Board extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
public function createComment(int $group_id, int $topic_id, string $message = "", string $attachments = "", bool $from_group = true)
|
||||
public function createComment(int $group_id, int $topic_id, string $message = "", bool $from_group = true)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
if (empty($message) && empty($attachments)) {
|
||||
if (empty($message)) {
|
||||
$this->fail(100, "Required parameter 'message' missing.");
|
||||
}
|
||||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || $topic->isDeleted() || $topic->isClosed()) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$flags = 0;
|
||||
if ($from_group != 0 && !is_null($topic->getClub()) && $topic->getClub()->canBeModifiedBy($this->user)) {
|
||||
if ($from_group != 0 && ($topic->getClub()->canBeModifiedBy($this->user))) {
|
||||
$flags |= 0b10000000;
|
||||
}
|
||||
|
||||
$comment = new Comment();
|
||||
|
||||
$comment->setOwner($this->getUser()->getId());
|
||||
$comment->setModel(get_class($topic));
|
||||
$comment->setTarget($topic->getId());
|
||||
$comment->setContent($message);
|
||||
$comment->setCreated(time());
|
||||
$comment->setFlags($flags);
|
||||
|
||||
$comment->save();
|
||||
|
||||
return $comment->getId();
|
||||
|
@ -113,7 +123,7 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
if (!$topic || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -129,7 +139,7 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || $topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
if (!$topic || $topic->isDeleted() || !$topic->canBeModifiedBy($this->getUser())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -147,7 +157,7 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
if (!$topic || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -158,75 +168,92 @@ final class Board extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
public function getComments(int $group_id, int $topic_id, bool $need_likes = false, int $start_comment_id = 0, int $offset = 0, int $count = 40, bool $extended = false, string $sort = "asc")
|
||||
public function getComments(int $group_id, int $topic_id, bool $need_likes = false, int $offset = 0, int $count = 10, bool $extended = false)
|
||||
{
|
||||
# start_comment_id ne robit
|
||||
$this->requireUser();
|
||||
|
||||
if ($count < 1 || $count > 100) {
|
||||
$this->fail(4, "Invalid count");
|
||||
}
|
||||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || $topic->isDeleted()) {
|
||||
$this->fail(5, "Invalid topic");
|
||||
if (!$topic || $topic->isDeleted()) {
|
||||
$this->fail(5, "Not found");
|
||||
}
|
||||
|
||||
$arr = [
|
||||
"items" => [],
|
||||
$obj = (object) [
|
||||
"items" => []
|
||||
];
|
||||
|
||||
$comms = array_slice(iterator_to_array($topic->getComments(1, $count + $offset)), $offset);
|
||||
foreach ($comms as $comm) {
|
||||
$arr["items"][] = $this->getApiBoardComment($comm, $need_likes);
|
||||
if ($extended) {
|
||||
$obj->profiles = [];
|
||||
$obj->groups = [];
|
||||
}
|
||||
|
||||
$comments = array_slice(iterator_to_array($topic->getComments(1, $count + $offset)), $offset);
|
||||
|
||||
foreach ($comments as $comment) {
|
||||
$obj->items[] = $comment->toVkApiStruct($this->getUser(), $need_likes);
|
||||
|
||||
if ($extended) {
|
||||
if ($comm->getOwner() instanceof \openvk\Web\Models\Entities\User) {
|
||||
$arr["profiles"][] = $comm->getOwner()->toVkApiStruct();
|
||||
$owner = $comment->getOwner();
|
||||
|
||||
if ($owner instanceof \openvk\Web\Models\Entities\User) {
|
||||
$obj->profiles[] = $owner->toVkApiStruct();
|
||||
}
|
||||
|
||||
if ($comm->getOwner() instanceof \openvk\Web\Models\Entities\Club) {
|
||||
$arr["groups"][] = $comm->getOwner()->toVkApiStruct();
|
||||
if ($owner instanceof \openvk\Web\Models\Entities\Club) {
|
||||
$obj->groups[] = $owner->toVkApiStruct();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getTopics(int $group_id, string $topic_ids = "", int $order = 1, int $offset = 0, int $count = 40, bool $extended = false, int $preview = 0, int $preview_length = 90)
|
||||
public function getTopics(int $group_id, string $topic_ids = "", int $offset = 0, int $count = 10, bool $extended = false, int $preview = 0, int $preview_length = 90)
|
||||
{
|
||||
# order и extended ничё не делают
|
||||
# TODO: $extended
|
||||
|
||||
$this->requireUser();
|
||||
|
||||
$arr = [];
|
||||
if ($count < 1 || $count > 100) {
|
||||
$this->fail(4, "Invalid count");
|
||||
}
|
||||
|
||||
$obj = (object)[];
|
||||
|
||||
$club = (new ClubsRepo())->get($group_id);
|
||||
|
||||
if (!$club || !$club->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$topics = array_slice(iterator_to_array((new TopicsRepo())->getClubTopics($club, 1, $count + $offset)), $offset);
|
||||
$arr["count"] = (new TopicsRepo())->getClubTopicsCount($club);
|
||||
$arr["items"] = [];
|
||||
$arr["default_order"] = $order;
|
||||
$arr["can_add_topics"] = $club->canBeModifiedBy($this->getUser()) ? true : ($club->isEveryoneCanCreateTopics() ? true : false);
|
||||
$arr["profiles"] = [];
|
||||
|
||||
$obj->count = (new TopicsRepo())->getClubTopicsCount($club);
|
||||
$obj->items = [];
|
||||
$obj->profiles = [];
|
||||
$obj->can_add_topics = $club->canBeModifiedBy($this->getUser()) ? true : ($club->isEveryoneCanCreateTopics() ? true : false);
|
||||
|
||||
if (empty($topic_ids)) {
|
||||
foreach ($topics as $topic) {
|
||||
if ($topic->isDeleted()) {
|
||||
continue;
|
||||
}
|
||||
$arr["items"][] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
|
||||
$obj->items[] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
|
||||
}
|
||||
} else {
|
||||
$topics = explode(',', $topic_ids);
|
||||
|
||||
foreach ($topics as $topic) {
|
||||
$id = explode("_", $topic);
|
||||
$topicy = (new TopicsRepo())->getTopicById((int) $id[0], (int) $id[1]);
|
||||
foreach ($topics as $topic_id) {
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, (int) $topic_id);
|
||||
|
||||
if ($topicy && !$topicy->isDeleted()) {
|
||||
$arr["items"][] = $topicy->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
|
||||
if ($topic && !$topic->isDeleted()) {
|
||||
$obj->items[] = $topic->toVkApiStruct($preview, $preview_length > 1 ? $preview_length : 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function openTopic(int $group_id, int $topic_id)
|
||||
|
@ -236,7 +263,7 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || !$topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
if (!$topic || !$topic->isDeleted() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -248,11 +275,6 @@ final class Board extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
public function restoreComment(int $group_id, int $topic_id, int $comment_id)
|
||||
{
|
||||
$this->fail(501, "Not implemented");
|
||||
}
|
||||
|
||||
public function unfixTopic(int $group_id, int $topic_id)
|
||||
{
|
||||
$this->requireUser();
|
||||
|
@ -260,7 +282,7 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
$topic = (new TopicsRepo())->getTopicById($group_id, $topic_id);
|
||||
|
||||
if (!$topic || !$topic->getClub() || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
if (!$topic || !$topic->getClub()->canBeModifiedBy($this->getUser())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -275,33 +297,4 @@ final class Board extends VKAPIRequestHandler
|
|||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private function getApiBoardComment(?Comment $comment, bool $need_likes = false)
|
||||
{
|
||||
$res = (object) [];
|
||||
|
||||
$res->id = $comment->getId();
|
||||
$res->from_id = $comment->getOwner()->getId();
|
||||
$res->date = $comment->getPublicationTime()->timestamp();
|
||||
$res->text = $comment->getText(false);
|
||||
$res->attachments = [];
|
||||
$res->likes = [];
|
||||
if ($need_likes) {
|
||||
$res->likes = [
|
||||
"count" => $comment->getLikesCount(),
|
||||
"user_likes" => (int) $comment->hasLikeFrom($this->getUser()),
|
||||
"can_like" => 1, # а чё типо не может ахахаххахах
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($comment->getChildren() as $attachment) {
|
||||
if ($attachment->isDeleted()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$res->attachments[] = $attachment->toVkApiStruct();
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,62 +10,44 @@ use openvk\Web\Models\Entities\Notifications\GiftNotification;
|
|||
|
||||
final class Gifts extends VKAPIRequestHandler
|
||||
{
|
||||
public function get(int $user_id = null, int $count = 10, int $offset = 0)
|
||||
public function get(int $user_id = 0, int $count = 10, int $offset = 0)
|
||||
{
|
||||
# There is no extended :)
|
||||
|
||||
$this->requireUser();
|
||||
|
||||
$i = 0;
|
||||
$i += $offset;
|
||||
$server_url = ovk_scheme(true) . $_SERVER["HTTP_HOST"];
|
||||
|
||||
if ($user_id) {
|
||||
$user = (new UsersRepo())->get($user_id);
|
||||
} else {
|
||||
$user = $this->getUser();
|
||||
if ($user_id < 1) {
|
||||
$user_id = $this->getUser()->getId();
|
||||
}
|
||||
|
||||
$user = (new UsersRepo())->get($user_id);
|
||||
|
||||
if (!$user || $user->isDeleted()) {
|
||||
$this->fail(177, "Invalid user");
|
||||
}
|
||||
|
||||
if (!$user->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
/*
|
||||
if(!$user->getPrivacyPermission('gifts.read', $this->getUser()))
|
||||
$this->fail(15, "Access denied: this user chose to hide his gifts");*/
|
||||
|
||||
|
||||
if (!$user->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$gift_item = [];
|
||||
$user_gifts = array_slice(iterator_to_array($user->getGifts(1, $count)), $offset, $count);
|
||||
|
||||
$userGifts = array_slice(iterator_to_array($user->getGifts(1, $count, false)), $offset);
|
||||
|
||||
if (sizeof($userGifts) < 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($userGifts as $gift) {
|
||||
if ($i < $count) {
|
||||
$gift_item[] = [
|
||||
"id" => $i,
|
||||
"from_id" => $gift->anon == true ? 0 : $gift->sender->getId(),
|
||||
"message" => $gift->caption == null ? "" : $gift->caption,
|
||||
"date" => $gift->sent->timestamp(),
|
||||
"gift" => [
|
||||
"id" => $gift->gift->getId(),
|
||||
"thumb_256" => $server_url . $gift->gift->getImage(2),
|
||||
"thumb_96" => $server_url . $gift->gift->getImage(2),
|
||||
"thumb_48" => $server_url . $gift->gift->getImage(2),
|
||||
],
|
||||
"privacy" => 0,
|
||||
];
|
||||
}
|
||||
$i += 1;
|
||||
foreach ($user_gifts as $gift) {
|
||||
$gift_item[] = [
|
||||
"id" => $i,
|
||||
"from_id" => $gift->anon == true ? 0 : $gift->sender->getId(),
|
||||
"message" => $gift->caption == null ? "" : $gift->caption,
|
||||
"date" => $gift->sent->timestamp(),
|
||||
"gift" => [
|
||||
"id" => $gift->gift->getId(),
|
||||
"thumb_256" => $server_url . $gift->gift->getImage(2),
|
||||
"thumb_96" => $server_url . $gift->gift->getImage(2),
|
||||
"thumb_48" => $server_url . $gift->gift->getImage(2),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return $gift_item;
|
||||
|
@ -76,14 +58,14 @@ final class Gifts extends VKAPIRequestHandler
|
|||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$user = (new UsersRepo())->get((int) $user_ids);
|
||||
|
||||
if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) {
|
||||
$this->fail(105, "Commerce is disabled on this instance");
|
||||
$this->fail(-105, "Commerce is disabled on this instance");
|
||||
}
|
||||
|
||||
$user = (new UsersRepo())->get((int) $user_ids); # FAKE прогноз погоды (в данном случае user_ids)
|
||||
|
||||
if (!$user || $user->isDeleted()) {
|
||||
$this->fail(177, "Invalid user");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$user->canBeViewedBy($this->getUser())) {
|
||||
|
@ -93,7 +75,7 @@ final class Gifts extends VKAPIRequestHandler
|
|||
$gift = (new GiftsRepo())->get($gift_id);
|
||||
|
||||
if (!$gift) {
|
||||
$this->fail(165, "Invalid gift");
|
||||
$this->fail(15, "Invalid gift");
|
||||
}
|
||||
|
||||
$price = $gift->getPrice();
|
||||
|
@ -134,24 +116,17 @@ final class Gifts extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$this->fail(501, "Not implemented");
|
||||
}
|
||||
|
||||
# в vk кстати называется gifts.getCatalog
|
||||
public function getCategories(bool $extended = false, int $page = 1)
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$cats = (new GiftsRepo())->getCategories($page);
|
||||
$categ = [];
|
||||
$i = 0;
|
||||
$server_url = ovk_scheme(true) . $_SERVER["HTTP_HOST"];
|
||||
|
||||
if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) {
|
||||
$this->fail(105, "Commerce is disabled on this instance");
|
||||
$this->fail(-105, "Commerce is disabled on this instance");
|
||||
}
|
||||
|
||||
foreach ($cats as $cat) {
|
||||
|
@ -184,17 +159,19 @@ final class Gifts extends VKAPIRequestHandler
|
|||
$this->requireUser();
|
||||
|
||||
if (!OPENVK_ROOT_CONF['openvk']['preferences']['commerce']) {
|
||||
$this->fail(105, "Commerce is disabled on this instance");
|
||||
$this->fail(-105, "Commerce is disabled on this instance");
|
||||
}
|
||||
|
||||
if (!(new GiftsRepo())->getCat($id)) {
|
||||
$this->fail(177, "Category not found");
|
||||
$gift_category = (new GiftsRepo())->getCat($id);
|
||||
|
||||
if (!$gift_category) {
|
||||
$this->fail(15, "Category not found");
|
||||
}
|
||||
|
||||
$giftz = ((new GiftsRepo())->getCat($id))->getGifts($page);
|
||||
$gifts_list = $gift_category->getGifts($page);
|
||||
$gifts = [];
|
||||
|
||||
foreach ($giftz as $gift) {
|
||||
foreach ($gifts_list as $gift) {
|
||||
$gifts[] = [
|
||||
"name" => $gift->getName(),
|
||||
"image" => $gift->getImage(2),
|
||||
|
|
|
@ -107,7 +107,6 @@ final class Groups extends VKAPIRequestHandler
|
|||
$backgrounds = $usr->getBackDropPictureURLs();
|
||||
$rClubs[$i]->background = $backgrounds;
|
||||
break;
|
||||
# unstandard feild
|
||||
case "suggested_count":
|
||||
if ($usr->getWallType() != 2) {
|
||||
$rClubs[$i]->suggested_count = null;
|
||||
|
@ -335,23 +334,6 @@ final class Groups extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
public function create(string $title, string $description = "", string $type = "group", int $public_category = 1, int $public_subcategory = 1, int $subtype = 1)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$club = new Club();
|
||||
|
||||
$club->setName($title);
|
||||
$club->setAbout($description);
|
||||
$club->setOwner($this->getUser()->getId());
|
||||
$club->save();
|
||||
|
||||
$club->toggleSubscription($this->getUser());
|
||||
|
||||
return $this->getById((string) $club->getId());
|
||||
}
|
||||
|
||||
public function edit(
|
||||
int $group_id,
|
||||
string $title = null,
|
||||
|
@ -371,13 +353,15 @@ final class Groups extends VKAPIRequestHandler
|
|||
$club = (new ClubsRepo())->get($group_id);
|
||||
|
||||
if (!$club) {
|
||||
$this->fail(203, "Club not found");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$club || !$club->canBeModifiedBy($this->getUser())) {
|
||||
$this->fail(15, "You can't modify this group.");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!empty($screen_name) && !$club->setShortcode($screen_name)) {
|
||||
$this->fail(103, "Invalid shortcode.");
|
||||
$this->fail(103, "Invalid screen_name");
|
||||
}
|
||||
|
||||
!empty($title) ? $club->setName($title) : null;
|
||||
|
@ -404,260 +388,86 @@ final class Groups extends VKAPIRequestHandler
|
|||
try {
|
||||
$club->save();
|
||||
} catch (\TypeError $e) {
|
||||
$this->fail(15, "Nothing changed");
|
||||
return 1;
|
||||
} catch (\Exception $e) {
|
||||
$this->fail(18, "An unknown error occurred: maybe you set an incorrect value?");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function getMembers(string $group_id, string $sort = "id_asc", int $offset = 0, int $count = 100, string $fields = "", string $filter = "any")
|
||||
public function getMembers(int $group_id, int $offset = 0, int $count = 10, string $fields = "")
|
||||
{
|
||||
# bdate,can_post,can_see_all_posts,can_see_audio,can_write_private_message,city,common_count,connections,contacts,country,domain,education,has_mobile,last_seen,lists,online,online_mobile,photo_100,photo_200,photo_200_orig,photo_400_orig,photo_50,photo_max,photo_max_orig,relation,relatives,schools,sex,site,status,universities
|
||||
$club = (new ClubsRepo())->get((int) $group_id);
|
||||
if (!$club) {
|
||||
$this->fail(125, "Invalid group id");
|
||||
$this->requireUser();
|
||||
|
||||
$club = (new ClubsRepo())->get($group_id);
|
||||
|
||||
if (!$club || !$club->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$sorter = "follower ASC";
|
||||
$sort_string = "follower ASC";
|
||||
$members = array_slice(iterator_to_array($club->getFollowers(1, $count, $sort_string)), $offset, $count);
|
||||
|
||||
switch ($sort) {
|
||||
default:
|
||||
case "time_asc":
|
||||
case "id_asc":
|
||||
$sorter = "follower ASC";
|
||||
break;
|
||||
case "time_desc":
|
||||
case "id_desc":
|
||||
$sorter = "follower DESC";
|
||||
break;
|
||||
}
|
||||
$obj = (object) [
|
||||
"count" => sizeof($members),
|
||||
"items" => []
|
||||
];
|
||||
|
||||
$members = array_slice(iterator_to_array($club->getFollowers(1, $count, $sorter)), $offset);
|
||||
$arr = (object) [
|
||||
"count" => count($members),
|
||||
"items" => []];
|
||||
|
||||
$filds = explode(",", $fields);
|
||||
|
||||
$i = 0;
|
||||
foreach ($members as $member) {
|
||||
if ($i > $count) {
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[] = (object) [
|
||||
"id" => $member->getId(),
|
||||
"first_name" => $member->getFirstName(),
|
||||
"last_name" => $member->getLastName(),
|
||||
];
|
||||
|
||||
foreach ($filds as $fild) {
|
||||
$canView = $member->canBeViewedBy($this->getUser());
|
||||
switch ($fild) {
|
||||
case "bdate":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->bdate = "01.01.1970";
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->bdate = $member->getBirthday() ? $member->getBirthday()->format('%e.%m.%Y') : null;
|
||||
break;
|
||||
case "can_post":
|
||||
$arr->items[$i]->can_post = $club->canBeModifiedBy($member);
|
||||
break;
|
||||
case "can_see_all_posts":
|
||||
$arr->items[$i]->can_see_all_posts = 1;
|
||||
break;
|
||||
case "can_see_audio":
|
||||
$arr->items[$i]->can_see_audio = 1;
|
||||
break;
|
||||
case "can_write_private_message":
|
||||
$arr->items[$i]->can_write_private_message = 0;
|
||||
break;
|
||||
case "common_count":
|
||||
$arr->items[$i]->common_count = 420;
|
||||
break;
|
||||
case "connections":
|
||||
$arr->items[$i]->connections = 1;
|
||||
break;
|
||||
case "contacts":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->contacts = "secret@gmail.com";
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->contacts = $member->getContactEmail();
|
||||
break;
|
||||
case "country":
|
||||
$arr->items[$i]->country = 1;
|
||||
break;
|
||||
case "domain":
|
||||
$arr->items[$i]->domain = "";
|
||||
break;
|
||||
case "education":
|
||||
$arr->items[$i]->education = "";
|
||||
break;
|
||||
case "has_mobile":
|
||||
$arr->items[$i]->has_mobile = false;
|
||||
break;
|
||||
case "last_seen":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->last_seen = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->last_seen = $member->getOnline()->timestamp();
|
||||
break;
|
||||
case "lists":
|
||||
$arr->items[$i]->lists = "";
|
||||
break;
|
||||
case "online":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->online = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->online = $member->isOnline();
|
||||
break;
|
||||
case "online_mobile":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->online_mobile = false;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->online_mobile = $member->getOnlinePlatform() == "android" || $member->getOnlinePlatform() == "iphone" || $member->getOnlinePlatform() == "mobile";
|
||||
break;
|
||||
case "photo_100":
|
||||
$arr->items[$i]->photo_100 = $member->getAvatarURL("tiny");
|
||||
break;
|
||||
case "photo_200":
|
||||
$arr->items[$i]->photo_200 = $member->getAvatarURL("normal");
|
||||
break;
|
||||
case "photo_200_orig":
|
||||
$arr->items[$i]->photo_200_orig = $member->getAvatarURL("normal");
|
||||
break;
|
||||
case "photo_400_orig":
|
||||
$arr->items[$i]->photo_400_orig = $member->getAvatarURL("normal");
|
||||
break;
|
||||
case "photo_max":
|
||||
$arr->items[$i]->photo_max = $member->getAvatarURL("original");
|
||||
break;
|
||||
case "photo_max_orig":
|
||||
$arr->items[$i]->photo_max_orig = $member->getAvatarURL();
|
||||
break;
|
||||
case "relation":
|
||||
$arr->items[$i]->relation = $member->getMaritalStatus();
|
||||
break;
|
||||
case "relatives":
|
||||
$arr->items[$i]->relatives = 0;
|
||||
break;
|
||||
case "schools":
|
||||
$arr->items[$i]->schools = 0;
|
||||
break;
|
||||
case "sex":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->sex = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->sex = $member->isFemale() ? 1 : 2;
|
||||
break;
|
||||
case "site":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->site = null;
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->site = $member->getWebsite();
|
||||
break;
|
||||
case "status":
|
||||
if (!$canView) {
|
||||
$arr->items[$i]->status = "r";
|
||||
break;
|
||||
}
|
||||
|
||||
$arr->items[$i]->status = $member->getStatus();
|
||||
break;
|
||||
case "universities":
|
||||
$arr->items[$i]->universities = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
$obj->items[] = $member->toVkApiStruct($this->getUser(), $fields);
|
||||
}
|
||||
return $arr;
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function getSettings(string $group_id)
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$club = (new ClubsRepo())->get((int) $group_id);
|
||||
|
||||
if (!$club || !$club->canBeModifiedBy($this->getUser())) {
|
||||
$this->fail(15, "You can't get settings of this group.");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$arr = (object) [
|
||||
"title" => $club->getName(),
|
||||
"description" => $club->getDescription() != null ? $club->getDescription() : "",
|
||||
"description" => $club->getDescription(),
|
||||
"address" => $club->getShortcode(),
|
||||
"wall" => $club->getWallType(), # отличается от вкшных но да ладно
|
||||
"wall" => $club->getWallType(), # is different from vk values
|
||||
"photos" => 1,
|
||||
"video" => 0,
|
||||
"audio" => $club->isEveryoneCanUploadAudios() ? 1 : 0,
|
||||
"docs" => 0,
|
||||
"docs" => 1,
|
||||
"topics" => $club->isEveryoneCanCreateTopics() == true ? 1 : 0,
|
||||
"wiki" => 0,
|
||||
"messages" => 0,
|
||||
"obscene_filter" => 0,
|
||||
"obscene_stopwords" => 0,
|
||||
"obscene_words" => "",
|
||||
"access" => 1,
|
||||
"subject" => 1,
|
||||
"subject_list" => [
|
||||
0 => "в",
|
||||
1 => "опенвк",
|
||||
2 => "нет",
|
||||
3 => "категорий",
|
||||
4 => "групп",
|
||||
],
|
||||
"rss" => "/club" . $club->getId() . "/rss",
|
||||
"website" => $club->getWebsite(),
|
||||
"age_limits" => 0,
|
||||
"market" => [],
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function isMember(string $group_id, int $user_id, string $user_ids = "", bool $extended = false)
|
||||
public function isMember(string $group_id, int $user_id, int $extended = 0)
|
||||
{
|
||||
$this->requireUser();
|
||||
$id = $user_id != null ? $user_id : explode(",", $user_ids);
|
||||
|
||||
if ($group_id < 0) {
|
||||
$this->fail(228, "Remove the minus from group_id");
|
||||
$input_club = (new ClubsRepo())->get(abs((int) $group_id));
|
||||
$input_user = (new UsersRepo())->get(abs((int) $user_id));
|
||||
|
||||
if (!$input_club || !$input_club->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$club = (new ClubsRepo())->get((int) $group_id);
|
||||
$usver = (new UsersRepo())->get((int) $id);
|
||||
|
||||
if (!$club || $group_id == 0) {
|
||||
$this->fail(203, "Invalid club");
|
||||
if (!$input_user || $input_user->isDeleted()) {
|
||||
$this->fail(15, "Not found");
|
||||
}
|
||||
|
||||
if (!$usver || $usver->isDeleted() || $user_id == 0) {
|
||||
$this->fail(30, "Invalid user");
|
||||
}
|
||||
|
||||
if ($extended == false) {
|
||||
return $club->getSubscriptionStatus($usver) ? 1 : 0;
|
||||
if ($extended == 0) {
|
||||
return $input_club->getSubscriptionStatus($input_user) ? 1 : 0;
|
||||
} else {
|
||||
return (object)
|
||||
[
|
||||
"member" => $club->getSubscriptionStatus($usver) ? 1 : 0,
|
||||
"member" => $input_club->getSubscriptionStatus($input_user) ? 1 : 0,
|
||||
"request" => 0,
|
||||
"invitation" => 0,
|
||||
"can_invite" => 0,
|
||||
|
@ -665,11 +475,4 @@ final class Groups extends VKAPIRequestHandler
|
|||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(int $group_id, int $user_id)
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$this->fail(501, "Not implemented");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,7 +118,14 @@ final class Likes extends VKAPIRequestHandler
|
|||
}
|
||||
|
||||
if (!$user->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(1984, "Access denied: you can't see this user");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($user->isPrivateLikes()) {
|
||||
return (object) [
|
||||
"liked" => 1,
|
||||
"copied" => 1,
|
||||
];
|
||||
}
|
||||
|
||||
$postable = null;
|
||||
|
|
|
@ -13,38 +13,49 @@ use openvk\Web\Models\Entities\{Note, Comment};
|
|||
|
||||
final class Notes extends VKAPIRequestHandler
|
||||
{
|
||||
public function add(string $title, string $text, int $privacy = 0, int $comment_privacy = 0, string $privacy_view = "", string $privacy_comment = "")
|
||||
public function add(string $title, string $text)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
if (empty($title)) {
|
||||
$this->fail(100, "Required parameter 'title' missing.");
|
||||
}
|
||||
|
||||
$note = new Note();
|
||||
|
||||
$note->setOwner($this->getUser()->getId());
|
||||
$note->setCreated(time());
|
||||
$note->setName($title);
|
||||
$note->setSource($text);
|
||||
$note->setEdited(time());
|
||||
|
||||
$note->save();
|
||||
|
||||
return $note->getVirtualId();
|
||||
}
|
||||
|
||||
public function createComment(string $note_id, int $owner_id, string $message, int $reply_to = 0, string $attachments = "")
|
||||
public function createComment(int $note_id, int $owner_id, string $message, string $attachments = "")
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
$note = (new NotesRepo())->getNoteById((int) $owner_id, (int) $note_id);
|
||||
|
||||
if (empty($message)) {
|
||||
$this->fail(100, "Required parameter 'message' missing.");
|
||||
}
|
||||
|
||||
$note = (new NotesRepo())->getNoteById($owner_id, $note_id);
|
||||
|
||||
if (!$note) {
|
||||
$this->fail(180, "Note not found");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($note->isDeleted()) {
|
||||
$this->fail(189, "Note is deleted");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($note->getOwner()->isDeleted()) {
|
||||
$this->fail(403, "Owner is deleted");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->canBeViewedBy($this->getUser())) {
|
||||
|
@ -52,11 +63,7 @@ final class Notes extends VKAPIRequestHandler
|
|||
}
|
||||
|
||||
if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
|
||||
$this->fail(43, "No access");
|
||||
}
|
||||
|
||||
if (empty($message) && empty($attachments)) {
|
||||
$this->fail(100, "Required parameter 'message' missing.");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$comment = new Comment();
|
||||
|
@ -67,78 +74,9 @@ final class Notes extends VKAPIRequestHandler
|
|||
$comment->setCreated(time());
|
||||
$comment->save();
|
||||
|
||||
if (!empty($attachments)) {
|
||||
$attachmentsArr = explode(",", $attachments);
|
||||
|
||||
if (sizeof($attachmentsArr) > 10) {
|
||||
$this->fail(50, "Error: too many attachments");
|
||||
}
|
||||
|
||||
foreach ($attachmentsArr as $attac) {
|
||||
$attachmentType = null;
|
||||
|
||||
if (str_contains($attac, "photo")) {
|
||||
$attachmentType = "photo";
|
||||
} elseif (str_contains($attac, "video")) {
|
||||
$attachmentType = "video";
|
||||
} else {
|
||||
$this->fail(205, "Unknown attachment type");
|
||||
}
|
||||
|
||||
$attachment = str_replace($attachmentType, "", $attac);
|
||||
|
||||
$attachmentOwner = (int) explode("_", $attachment)[0];
|
||||
$attachmentId = (int) end(explode("_", $attachment));
|
||||
|
||||
$attacc = null;
|
||||
|
||||
if ($attachmentType == "photo") {
|
||||
$attacc = (new PhotosRepo())->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
||||
if (!$attacc || $attacc->isDeleted()) {
|
||||
$this->fail(100, "Photo does not exists");
|
||||
}
|
||||
if ($attacc->getOwner()->getId() != $this->getUser()->getId()) {
|
||||
$this->fail(43, "You do not have access to this photo");
|
||||
}
|
||||
|
||||
$comment->attach($attacc);
|
||||
} elseif ($attachmentType == "video") {
|
||||
$attacc = (new VideosRepo())->getByOwnerAndVID($attachmentOwner, $attachmentId);
|
||||
if (!$attacc || $attacc->isDeleted()) {
|
||||
$this->fail(100, "Video does not exists");
|
||||
}
|
||||
if ($attacc->getOwner()->getId() != $this->getUser()->getId()) {
|
||||
$this->fail(43, "You do not have access to this video");
|
||||
}
|
||||
|
||||
$comment->attach($attacc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $comment->getId();
|
||||
}
|
||||
|
||||
public function delete(string $note_id)
|
||||
{
|
||||
$this->requireUser();
|
||||
$this->willExecuteWriteAction();
|
||||
|
||||
$note = (new NotesRepo())->get((int) $note_id);
|
||||
|
||||
if (!$note) {
|
||||
$this->fail(180, "Note not found");
|
||||
}
|
||||
|
||||
if (!$note->canBeModifiedBy($this->getUser())) {
|
||||
$this->fail(15, "Access to note denied");
|
||||
}
|
||||
|
||||
$note->delete();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function edit(string $note_id, string $title = "", string $text = "", int $privacy = 0, int $comment_privacy = 0, string $privacy_view = "", string $privacy_comment = "")
|
||||
{
|
||||
$this->requireUser();
|
||||
|
@ -147,15 +85,15 @@ final class Notes extends VKAPIRequestHandler
|
|||
$note = (new NotesRepo())->getNoteById($this->getUser()->getId(), (int) $note_id);
|
||||
|
||||
if (!$note) {
|
||||
$this->fail(180, "Note not found");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($note->isDeleted()) {
|
||||
$this->fail(189, "Note is deleted");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->canBeModifiedBy($this->getUser())) {
|
||||
$this->fail(403, "No access");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
!empty($title) ? $note->setName($title) : null;
|
||||
|
@ -168,29 +106,31 @@ final class Notes extends VKAPIRequestHandler
|
|||
return 1;
|
||||
}
|
||||
|
||||
public function get(int $user_id, string $note_ids = "", int $offset = 0, int $count = 10, int $sort = 0)
|
||||
public function get(int $user_id, string $note_ids = "", int $offset = 0, int $count = 10)
|
||||
{
|
||||
$this->requireUser();
|
||||
|
||||
$user = (new UsersRepo())->get($user_id);
|
||||
|
||||
if (!$user || $user->isDeleted()) {
|
||||
$this->fail(15, "Invalid user");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$user->getPrivacyPermission('notes.read', $this->getUser())) {
|
||||
$this->fail(15, "Access denied: this user chose to hide his notes");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$user->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$nodez = (object) [
|
||||
$notes_return_object = (object) [
|
||||
"count" => 0,
|
||||
"notes" => [],
|
||||
"items" => [],
|
||||
];
|
||||
|
||||
if (empty($note_ids)) {
|
||||
$nodez->count = (new NotesRepo())->getUserNotesCount($user);
|
||||
$notes_return_object->count = (new NotesRepo())->getUserNotesCount($user);
|
||||
|
||||
$notes = array_slice(iterator_to_array((new NotesRepo())->getUserNotes($user, 1, $count + $offset, $sort == 0 ? "ASC" : "DESC")), $offset);
|
||||
|
||||
|
@ -199,25 +139,21 @@ final class Notes extends VKAPIRequestHandler
|
|||
continue;
|
||||
}
|
||||
|
||||
$nodez->notes[] = $note->toVkApiStruct();
|
||||
$notes_return_object->items[] = $note->toVkApiStruct();
|
||||
}
|
||||
} else {
|
||||
$notes = explode(',', $note_ids);
|
||||
$notes_splitted = explode(',', $note_ids);
|
||||
|
||||
foreach ($notes as $note) {
|
||||
$id = explode("_", $note);
|
||||
foreach ($notes_splitted as $note_id) {
|
||||
$note = (new NotesRepo())->getNoteById($user_id, $note_id);
|
||||
|
||||
$items = [];
|
||||
|
||||
$note = (new NotesRepo())->getNoteById((int) $id[0], (int) $id[1]);
|
||||
if ($note && !$note->isDeleted()) {
|
||||
$nodez->notes[] = $note->toVkApiStruct();
|
||||
$nodez->count++;
|
||||
$notes_return_object->items[] = $note->toVkApiStruct();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $nodez;
|
||||
return $notes_return_object;
|
||||
}
|
||||
|
||||
public function getById(int $note_id, int $owner_id, bool $need_wiki = false)
|
||||
|
@ -227,23 +163,23 @@ final class Notes extends VKAPIRequestHandler
|
|||
$note = (new NotesRepo())->getNoteById($owner_id, $note_id);
|
||||
|
||||
if (!$note) {
|
||||
$this->fail(180, "Note not found");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($note->isDeleted()) {
|
||||
$this->fail(189, "Note is deleted");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->getOwner() || $note->getOwner()->isDeleted()) {
|
||||
$this->fail(177, "Owner does not exists");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
|
||||
$this->fail(40, "Access denied: this user chose to hide his notes");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access to note denied");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
return $note->toVkApiStruct();
|
||||
|
@ -256,23 +192,23 @@ final class Notes extends VKAPIRequestHandler
|
|||
$note = (new NotesRepo())->getNoteById($owner_id, $note_id);
|
||||
|
||||
if (!$note) {
|
||||
$this->fail(180, "Note not found");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($note->isDeleted()) {
|
||||
$this->fail(189, "Note is deleted");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->getOwner()) {
|
||||
$this->fail(177, "Owner does not exists");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->getOwner()->getPrivacyPermission('notes.read', $this->getUser())) {
|
||||
$this->fail(14, "No access");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if (!$note->canBeViewedBy($this->getUser())) {
|
||||
$this->fail(15, "Access to note denied");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$arr = (object) [
|
||||
|
@ -286,14 +222,4 @@ final class Notes extends VKAPIRequestHandler
|
|||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
public function getFriendsNotes(int $offset = 0, int $count = 0)
|
||||
{
|
||||
$this->fail(501, "Not implemented");
|
||||
}
|
||||
|
||||
public function restoreComment(int $comment_id = 0, int $owner_id = 0)
|
||||
{
|
||||
$this->fail(501, "Not implemented");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,11 +120,11 @@ final class Polls extends VKAPIRequestHandler
|
|||
$poll = (new PollsRepo())->get($poll_id);
|
||||
|
||||
if (!$poll) {
|
||||
$this->fail(251, "Invalid poll");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
if ($poll->isAnonymous()) {
|
||||
$this->fail(251, "Access denied: poll is anonymous.");
|
||||
$this->fail(15, "Access denied");
|
||||
}
|
||||
|
||||
$voters = array_slice($poll->getVoters($answer_ids, 1, $offset + $count), $offset);
|
||||
|
@ -175,10 +175,4 @@ final class Polls extends VKAPIRequestHandler
|
|||
|
||||
return $this->getById($poll->getId());
|
||||
}
|
||||
|
||||
public function edit()
|
||||
{
|
||||
#todo
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,18 +138,13 @@ class Note extends Postable
|
|||
{
|
||||
$res = (object) [];
|
||||
|
||||
$res->type = "note";
|
||||
$res->id = $this->getVirtualId();
|
||||
$res->owner_id = $this->getOwner()->getId();
|
||||
$res->title = $this->getName();
|
||||
$res->text = $this->getText();
|
||||
$res->date = $this->getPublicationTime()->timestamp();
|
||||
$res->comments = $this->getCommentsCount();
|
||||
$res->read_comments = $this->getCommentsCount();
|
||||
$res->view_url = "/note" . $this->getOwner()->getId() . "_" . $this->getVirtualId();
|
||||
$res->privacy_view = 1;
|
||||
$res->can_comment = 1;
|
||||
$res->text_wiki = "r";
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
|
|
@ -1502,7 +1502,7 @@ class User extends RowModel
|
|||
return $this->getPrivacySetting("likes.read") == User::PRIVACY_NO_ONE;
|
||||
}
|
||||
|
||||
public function toVkApiStruct(?User $user = null, string $fields = ''): object
|
||||
public function toVkApiStruct(?User $relation_user = null, string $fields = ''): object
|
||||
{
|
||||
$res = (object) [];
|
||||
|
||||
|
@ -1512,8 +1512,8 @@ class User extends RowModel
|
|||
$res->deactivated = $this->isDeactivated();
|
||||
$res->is_closed = $this->isClosed();
|
||||
|
||||
if (!is_null($user)) {
|
||||
$res->can_access_closed = (bool) $this->canBeViewedBy($user);
|
||||
if (!is_null($relation_user)) {
|
||||
$res->can_access_closed = (bool) $this->canBeViewedBy($relation_user);
|
||||
}
|
||||
|
||||
if (!is_array($fields)) {
|
||||
|
@ -1569,18 +1569,18 @@ class User extends RowModel
|
|||
$res->real_id = $this->getRealId();
|
||||
break;
|
||||
case "blacklisted_by_me":
|
||||
if (!$user) {
|
||||
if (!$relation_user) {
|
||||
break;
|
||||
}
|
||||
|
||||
$res->blacklisted_by_me = (int) $this->isBlacklistedBy($user);
|
||||
$res->blacklisted_by_me = (int) $this->isBlacklistedBy($relation_user);
|
||||
break;
|
||||
case "blacklisted":
|
||||
if (!$user) {
|
||||
if (!$relation_user) {
|
||||
break;
|
||||
}
|
||||
|
||||
$res->blacklisted = (int) $user->isBlacklistedBy($this);
|
||||
$res->blacklisted = (int) $relation_user->isBlacklistedBy($this);
|
||||
break;
|
||||
case "games":
|
||||
$res->games = $this->getFavoriteGames();
|
||||
|
|
Loading…
Reference in a new issue