Skip to content

Instantly share code, notes, and snippets.

@firecentaur
Created May 28, 2020 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save firecentaur/3bfec6519af621bdc624062e776a3cfc to your computer and use it in GitHub Desktop.
Save firecentaur/3bfec6519af621bdc624062e776a3cfc to your computer and use it in GitHub Desktop.
getVideoMapData
static public function getVideoMapData($video){
/**
* @var $video Video
* var/class
*/
$homepageTags = $video->getHomePageTags();
$homepageTagsArr = [];
foreach ($homepageTags as $hTag) {
if ($hTag->id === "" || !$hTag->id || $hTag->id === null) {
continue;
}
$homepageTagsArr[] = [
'id' => $hTag->id,
'metaType' => $hTag->metaType,
'channel_name' => $hTag->content,
'channel_order' => 0 //$this->getHomePageOrdering($hTag->content, $channels)
];
}
if ($video->featured === 1 || $video->featured === "1") {
$featured = "yes";
} else {
$featured = "no";
}
if ($video->flag === "invalid") {
$flag = "invalid";
} else {
$flag = "valid";
}
$sql = "select n.id, n.subject, n.published_at from newsletter_item i inner join newsletter n on n.id = i.newsletter_id where i.video_id = :video_id ";
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$vid = $video->id;
$command->bindParam(":video_id", $vid, PDO::PARAM_STR);
$newsletters = $command->queryAll();
$newslettersArr = [];
/**
* @var $newslettersData NewsletterItem[]
* var/class
*/
foreach ($newsletters as $newsletter) {
if (is_object($newsletter)) {
if ($newsletter->id === "" || !$newsletter->id || $newsletter->id === null) {
continue;
}
$newsletterName = $newsletter->subject;
$newslettersArr[] = [
'id' => $newsletter->id,
'name' => $newsletterName,
'published_at' => $newsletter->published_at
];
}
}
/**
* @var $video Video
*
* var/class
*/
$videoMapData = array(
'id' => $video->id, //id of video
'name' => $video->name,
'summary' => $video->summary,
'cefr' => $video->cefr,
'video_name' => $video->name,
'uid' => $video->uid, //userid
'order' => $video->order,
'unlocked' => $video->unlocked,
'vid_url' => $video->vidurl, //youtube url
'newsletters' => $newslettersArr,
'duration' => $video->duration,
'youtube_published_at' => $video->youtube_published_at,
'update_time' => $video->update_time,
'channelName' => $video->channelName,
'channelId' => $video->channelId,
'date_added_to_movie_english' => $video->create_time,
'source_id' => $video->vidid, //youtube id
'number_of_views' => $video->views,
'provider' => $video->provider,
'publish' => $video->publish,
'publishedAt' => $video->publishedAt,
'flag' => $flag,
'parent_id' => $video->fid,
'parent_type' => $video->parent_type,
'type' => $video->type,
'featured' => $featured,
'featuredOrder' => $video->featured_order,
'views' => $video->views,
'breadcrumbs' => $video->getBreadcrumbs(),
'homepage_tags' => $homepageTagsArr,
'tags' => [],//gets filled below
'subtitles' => [],//gets filled below
'questions' => []//gets filled below
);
$source_id = $video->vidid;
$videoMapData['posters'] = [];
$videoMapData['posters'][] = ['img' => "http://img.youtube.com/vi/$source_id/0.jpg"];
$videoMapData['posters'][] = ['img' => "http://img.youtube.com/vi/$source_id/1.jpg"];
$videoMapData['posters'][] = ['img' => "http://img.youtube.com/vi/$source_id/2.jpg"];
$subtitles = Video::getAllSubtitlesStatic($video->id);
$subindexes = FireHelper::arrayIdsToCsv($subtitles);
$subindexesArr = str_getcsv($subindexes);
$subs = [];
$translations = $video->getTranslations('id,text,parentid,parent_type,langcode,category');
foreach ($subtitles as $subtitle) {
$myIndex = array_search($subtitle['id'], $subindexesArr);
$sub = $subtitle;
$sub['video_parent_type'] = $video->parent_type;
$sub['video_parent_id'] = $video->fid;
$sub['myIndex'] = $myIndex;
$subId = $sub['id'];
$myTranslations = array_filter(
$translations,
function ($trans) use ($subId) {
return $trans['parentid'] == $subId;
}
);
$sub['translations'] = $myTranslations;
$subs[] = $sub;
}
$videoMapData['subtitles'] = $subs;
$videoMapData['tags'] = VideoLibraryTag::getTags($video->id);
return $videoMapData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment