public function getVideo($options = null)
 {
     if (!isset($options["youtubeId"])) {
         die("You must specify a youtubeId param");
     }
     $this->db->where('youtubeId', $options["youtubeId"]);
     $video = $this->db->getOne('videos');
     if (strpos($video["slides"], "http") === false) {
         $video["slides"] = "https://docs.google.com/presentation/d/{$video['slides']}/embed?start=false&loop=false&delayms=3000";
     }
     $ids = explode(",", $video["related"]);
     $video["related"] = array();
     foreach ($ids as $id) {
         $this->db->where('id', $id);
         $v = $this->db->getOne('videos');
         array_push($video["related"], $v);
     }
     $video["tags"] = explode(",", $video["tags"]);
     $entries = explode("\n", $video["videoIndex"]);
     $video["videoIndex"] = array();
     foreach ($entries as $e) {
         $index = strpos($e, " ");
         $entry = array("time" => substr($e, 0, $index), "text" => substr($e, $index + 1));
         // Parse time to seconds
         $entry["seconds"] = timeToSeconds($entry["time"]);
         array_push($video["videoIndex"], $entry);
     }
     // Parse PT40M2S to 40:02
     $time = convtime($video["duration"]);
     $video["length"] = timeToSeconds($time);
     //TODO: get current progress for the user meetup_id
     $this->db->where("youtubeId", $options["youtubeId"]);
     $v = $this->db->getOne("videos");
     $this->db->where("video_id", $v["id"]);
     if (isset($options['meetupId'])) {
         $this->db->where("meetup_id", $options['meetupId']);
         $elem = $this->db->getOne("progress");
         $video["progress"] = array();
         if (!$elem) {
             foreach ($video["videoIndex"] as $entry) {
                 array_push($video["progress"], array($entry["seconds"], 0));
             }
         } else {
             $indexes = explode("|", $elem["indexes"]);
             for ($i = 0; $i < sizeof($indexes); $i++) {
                 $t = explode(",", $indexes[$i]);
                 array_push($video["progress"], array($video["videoIndex"][$i]["seconds"], $t[1]));
             }
         }
         //Skip this step when video length==0 -> webinar
         if ($video["length"]) {
             $videoNumEl = sizeof($video["progress"]);
             for ($i = 0; $i < $videoNumEl; $i++) {
                 $t0 = $video["progress"][$i][0];
                 if ($i + 1 < $videoNumEl) {
                     $t1 = $video["progress"][$i + 1][0];
                 } else {
                     $t1 = $video["length"];
                 }
                 $num = ($t1 - $t0) / $video["length"];
                 array_push($video["progress"][$i], $num);
             }
         }
     }
     return $video;
 }
<?php

require_once '../config.php';
require_once 'init.php';
$db->orderBy("publishedAt", "desc");
$date = getdate();
$db->where('eventDate', $date["year"] . "-" . $date["mon"] . "-" . $date["mday"], "<");
$db->where('status', 2);
$videos = $db->get('videos');
if ($db->count > 0) {
    $tags = array();
    for ($i = 0; $i < sizeof($videos); $i++) {
        $videos[$i]["publishedAt"] = date('d-m-Y', strtotime($videos[$i]["publishedAt"]));
        if ($videos[$i]["duration"]) {
            $videos[$i]["duration"] = convtime($videos[$i]["duration"]);
        }
        $videos[$i]["arrayTags"] = explode(",", $videos[$i]["tags"]);
        foreach ($videos[$i]["arrayTags"] as $t) {
            $t = trim($t);
            if (!in_array($t, $tags) && $t) {
                array_push($tags, $t);
            }
        }
    }
    sort($tags);
    $smarty->assign('TAGS', $tags);
    $smarty->assign('VIDEOS', $videos);
    $smarty->assign('NUMVIDEOS', $db->count - 1);
}
$smarty->display('academy.tpl');