diff --git a/VKAPI/Handlers/Friends.php b/VKAPI/Handlers/Friends.php index 56af8d11..51046be4 100644 --- a/VKAPI/Handlers/Friends.php +++ b/VKAPI/Handlers/Friends.php @@ -147,7 +147,7 @@ final class Friends extends VKAPIRequestHandler return $response; } - function getRequests(string $fields = "", int $offset = 0, int $count = 100, int $extended = 0): object + function getRequests(string $fields = "", int $out = 0, int $offset = 0, int $count = 100, int $extended = 0): object { if ($count >= 1000) $this->fail(100, "One of the required parameters was not passed or is invalid."); @@ -158,9 +158,18 @@ final class Friends extends VKAPIRequestHandler $offset++; $followers = []; - foreach($this->getUser()->getFollowers($offset, $count) as $follower) { - $followers[$i] = $follower->getId(); - $i++; + if ($out != 0) { + foreach($this->getUser()->getFollowers($offset, $count) as $follower) { + $followers[$i] = $follower->getId(); + $i++; + } + } + else + { + foreach($this->getUser()->getRequests($offset, $count) as $follower) { + $followers[$i] = $follower->getId(); + $i++; + } } $response = $followers; diff --git a/Web/Models/Entities/Traits/TSubscribable.php b/Web/Models/Entities/Traits/TSubscribable.php index 802bc427..7d1c0d28 100644 --- a/Web/Models/Entities/Traits/TSubscribable.php +++ b/Web/Models/Entities/Traits/TSubscribable.php @@ -39,4 +39,25 @@ trait TSubscribable $sub->delete(); return false; } + + function changeFlags(User $user, int $flags, bool $reverse): bool + { + $ctx = DatabaseConnection::i()->getContext(); + $data = [ + "follower" => $reverse ? $this->getId() : $user->getId(), + "model" => static::class, + "target" => $reverse ? $user->getId() : $this->getId(), + ]; + $sub = $ctx->table("subscriptions")->where($data); + + bdump($data); + + if (!$sub) + return false; + + $sub->update([ + 'flags' => $flags + ]); + return true; + } } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 4f1fbff1..933ab486 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -592,6 +592,16 @@ class User extends RowModel return $this->_abstractRelationCount("get-followers"); } + function getRequests(int $page = 1, int $limit = 6): \Traversable + { + return $this->_abstractRelationGenerator("get-requests", $page, $limit); + } + + function getRequestsCount(): int + { + return $this->_abstractRelationCount("get-requests"); + } + function getSubscriptions(int $page = 1, int $limit = 6): \Traversable { return $this->_abstractRelationGenerator("get-subscriptions-user", $page, $limit); diff --git a/Web/Models/sql/get-followers.tsql b/Web/Models/sql/get-followers.tsql index 552aafb8..b07b1c69 100644 --- a/Web/Models/sql/get-followers.tsql +++ b/Web/Models/sql/get-followers.tsql @@ -1,5 +1,5 @@ (SELECT DISTINCT(follower) AS __id FROM - (SELECT follower FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 + (SELECT follower, flags FROM subscriptions WHERE target=? AND model="openvk\\Web\\Models\\Entities\\User") u0 LEFT JOIN (SELECT target FROM subscriptions WHERE follower=? AND model="openvk\\Web\\Models\\Entities\\User") u1 ON u0.follower = u1.target WHERE u1.target IS NULL) u2 diff --git a/Web/Models/sql/get-requests.tsql b/Web/Models/sql/get-requests.tsql new file mode 100755 index 00000000..0220e340 --- /dev/null +++ b/Web/Models/sql/get-requests.tsql @@ -0,0 +1,6 @@ + (SELECT DISTINCT(follower) AS __id FROM + (SELECT follower FROM subscriptions WHERE target=? AND flags=0 AND model="openvk\\Web\\Models\\Entities\\User") u0 + LEFT JOIN + (SELECT target FROM subscriptions WHERE follower=? AND flags=0 AND model="openvk\\Web\\Models\\Entities\\User") u1 + ON u0.follower = u1.target WHERE u1.target IS NULL) u2 +INNER JOIN profiles ON profiles.id = u2.__id \ No newline at end of file diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index 3785e47b..1c2fa02e 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -329,9 +329,12 @@ final class UserPresenter extends OpenVKPresenter $user = $this->users->get((int) $this->postParam("id")); if(!$user) exit("Invalid state"); - $user->toggleSubscription($this->user->identity); + if ($this->postParam("act") == "rej") + $user->changeFlags($this->user->identity, 0b10000000, true); + else + $user->toggleSubscription($this->user->identity); - $this->redirect($user->getURL()); + $this->redirect($_SERVER['HTTP_REFERER']); } function renderSetAvatar() diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml index 59560a90..aa2db799 100644 --- a/Web/Presenters/templates/@layout.xml +++ b/Web/Presenters/templates/@layout.xml @@ -178,9 +178,9 @@ {_edit_button} {_my_page} {_my_friends} - + - ({$thisUser->getFollowersCount()}) + ({$thisUser->getRequestsCount()}) diff --git a/Web/Presenters/templates/User/Friends.xml b/Web/Presenters/templates/User/Friends.xml index cd546a13..40146f11 100644 --- a/Web/Presenters/templates/User/Friends.xml +++ b/Web/Presenters/templates/User/Friends.xml @@ -4,11 +4,14 @@ {var $act = $_GET["act"] ?? "friends"} {if $act == "incoming"} - {var $iterator = iterator_to_array($user->getFollowers($page))} - {var $count = $user->getFollowersCount()} + {var $iterator = iterator_to_array($user->getRequests($page))} + {var $count = $user->getRequestsCount()} {elseif $act == "outcoming"} {var $iterator = iterator_to_array($user->getSubscriptions($page))} {var $count = $user->getSubscriptionsCount()} +{elseif $act == "followers"} + {var $iterator = iterator_to_array($user->getFollowers($page))} + {var $count = $user->getFollowersCount()} {elseif $act == "online"} {var $iterator = iterator_to_array($user->getFriendsOnline($page))} {var $count = $user->getFriendsOnlineCount()} @@ -22,6 +25,8 @@ {_incoming_req} {elseif $act == "outcoming"} {_outcoming_req} + {elseif $act == "followers"} + {_followers} {elseif $act == "online"} {_friends_online} {else} @@ -38,6 +43,8 @@ {_incoming_req} {elseif $act == "outcoming"} {_outcoming_req} + {elseif $act == "followers"} + {_followers} {elseif $act == "online"} {_friends_online} {else} @@ -53,18 +60,23 @@ -
- {_req} +
+ {_req}
{/block} {block size} -
+
+
+ +
{_outcoming_req} @@ -78,6 +90,8 @@ {tr("req", $count)} {elseif $act == "outcoming"} {tr("req", $count)} + {elseif $act == "followers"} + {tr("followers", $count)} {elseif $act == "online"} {tr("friends_list_online", $count)} {else} @@ -144,6 +158,14 @@ + {if $act !== 'followers'} + + {/if} {elseif $subStatus === 2}