2021-12-21 16:25:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-12-21 16:25:03 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities\Clip;
|
|
|
|
|
2021-12-24 09:49:34 +00:00
|
|
|
use CodeIgniter\Files\File;
|
2023-03-16 13:00:05 +00:00
|
|
|
use Modules\Media\Entities\Video;
|
|
|
|
use Modules\Media\Models\MediaModel;
|
2021-12-24 09:49:34 +00:00
|
|
|
|
2021-12-21 16:25:03 +00:00
|
|
|
/**
|
2021-12-24 09:49:34 +00:00
|
|
|
* @property array $theme
|
|
|
|
* @property string $format
|
2021-12-21 16:25:03 +00:00
|
|
|
*/
|
|
|
|
class VideoClip extends BaseClip
|
|
|
|
{
|
|
|
|
protected string $type = 'video';
|
|
|
|
|
2021-12-24 09:49:34 +00:00
|
|
|
/**
|
|
|
|
* @param array<string, mixed>|null $data
|
|
|
|
*/
|
2021-12-21 16:25:03 +00:00
|
|
|
public function __construct(array $data = null)
|
|
|
|
{
|
|
|
|
parent::__construct($data);
|
|
|
|
|
2021-12-24 09:49:34 +00:00
|
|
|
if ($this->metadata !== null && $this->metadata !== []) {
|
2021-12-21 16:25:03 +00:00
|
|
|
$this->theme = $this->metadata['theme'];
|
|
|
|
$this->format = $this->metadata['format'];
|
|
|
|
}
|
|
|
|
}
|
2021-12-24 09:49:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, string> $theme
|
|
|
|
*/
|
|
|
|
public function setTheme(array $theme): self
|
|
|
|
{
|
|
|
|
// TODO: change?
|
|
|
|
$this->attributes['metadata'] = json_decode($this->attributes['metadata'] ?? '[]', true);
|
|
|
|
|
|
|
|
$this->attributes['theme'] = $theme;
|
|
|
|
$this->attributes['metadata']['theme'] = $theme;
|
|
|
|
|
|
|
|
$this->attributes['metadata'] = json_encode($this->attributes['metadata']);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFormat(string $format): self
|
|
|
|
{
|
2022-10-17 14:17:50 +00:00
|
|
|
$this->attributes['metadata'] = json_decode((string) $this->attributes['metadata'], true);
|
2021-12-24 09:49:34 +00:00
|
|
|
|
|
|
|
$this->attributes['format'] = $format;
|
|
|
|
$this->attributes['metadata']['format'] = $format;
|
|
|
|
|
|
|
|
$this->attributes['metadata'] = json_encode($this->attributes['metadata']);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-03-16 13:00:05 +00:00
|
|
|
public function setMedia(File $file, string $fileKey): static
|
2021-12-24 09:49:34 +00:00
|
|
|
{
|
2022-01-21 17:25:27 +00:00
|
|
|
if ($this->attributes['media_id'] !== null) {
|
|
|
|
// media is already set, do nothing
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-12-24 09:49:34 +00:00
|
|
|
$video = new Video([
|
2023-06-12 14:47:38 +00:00
|
|
|
'file_key' => $fileKey,
|
2021-12-24 09:49:34 +00:00
|
|
|
'language_code' => $this->getPodcast()
|
2023-03-16 13:00:05 +00:00
|
|
|
->language_code,
|
2021-12-24 09:49:34 +00:00
|
|
|
'uploaded_by' => $this->attributes['created_by'],
|
2023-06-12 14:47:38 +00:00
|
|
|
'updated_by' => $this->attributes['created_by'],
|
2021-12-24 09:49:34 +00:00
|
|
|
]);
|
|
|
|
$video->setFile($file);
|
|
|
|
|
2023-03-16 13:00:05 +00:00
|
|
|
$this->attributes['media_id'] = (new MediaModel('video'))->saveMedia($video);
|
2021-12-24 09:49:34 +00:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2021-12-21 16:25:03 +00:00
|
|
|
}
|