2025-01-31 18:20:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-12-12 02:23:42 +03:00
|
|
|
namespace openvk\Web\Models\Entities\Traits;
|
|
|
|
|
|
|
|
use openvk\Web\Models\Entities\Photo;
|
|
|
|
use openvk\Web\Models\Repositories\Photos;
|
|
|
|
|
2025-01-31 18:20:13 +03:00
|
|
|
trait TBackDrops
|
|
|
|
{
|
|
|
|
public function getBackDropPictureURLs(): ?array
|
2022-12-12 02:23:42 +03:00
|
|
|
{
|
|
|
|
$photo1 = $this->getRecord()->backdrop_1;
|
|
|
|
$photo2 = $this->getRecord()->backdrop_2;
|
2025-01-31 18:20:13 +03:00
|
|
|
if (is_null($photo1) && is_null($photo2)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$photo1obj = $photo2obj = null;
|
|
|
|
if (!is_null($photo1)) {
|
|
|
|
$photo1obj = (new Photos())->get($photo1);
|
|
|
|
}
|
|
|
|
if (!is_null($photo2)) {
|
|
|
|
$photo2obj = (new Photos())->get($photo2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($photo1obj) && is_null($photo2obj)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-12 02:23:42 +03:00
|
|
|
return [
|
|
|
|
is_null($photo1obj) ? "" : $photo1obj->getURL(),
|
|
|
|
is_null($photo2obj) ? "" : $photo2obj->getURL(),
|
|
|
|
];
|
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function setBackDropPictures(?Photo $first, ?Photo $second): void
|
2022-12-12 02:23:42 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
if (!is_null($first)) {
|
2022-12-12 02:23:42 +03:00
|
|
|
$this->stateChanges("backdrop_1", $first->getId());
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_null($second)) {
|
2022-12-12 02:23:42 +03:00
|
|
|
$this->stateChanges("backdrop_2", $second->getId());
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|
2022-12-12 02:23:42 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
|
|
|
|
public function unsetBackDropPictures(): void
|
2022-12-12 02:23:42 +03:00
|
|
|
{
|
2025-01-31 18:20:13 +03:00
|
|
|
$this->stateChanges("backdrop_1", null);
|
|
|
|
$this->stateChanges("backdrop_2", null);
|
2022-12-12 02:23:42 +03:00
|
|
|
}
|
2025-01-31 18:20:13 +03:00
|
|
|
}
|