<?php

class presentPPT extends presentBase {

  public function presentPPT(Tblpresentation $pre) {
    parent::presentBase($pre);
    $this->viewRoot = 'http://d3.violet.vn/';
    $this->viewdir  = 'previews';
  }

  public function onPrivateUpload($fileName) {
    $this->present->setPrThumbnail(3);
  }

  public function getPreview($width = 500, $height = 425) {
    $player = $this->viewRoot."plugins/flash/pptPlayer.swf";
    $imgPath = $this->getViewPath(false)."images";
    $slides = $this->present->getPrSlides();
    return flash_tag($player, $width, $height, array('slides'=>$slides, 'presentation'=>$imgPath));
  }

  public function getThumbFileName($absolute = true) {
    $path = $this->getThumbPath($absolute).'images';
    if ($absolute && !file_exists($path)) {umask(0); mkdir($path, 0777, true);}
    return $path.'/Slide0.jpg';
  }

  public function getThumbnail($options = null) {
    if ($this->present->getPrThumbnail() == 3) {
      $this->present->setPrThumbnail(2);
      $this->present->save();
      $thumbSrc = $this->getViewPath().'images/Slide1.JPG';
      if (file_exists($thumbSrc)) {
        $thumb = $this->getThumbFileName();
        if (sfConversion::SizeImage(150, 100, $thumbSrc, $thumb)) {
          myUtility::track_upload($thumb, 'thumbnails');
          $this->present->setPrThumbnail(1);
          $this->present->save();
        }
      }
    }
    return parent::getThumbnail($options);
  }
}
