Skip to content
Snippets Groups Projects
VideoClip.php 2.29 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * @copyright  2020 Ad Aures
    
     * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
     * @link       https://castopod.org/
     */
    
    namespace App\Entities\Clip;
    
    
    use Modules\Media\Entities\Video;
    use Modules\Media\Models\MediaModel;
    
     * @property array{name:string,preview:string} $theme
    
     */
    class VideoClip extends BaseClip
    {
        protected string $type = 'video';
    
    
        public function __construct(?array $data = null)
    
            if ($this->metadata !== null && $this->metadata !== []) {
    
                $this->theme = $this->metadata['theme'];
                $this->format = $this->metadata['format'];
            }
        }
    
         * @param array{name:string,preview: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
        {
    
            $this->attributes['metadata'] = json_decode((string) $this->attributes['metadata'], true);
    
    
            $this->attributes['format'] = $format;
            $this->attributes['metadata']['format'] = $format;
    
            $this->attributes['metadata'] = json_encode($this->attributes['metadata']);
    
            return $this;
        }
    
    
        public function setMedia(File $file, string $fileKey): static
    
            if ($this->attributes['media_id'] !== null) {
                // media is already set, do nothing
                return $this;
            }
    
    
                'uploaded_by' => $this->attributes['created_by'],
    
                'updated_by'  => $this->attributes['created_by'],
    
            $this->attributes['media_id'] = (new MediaModel('video'))->saveMedia($video);