Skip to content

Commit

Permalink
pridanie , že zobrazuje userovi, keď on dal like
Browse files Browse the repository at this point in the history
  • Loading branch information
Filip10 committed Dec 2, 2024
1 parent 825f205 commit abf2790
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions App/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ public function likeToggle($userName)
$like->save();
}
}

public function isLiker($userName)
{
if (empty($this->id)) {
throw new \Exception("Post must be stored or loaded to check the liker.");
}

$likes = Like::getAll("post_id = ? AND liker LIKE ?", [$this->id, $userName]);

return count($likes) > 0;
}

}
14 changes: 9 additions & 5 deletions App/Views/Home/ostatne.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<?php
foreach ($data as $post) {
?>
<div class="col-md-6">
<div class="row g-0 border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div class="col-md-6 mb-3">
<div class="row g-0 border rounded overflow-hidden flex-md-row mb-2 shadow-sm h-md-250 position-relative">
<div class="col p-4 d-flex flex-column position-static">
<h3 class="mb-2"><?= $post->getNazov() ?></h3>
<div class="mb-1 text-body-secondary"><?= $post->getDatumPublikovania() ?></div>
Expand All @@ -41,7 +41,7 @@
</div>
</div>
<a href="<?= $post->getZdroj() ?>?ref=dopravanaslovensku.sk"
class="icon-link gap-1 icon-link-hover stretched-link" style="margin-bottom: 0.8em">
class="icon-link gap-1 icon-link-hover" style="margin-bottom: 0.8em">
Čítať viac
<svg class="bi">
<use xlink:href="#chevron-right"></use>
Expand All @@ -58,8 +58,12 @@ class="icon-link gap-1 icon-link-hover stretched-link" style="margin-bottom: 0.8
</svg>
</div>
</div>
<a href="<?= $link->url('like.toggle', ['id' => $post->getId()]) ?>" class="btn btn-primary btn-sm"><?= $post->getLikeCount() ?> <i class="bi bi-hand-thumbs-up"></i></a>
<?php if ($auth->isLogged() && $auth->getLoggedUserName()) { ?>
<a href="<?= $link->url('like.toggle', ['id' => $post->getId()]) ?>" class="btn btn-primary"><?= $post->getLikeCount() ?> ľudia
<?php if ($auth->isLogged() && $post->isLiker($auth->getLoggedUserName())) { ?>
vrátane vás
<?php } ?>
to označili ako užitočné</a>
<?php if ($auth->isLogged() && $auth->getLoggedUserName() == "admin") { ?>
<a href="<?= $link->url('admin.edit', ['id' => $post->getId()]) ?>" class="btn btn-primary">Upraviť</a>
<a href="<?= $link->url('admin.delete', ['id' => $post->getId()]) ?>" class="btn btn-danger">Vymazať</a>
<?php } ?>
Expand Down

0 comments on commit abf2790

Please sign in to comment.