2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
|
|
|
use App\Models\EpisodeModel;
|
2021-08-27 10:58:22 +00:00
|
|
|
use Modules\Fediverse\Entities\Post as FediversePost;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int|null $episode_id
|
|
|
|
* @property Episode|null $episode
|
|
|
|
*/
|
2021-08-27 10:58:22 +00:00
|
|
|
class Post extends FediversePost
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Episode $episode = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2021-05-14 17:59:35 +00:00
|
|
|
* @var array<string, string>
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
|
|
|
protected $casts = [
|
2023-06-12 14:47:38 +00:00
|
|
|
'id' => 'string',
|
|
|
|
'uri' => 'string',
|
|
|
|
'actor_id' => 'integer',
|
|
|
|
'in_reply_to_id' => '?string',
|
|
|
|
'reblog_of_id' => '?string',
|
|
|
|
'episode_id' => '?integer',
|
|
|
|
'message' => 'string',
|
|
|
|
'message_html' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'favourites_count' => 'integer',
|
2023-06-12 14:47:38 +00:00
|
|
|
'reblogs_count' => 'integer',
|
|
|
|
'replies_count' => 'integer',
|
|
|
|
'created_by' => 'integer',
|
2021-04-02 17:20:02 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* Returns the post's attached episode
|
2021-04-02 17:20:02 +00:00
|
|
|
*/
|
2021-05-14 17:59:35 +00:00
|
|
|
public function getEpisode(): ?Episode
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->episode_id === null) {
|
2021-08-13 11:07:29 +00:00
|
|
|
throw new RuntimeException('Post must have an episode_id before getting episode.');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 15:47:23 +00:00
|
|
|
if (! $this->episode instanceof Episode) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->episode = (new EpisodeModel())->getEpisodeById($this->episode_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->episode;
|
|
|
|
}
|
|
|
|
}
|