<?php

namespace App\Models;



use Illuminate\Database\Eloquent\Model;

class SitePreviewVideo extends Model
{

    protected $table = 'site_preview_video';

    public static function changeVideo($albumId,$voidData) {
        if (is_string($voidData)) {
            $voidData = json_decode($voidData, true);
        }
        $result = SitePreviewVideo::where('album_id', $albumId)->get();
        foreach ($voidData as $key => $value) {
            $voidData[$key]['preview_url'] = '';
            foreach ($result as $item) {
                if ($item->video_url == $value['video_src']) {
                    $voidData[$key]['preview_url'] = $item->preview_url;
                }
            }
            if (isset($voidData[$key]['order']) == false) {
                $voidData[$key]['order'] = 0;
            }
        }

        return json_encode($voidData);
    }


}
