<?php
class docVideo extends docBase {

  public function getPreview($width = 352, $height = 308) {
    return flash_tag(
    $this->viewRoot.'plugins/flash/flvPlayer.swf', $width, $height,
    array('file'=>$this->getPreviewUrl(), 'repeat'=>false));
  }

  public function onPrivateUpload($tempFile)
  {
    $errEx = new Exception('Cấu trúc video đưa lên không hợp lệ, hãy kiểm tra xem video này có xem được trên máy bạn hay không');
    $info = sfConversion::GetVideoInfo($tempFile);
    $format = $info['ID_VIDEO_FORMAT'];
    if (!isset($format)) throw $errEx;

    $this->doc->setDocWidth($info['ID_VIDEO_WIDTH']);
    $this->doc->setDocHeight($info['ID_VIDEO_HEIGHT']);

    myUtility::log("Create thumbnail and FLV $doc_id", "uploads.log");
    if ($ext == 'flv') {
      chmod($tempFile, 0777);
      sfConversion::FlvAddMeta($tempFile);
    } else {
      $tempFlv = $tempFile.'.flv';
      if (!sfConversion::MovieToFlv($tempFile, $tempFlv)) throw $errEx;
      sfConversion::FlvAddMeta($tempFlv);
      rename($tempFlv, $this->getFullFileName());
      myUtility::track_upload($this->getFullFileName(), 'resources');
    }

    if (sfConversion::FlvToThumbnail($tempFile, $tempFile.'.jpg')) {
      rename($tempFile.'.jpg', $this->getThumbFileName());
      myUtility::track_upload($this->getThumbFileName(), 'thumbnails');
      $this->doc->setDocThumbnail(1);
    } else {
      $this->doc->setDocThumbnail(2);
    }
  }
}
?>
