<?php

class presentVIOLET extends presentBase {

  /**
   * Upload new presentation
   * @param $fileName: Name of file for processing
   *  - Unpack zip file
   *  - Change player from Scenario.xvl to player.swf
   *  - Copy default Player.swf
   */
  public function onPrivateUpload($fileName) {
    myZip::Unzip($fileName, $this->getViewPath());

    $playerName = $this->present->getPrPlayerName();
    $dirs = explode('/', $playerName);
    array_pop($dirs);
    $playerName = join('/', $dirs) . '/player.swf';
    $this->present->setPrPlayerName($playerName);

    $playerName = $this->getViewPath().$playerName;
    $sourcePlayer = sfConfig::get('sf_web_dir') . '/plugins/flash/Player.swf';
    rename($playerName, $playerName . '.swf');
    copy($sourcePlayer, $playerName);
    $this->present->setPrThumbnail(3);
  }

  public function getPlayerUrl() {
    return $this->getViewPath(false) . $this->present->getPrPlayerName();
  }

  public function getPreview($width = 500, $height = 375) {
    return flash_tag($this->getPlayerUrl(), $width, $height);
  }

  public function getThumbnail($options = null) {
    if ($this->present->getPrThumbnail() == 3) {
      $this->present->setPrThumbnail(2);
      $this->present->save();
      $thumbSrc = $this->getViewPath().'thumbnail.jpg';
      if (file_exists($thumbSrc)) {
        $thumb = $this->getThumbFileName();
        if (copy($thumbSrc, $thumb)) {
          myUtility::track_upload($thumb, 'thumbnails');
          $this->present->setPrThumbnail(1);
          $this->present->save();
        }
      }
    }
    return parent::getThumbnail($options);
  }
}
