Add "owner's posts' and "other's posts"

Давайте рофлить👨‍💻👨‍💻👨‍💻
This commit is contained in:
lalka2016 2023-08-28 18:08:38 +03:00
parent 2ddd4544e8
commit e1f10353e0
6 changed files with 110 additions and 5 deletions

View file

@ -49,10 +49,12 @@ final class Wall extends VKAPIRequestHandler
$cnt = $posts->getPostCountOnUserWall($owner_id);
break;
case "owner":
$this->fail(42, "Not implemented");
$iteratorv = $posts->getOwnersPostsFromWall($owner_id, 1, $count, $offset);
$cnt = $posts->getOwnersCountOnUserWall($owner_id);
break;
case "others":
$this->fail(42, "Not implemented");
$iteratorv = $posts->getOthersPostsFromWall($owner_id, 1, $count, $offset);
$cnt = $posts->getOthersCountOnUserWall($owner_id);
break;
case "postponed":
$this->fail(42, "Postponed posts are not implemented.");

View file

@ -67,6 +67,50 @@ class Posts
foreach($sel as $post)
yield new Post($post);
}
function getOwnersPostsFromWall(int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
{
$perPage ??= OPENVK_DEFAULT_PER_PAGE;
$offset ??= $perPage * ($page - 1);
$sel = $this->posts->where([
"wall" => $user,
"deleted" => false,
"suggested" => 0,
]);
if($user > 0)
$sel->where("owner", $user);
else
$sel->where("flags !=", 0);
$sel->order("created DESC")->limit($perPage, $offset);
foreach($sel as $post)
yield new Post($post);
}
function getOthersPostsFromWall(int $user, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
{
$perPage ??= OPENVK_DEFAULT_PER_PAGE;
$offset ??= $perPage * ($page - 1);
$sel = $this->posts->where([
"wall" => $user,
"deleted" => false,
"suggested" => 0,
]);
if($user > 0)
$sel->where("owner !=", $user);
else
$sel->where("flags", 0);
$sel->order("created DESC")->limit($perPage, $offset);
foreach($sel as $post)
yield new Post($post);
}
function getPostsByHashtag(string $hashtag, int $page = 1, ?int $perPage = NULL): \Traversable
{
@ -147,6 +191,22 @@ class Posts
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0]));
}
function getOwnersCountOnUserWall(int $user): int
{
if($user > 0)
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "owner" => $user]));
else
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0])->where("flags !=", 0));
}
function getOthersCountOnUserWall(int $user): int
{
if($user > 0)
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0])->where("owner !=", $user));
else
return sizeof($this->posts->where(["wall" => $user, "deleted" => 0, "suggested" => 0])->where("flags", 0));
}
function getSuggestedPosts(int $club, int $page = 1, ?int $perPage = NULL, ?int $offset = NULL): \Traversable
{
$perPage ??= OPENVK_DEFAULT_PER_PAGE;

View file

@ -66,11 +66,32 @@ final class WallPresenter extends OpenVKPresenter
$this->template->oObj = $owner;
if($user < 0)
$this->template->club = $owner;
$iterator = NULL;
$count = 0;
$type = $this->queryParam("type") ?? "all";
switch($type) {
default:
case "all":
$iterator = $this->posts->getPostsFromUsersWall($user, (int) ($_GET["p"] ?? 1));
$count = $this->posts->getPostCountOnUserWall($user);
break;
case "owners":
$iterator = $this->posts->getOwnersPostsFromWall($user, (int) ($_GET["p"] ?? 1));
$count = $this->posts->getOwnersCountOnUserWall($user);
break;
case "others":
$iterator = $this->posts->getOthersPostsFromWall($user, (int) ($_GET["p"] ?? 1));
$count = $this->posts->getOthersCountOnUserWall($user);
break;
}
$this->template->owner = $user;
$this->template->canPost = $canPost;
$this->template->count = $this->posts->getPostCountOnUserWall($user);
$this->template->posts = iterator_to_array($this->posts->getPostsFromUsersWall($user, (int) ($_GET["p"] ?? 1)));
$this->template->count = $count;
$this->template->type = $type;
$this->template->posts = iterator_to_array($iterator);
$this->template->paginatorConf = (object) [
"count" => $this->template->count,
"page" => (int) ($_GET["p"] ?? 1),

View file

@ -15,7 +15,19 @@
{block content}
<div class="content_divider">
<div>
<div n:if="$canPost" class="content_subtitle">
<div class="tabs">
<div n:attr="id => ($type != 'all' ? 'ki' : 'activetabs')" class="tab">
<a n:attr="id => ($type != 'all' ? 'ki' : 'act_tab_a')" href="/wall{$owner}">{_all_posts}</a>
</div>
<div n:attr="id => ($type != 'owners' ? 'ki' : 'activetabs')" class="tab">
<a n:attr="id => ($type != 'owners' ? 'ki' : 'act_tab_a')" href="/wall{$owner}?type=owners">{isset($club) ? tr("clubs_posts") : tr("users_posts", ovk_proc_strtr($oObj->getFirstName(), 20))}</a>
</div>
<div n:attr="id => ($type != 'others' ? 'ki' : 'activetabs')" class="tab">
<a n:attr="id => ($type != 'others' ? 'ki' : 'act_tab_a')" href="/wall{$owner}?type=others">{_others_posts}</a>
</div>
</div>
<div n:if="$canPost && $type == 'all'" class="content_subtitle">
{include "../components/textArea.xml", route => "/wall$owner/makePost"}
</div>

View file

@ -214,6 +214,11 @@
"reply" = "Reply";
"all_posts" = "All posts";
"users_posts" = "Posts by $1";
"clubs_posts" = "Group's posts";
"others_posts" = "Others posts";
/* Friends */
"friends" = "Friends";

View file

@ -192,6 +192,11 @@
"graffiti" = "Граффити";
"reply" = "Ответить";
"all_posts" = "Все записи";
"users_posts" = "Записи $1";
"clubs_posts" = "Записи сообщества";
"others_posts" = "Чужие записи";
/* Friends */
"friends" = "Друзья";