Notes: Actual use of virtual ID

This commit is contained in:
Ilya Prokopenko 2021-11-15 14:00:49 +03:00
parent 22c592c075
commit 98fd851729
No known key found for this signature in database
GPG key ID: 7736BBBB05F14A56
5 changed files with 26 additions and 7 deletions

View file

@ -73,6 +73,16 @@ class Note extends Postable
return $purifier->purify($this->getRecord()->source);
}
function getVirtualId(): int
{
return $this->getRecord()->virtual_id;
}
function getPrettyId(): string
{
return $this->getRecord()->owner . "_" . $this->getVirtualId();
}
function getName(): string
{
return $this->getRecord()->name;

View file

@ -33,6 +33,15 @@ class Notes
yield new Note($album);
}
function getNoteById(int $owner, int $note): ?Note
{
$note = $this->notes->where(['owner' => $owner, 'virtual_id' => $note])->fetch();
if(!is_null($note))
return new Note($note);
else
return null;
}
function getUserNotesCount(User $user): int
{
return sizeof($this->notes->where("owner", $user->getId())->where("deleted", 0));

View file

@ -31,10 +31,10 @@ final class NotesPresenter extends OpenVKPresenter
];
}
function renderView(int $owner, int $id): void
function renderView(int $owner, int $note_id): void
{
$note = $this->notes->get($id);
if(!$note || $note->getOwner()->getId() !== $owner)
$note = $this->notes->getNoteById($owner, $note_id);
if(!$note || $note->getOwner()->getId() !== $owner || $note->isDeleted())
$this->notFound();
$this->template->cCount = $note->getCommentsCount();
@ -65,7 +65,7 @@ final class NotesPresenter extends OpenVKPresenter
$note->setSource($this->postParam("html"));
$note->save();
$this->redirect("/note" . $this->user->id . "_" . $note->getId());
$this->redirect("/note" . $this->user->id . "_" . $note->getVirtualId());
}
}

View file

@ -21,7 +21,7 @@
{* BEGIN ELEMENTS DESCRIPTION *}
{block link|strip|stripHtml}
/note{$x->getOwner()->getId()}_{$x->getId()}
/note{$x->getPrettyId()}
{/block}
{block preview}

View file

@ -296,13 +296,13 @@
<div style="padding: 5px 8px 15px 8px;">
<ul class="notes_titles" n:foreach="$notes as $note">
<li class="written">
<a href="/note{$user->getId()}_{$note->getId()}">
<a href="/note{$note->getPrettyId()}">
{$note->getName()}
</a>
<small>
{$note->getPublicationTime()}
<span class="divide">|</span>
<a href="/note{$user->getId()}_{$note->getId()}">{_comments}</a>
<a href="/note{$note->getPrettyId()}">{_comments}</a>
</small>
</li>
</ul>