mirror of
https://github.com/openvk/openvk
synced 2025-02-02 13:05:37 +03:00
Alexander Minkin
6ec54a379d
* feat(lint): add php-cs-fixer for linting Removing previous CODE_STYLE as it was not enforced anyway and using PER-CS 2.0. This is not the reformatting commit. * style: format code according to PER-CS 2.0 with php-cs-fixer * ci(actions): add lint action Resolves #1132.
42 lines
1 KiB
PHP
42 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace openvk\Web\Models\Entities;
|
|
|
|
use openvk\Web\Models\RowModel;
|
|
|
|
abstract class Attachable extends RowModel
|
|
{
|
|
public function getId(): int
|
|
{
|
|
return $this->getRecord()->id;
|
|
}
|
|
|
|
public function getParents(): \Traversable
|
|
{
|
|
$sel = $this->getRecord()
|
|
->related("attachments.attachable_id")
|
|
->where("attachments.attachable_type", get_class($this));
|
|
foreach ($sel as $rel) {
|
|
$repoName = $rel->target_type . "s";
|
|
$repoName = str_replace("Entities", "Repositories", $repoName);
|
|
$repo = new $repoName();
|
|
|
|
yield $repo->get($rel->target_id);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Deletes together with all references.
|
|
*/
|
|
public function delete(bool $softly = true): void
|
|
{
|
|
$this->getRecord()
|
|
->related("attachments.attachable_id")
|
|
->where("attachments.attachable_type", get_class($this))
|
|
->delete();
|
|
|
|
parent::delete();
|
|
}
|
|
}
|