This commit is contained in:
mrilyew 2025-03-02 20:20:51 +03:00
parent 09d4855e75
commit b23b770634
2 changed files with 20 additions and 16 deletions

View file

@ -1,5 +1,9 @@
<?php declare(strict_types=1); <?php
declare(strict_types=1);
namespace openvk\Web\Models\Repositories; namespace openvk\Web\Models\Repositories;
use Chandler\Database\DatabaseConnection; use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Entities\User; use openvk\Web\Models\Entities\User;
use Nette\Database\Table\ActiveRow; use Nette\Database\Table\ActiveRow;
@ -9,7 +13,7 @@ class Faves
private $context; private $context;
private $likes; private $likes;
function __construct() private function __construct()
{ {
$this->context = DatabaseConnection::i()->getContext(); $this->context = DatabaseConnection::i()->getContext();
$this->likes = $this->context->table("likes"); $this->likes = $this->context->table("likes");
@ -25,7 +29,7 @@ class Faves
return $fetch; return $fetch;
} }
function fetchLikesSection(User $user, string $class = 'Post', int $page = 1, ?int $perPage = NULL): \Traversable public function fetchLikesSection(User $user, string $class = 'Post', int $page = 1, ?int $perPage = NULL): \Traversable
{ {
$perPage ??= OPENVK_DEFAULT_PER_PAGE; $perPage ??= OPENVK_DEFAULT_PER_PAGE;
$fetch = $this->fetchLikes($user, $class)->page($page, $perPage)->order("index DESC"); $fetch = $this->fetchLikes($user, $class)->page($page, $perPage)->order("index DESC");
@ -41,7 +45,7 @@ class Faves
} }
} }
function fetchLikesSectionCount(User $user, string $class = 'Post') public function fetchLikesSectionCount(User $user, string $class = 'Post')
{ {
return $this->fetchLikes($user, $class)->count(); return $this->fetchLikes($user, $class)->count();
} }

View file

@ -945,14 +945,14 @@ final class UserPresenter extends OpenVKPresenter
} }
} }
function renderFave(): void public function renderFave(): void
{ {
$this->assertUserLoggedIn(); $this->assertUserLoggedIn();
$page = (int) ($this->queryParam("p") ?? 1); $page = (int) ($this->queryParam("p") ?? 1);
$section = $this->queryParam("section") ?? "posts"; $section = $this->queryParam("section") ?? "posts";
$display_section = "posts"; $display_section = "posts";
$data = NULL; $data = null;
$count = 0; $count = 0;
switch ($section) { switch ($section) {
@ -962,26 +962,26 @@ final class UserPresenter extends OpenVKPresenter
case 'wall': case 'wall':
case 'post': case 'post':
case 'posts': case 'posts':
$data = (new Faves)->fetchLikesSection($this->user->identity, 'Post', $page); $data = (new Faves())->fetchLikesSection($this->user->identity, 'Post', $page);
$count = (new Faves)->fetchLikesSectionCount($this->user->identity, 'Post'); $count = (new Faves())->fetchLikesSectionCount($this->user->identity, 'Post');
$display_section = "posts"; $display_section = "posts";
break; break;
case 'comment': case 'comment':
case 'comments': case 'comments':
$data = (new Faves)->fetchLikesSection($this->user->identity, 'Comment', $page); $data = (new Faves())->fetchLikesSection($this->user->identity, 'Comment', $page);
$count = (new Faves)->fetchLikesSectionCount($this->user->identity, 'Comment'); $count = (new Faves())->fetchLikesSectionCount($this->user->identity, 'Comment');
$display_section = "comments"; $display_section = "comments";
break; break;
case 'photo': case 'photo':
case 'photos': case 'photos':
$data = (new Faves)->fetchLikesSection($this->user->identity, 'Photo', $page); $data = (new Faves())->fetchLikesSection($this->user->identity, 'Photo', $page);
$count = (new Faves)->fetchLikesSectionCount($this->user->identity, 'Photo'); $count = (new Faves())->fetchLikesSectionCount($this->user->identity, 'Photo');
$display_section = "photos"; $display_section = "photos";
break; break;
case 'video': case 'video':
case 'videos': case 'videos':
$data = (new Faves)->fetchLikesSection($this->user->identity, 'Video', $page); $data = (new Faves())->fetchLikesSection($this->user->identity, 'Video', $page);
$count = (new Faves)->fetchLikesSectionCount($this->user->identity, 'Video'); $count = (new Faves())->fetchLikesSectionCount($this->user->identity, 'Video');
$display_section = "videos"; $display_section = "videos";
break; break;
} }