2020-06-07 19:04:43 +03:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Entities;
|
2021-12-04 22:46:26 +03:00
|
|
|
use openvk\Web\Models\Repositories\Clubs;
|
|
|
|
use openvk\Web\Models\RowModel;
|
2020-06-07 19:04:43 +03:00
|
|
|
|
|
|
|
class Comment extends Post
|
|
|
|
{
|
|
|
|
protected $tableName = "comments";
|
|
|
|
protected $upperNodeReferenceColumnName = "owner";
|
|
|
|
|
|
|
|
function getPrettyId(): string
|
|
|
|
{
|
|
|
|
return $this->getRecord()->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVirtualId(): int
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTarget(): ?Postable
|
|
|
|
{
|
|
|
|
$entityClassName = $this->getRecord()->model;
|
|
|
|
$repoClassName = str_replace("Entities", "Repositories", $entityClassName) . "s";
|
|
|
|
$entity = (new $repoClassName)->get($this->getRecord()->target);
|
|
|
|
|
|
|
|
return $entity;
|
|
|
|
}
|
2021-12-04 22:46:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* May return fake owner (group), if flags are [1, (*)]
|
|
|
|
*
|
|
|
|
* @param bool $honourFlags - check flags
|
|
|
|
*/
|
|
|
|
function getOwner(bool $honourFlags = true, bool $real = false): RowModel
|
|
|
|
{
|
2021-12-12 22:47:39 +03:00
|
|
|
if($honourFlags && $this->isPostedOnBehalfOfGroup() && $this->getTarget() instanceof Post)
|
|
|
|
return (new Clubs)->get(abs($this->getTarget()->getTargetWall()));
|
2021-12-04 22:46:26 +03:00
|
|
|
|
|
|
|
return parent::getOwner($honourFlags, $real);
|
|
|
|
}
|
2021-12-12 22:47:39 +03:00
|
|
|
|
|
|
|
function canBeDeletedBy(User $user): bool
|
|
|
|
{
|
|
|
|
return $this->getOwner()->getId() == $user->getId() ||
|
|
|
|
$this->getTarget()->getOwner()->getId() == $user->getId() ||
|
|
|
|
$this->getTarget() instanceof Post && $this->getTarget()->getTargetWall() < 0;
|
|
|
|
}
|
2020-06-07 19:04:43 +03:00
|
|
|
}
|