mirror of
https://github.com/openvk/openvk
synced 2024-11-11 01:19:53 +03:00
Notes: Actual use of virtual ID
This commit is contained in:
parent
22c592c075
commit
98fd851729
5 changed files with 26 additions and 7 deletions
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
{* BEGIN ELEMENTS DESCRIPTION *}
|
||||
|
||||
{block link|strip|stripHtml}
|
||||
/note{$x->getOwner()->getId()}_{$x->getId()}
|
||||
/note{$x->getPrettyId()}
|
||||
{/block}
|
||||
|
||||
{block preview}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue