Ejemplo n.º 1
0
 /**
  * Get url for showing preview file.
  * @param FileData $fileData
  * @return string|null
  */
 public function getDataForViewFile(FileData $fileData)
 {
     if (!$this->checkRequiredInputParams($fileData->toArray(), array('file'))) {
         return null;
     }
     $seconds = (int) 300;
     $deathTime = new DateTime();
     $deathTime->add("+ {$seconds} seconds");
     $data = array('TYPE' => ExternalLinkTable::TYPE_AUTO, 'DEATH_TIME' => $deathTime);
     $specificVersionModel = $fileData->getVersion();
     if ($specificVersionModel) {
         $data['VERSION_ID'] = $specificVersionModel->getId();
     }
     $extLinkModel = $fileData->getFile()->addExternalLink($data);
     if (!$extLinkModel) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_GOOGLE_VIEWER_HANDLER_ERROR_COULD_NOT_FIND_EXT_LINK'), self::ERROR_COULD_NOT_FIND_EXT_LINK)));
         $this->errorCollection->add($fileData->getFile()->getErrors());
     }
     $extLink = Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $extLinkModel->getHash(), 'action' => 'download'), true);
     return array('id' => $extLinkModel->getHash(), 'viewUrl' => Driver::getInstance()->getUrlManager()->generateUrlForGoogleViewer($extLink), 'neededDelete' => false, 'neededCheckView' => true);
 }