mirror of
https://github.com/openvk/openvk
synced 2025-03-14 21:45:22 +03:00
72 lines
1.6 KiB
PHP
72 lines
1.6 KiB
PHP
|
<?php declare(strict_types=1);
|
||
|
namespace openvk\Web\Models\Entities;
|
||
|
use openvk\Web\Models\RowModel;
|
||
|
use openvk\Web\Util\DateTime;
|
||
|
use openvk\Web\Models\Entities\{User, Club, Post};
|
||
|
use openvk\Web\Models\Repositories\{Users, Clubs, Posts};
|
||
|
use Nette\Database\Table\ActiveRow;
|
||
|
use Chandler\Database\DatabaseConnection;
|
||
|
|
||
|
class PostChangeRecord extends RowModel
|
||
|
{
|
||
|
protected $tableName = "posts_changes";
|
||
|
|
||
|
function getId(): int
|
||
|
{
|
||
|
return $this->getRecord()->id;
|
||
|
}
|
||
|
|
||
|
function getWid(): int
|
||
|
{
|
||
|
return $this->getRecord()->wall_id;
|
||
|
}
|
||
|
|
||
|
function getAuthorType(): string
|
||
|
{
|
||
|
return $this->getWid() < 0 ? "club" : "user";
|
||
|
}
|
||
|
|
||
|
function getVid(): int
|
||
|
{
|
||
|
return $this->getRecord()->virtual_id;
|
||
|
}
|
||
|
|
||
|
function getPost(): ?Post
|
||
|
{
|
||
|
return (new Posts)->getPostById($this->getWid(), $this->getVid());
|
||
|
}
|
||
|
|
||
|
function getAuthor()
|
||
|
{
|
||
|
if ($this->getAuthorType() === "club")
|
||
|
return (new Clubs)->get($this->getWid());
|
||
|
|
||
|
return (new Users)->get($this->getWid());
|
||
|
}
|
||
|
|
||
|
function getOldContent(): ?string
|
||
|
{
|
||
|
return $this->getRecord()->oldContent;
|
||
|
}
|
||
|
|
||
|
function getNewContent(): ?string
|
||
|
{
|
||
|
return $this->getRecord()->newContent;
|
||
|
}
|
||
|
|
||
|
function getCreationDate(): DateTime
|
||
|
{
|
||
|
return new DateTime($this->getRecord()->created);
|
||
|
}
|
||
|
|
||
|
function canBeApplied(string $type): bool
|
||
|
{
|
||
|
$post = $this->getPost();
|
||
|
|
||
|
if ($post->getChangeId() == $this->getId())
|
||
|
if ($post->getChangeType() == $type) return false;
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|