New type of attribute: Blob, allowing documents in the application. Was fully developed in the core, but roughly integrated in the application... todo: file upload for edition, file download for viewing

SVN:trunk[196]
This commit is contained in:
Romain Quetiez
2009-10-22 09:12:07 +00:00
parent e6c5d3563c
commit b2a9de9d59
9 changed files with 493 additions and 123 deletions

View File

@@ -0,0 +1,78 @@
<?php
/**
* ormDocument
* encapsulate the behavior of a binary data set that will be stored an attribute of class AttributeBlob
*
* @package tbd
* @author Romain Quetiez <romainquetiez@yahoo.fr>
* @author Denis Flaven <denisflave@free.fr>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.itop.com
* @since 1.0
*/
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 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()
{
$data = $this->GetData();
switch ($this->GetMainMimeType())
{
case 'text':
return "<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n";
case 'application':
return "binary data for ".$this->GetMimeType().', size: '.strlen($data).' byte(s).';
case 'html':
default:
return "<div>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</div>\n";
}
}
}
?>