mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 23:44:11 +01:00
121 lines
3.3 KiB
PHP
121 lines
3.3 KiB
PHP
<?php
|
|
// Copyright (C) 2010 Combodo SARL
|
|
//
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; version 3 of the License.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
/**
|
|
* ormDocument
|
|
* encapsulate the behavior of a binary data set that will be stored an attribute of class AttributeBlob
|
|
*
|
|
* @author Erwan Taloc <erwan.taloc@combodo.com>
|
|
* @author Romain Quetiez <romain.quetiez@combodo.com>
|
|
* @author Denis Flaven <denis.flaven@combodo.com>
|
|
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
|
|
*/
|
|
|
|
|
|
/**
|
|
* ormDocument
|
|
* encapsulate the behavior of a binary data set that will be stored an attribute of class AttributeBlob
|
|
*
|
|
* @package itopORM
|
|
*/
|
|
|
|
class ormDocument
|
|
{
|
|
protected $m_data;
|
|
protected $m_sMimeType;
|
|
protected $m_sFileName;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct($data = null, $sMimeType = 'text/plain', $sFileName = '')
|
|
{
|
|
$this->m_data = $data;
|
|
$this->m_sMimeType = $sMimeType;
|
|
$this->m_sFileName = $sFileName;
|
|
}
|
|
|
|
public function __toString()
|
|
{
|
|
return MyHelpers::beautifulstr($this->m_data, 100, true);
|
|
}
|
|
|
|
public function IsEmpty()
|
|
{
|
|
return ($this->m_data == null);
|
|
}
|
|
|
|
public function GetMimeType()
|
|
{
|
|
return $this->m_sMimeType;
|
|
}
|
|
public function GetMainMimeType()
|
|
{
|
|
$iSeparatorPos = strpos($this->m_sMimeType, '/');
|
|
if ($iSeparatorPos > 0)
|
|
{
|
|
return substr($this->m_sMimeType, 0, $iSeparatorPos);
|
|
}
|
|
return $this->m_sMimeType;
|
|
}
|
|
|
|
public function GetData()
|
|
{
|
|
return $this->m_data;
|
|
}
|
|
|
|
public function GetFileName()
|
|
{
|
|
return $this->m_sFileName;
|
|
}
|
|
|
|
public function GetAsHTML()
|
|
{
|
|
$sResult = '';
|
|
if ($this->IsEmpty())
|
|
{
|
|
// If the filename is not empty, display it, this is used
|
|
// by the creation wizard while the file has not yet been uploaded
|
|
$sResult = $this->GetFileName();
|
|
}
|
|
else
|
|
{
|
|
$data = $this->GetData();
|
|
$sResult = $this->GetFileName().' [ '.$this->GetMimeType().', size: '.strlen($data).' byte(s) ]<br/>';
|
|
}
|
|
return $sResult;
|
|
}
|
|
|
|
/**
|
|
* Returns an hyperlink to display the document *inline*
|
|
* @return string
|
|
*/
|
|
public function GetDisplayLink($sClass, $Id, $sAttCode)
|
|
{
|
|
return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=display_document&class=$sClass&id=$Id&field=$sAttCode\" target=\"_blank\" >".$this->GetFileName()."</a>\n";
|
|
}
|
|
|
|
/**
|
|
* Returns an hyperlink to download the document (content-disposition: attachment)
|
|
* @return string
|
|
*/
|
|
public function GetDownloadLink($sClass, $Id, $sAttCode)
|
|
{
|
|
return "<a href=\"".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=download_document&class=$sClass&id=$Id&field=$sAttCode\">".$this->GetFileName()."</a>\n";
|
|
}
|
|
}
|
|
?>
|