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;
use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Entities\User;
use Nette\Database\Table\ActiveRow;
@ -9,7 +13,7 @@ class Faves
private $context;
private $likes;
function __construct()
private function __construct()
{
$this->context = DatabaseConnection::i()->getContext();
$this->likes = $this->context->table("likes");
@ -25,7 +29,7 @@ class Faves
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;
$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();
}

View file

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