Added a helper function to get an icon stored as an ormDocument: ormDocument::GetDownloadURL

SVN:trunk[3191]
This commit is contained in:
Romain Quetiez
2014-06-04 13:10:23 +00:00
parent d7ba4166e5
commit c4632cda1a
2 changed files with 18 additions and 1 deletions

View File

@@ -117,7 +117,18 @@ class ormDocument
{ {
return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode\">".$this->GetFileName()."</a>\n"; return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode\">".$this->GetFileName()."</a>\n";
} }
/**
* Returns an URL to download a document like an image (uses HTTP caching)
* @return string
*/
public function GetDownloadURL($sClass, $Id, $sAttCode)
{
// Compute a signature to reset the cache anytime the data changes (this is acceptable if used only with icon files)
$sSignature = md5($this->GetData());
return utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode&s=$sSignature&cache=86400";
}
public function IsPreviewAvailable() public function IsPreviewAvailable()
{ {

View File

@@ -778,9 +778,15 @@ try
case 'download_document': case 'download_document':
$id = utils::ReadParam('id', ''); $id = utils::ReadParam('id', '');
$sField = utils::ReadParam('field', ''); $sField = utils::ReadParam('field', '');
$iCacheSec = (int) utils::ReadParam('cache', 0);
if (!empty($sClass) && !empty($id) && !empty($sField)) if (!empty($sClass) && !empty($id) && !empty($sField))
{ {
DownloadDocument($oPage, $sClass, $id, $sField, 'attachment'); DownloadDocument($oPage, $sClass, $id, $sField, 'attachment');
if ($iCacheSec > 0)
{
$oPage->add_header("Expires: "); // Reset the value set in ajax_page
$oPage->add_header("Cache-Control: no-transform,public,max-age=$iCacheSec,s-maxage=$iCacheSec");
}
} }
break; break;