ormdocument.class.inc.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * ormDocument
  4. * encapsulate the behavior of a binary data set that will be stored an attribute of class AttributeBlob
  5. *
  6. * @package tbd
  7. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  8. * @author Denis Flaven <denisflave@free.fr>
  9. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  10. * @link www.itop.com
  11. * @since 1.0
  12. */
  13. class ormDocument
  14. {
  15. protected $m_data;
  16. protected $m_sMimeType;
  17. protected $m_sFileName;
  18. /**
  19. * Constructor
  20. */
  21. public function __construct($data = null, $sMimeType = 'text/plain', $sFileName = '')
  22. {
  23. $this->m_data = $data;
  24. $this->m_sMimeType = $sMimeType;
  25. $this->m_sFileName = $sFileName;
  26. }
  27. public function __toString()
  28. {
  29. return MyHelpers::beautifulstr($this->m_data, 100, true);
  30. }
  31. public function GetMimeType()
  32. {
  33. return $this->m_sMimeType;
  34. }
  35. public function GetMainMimeType()
  36. {
  37. $iSeparatorPos = strpos($this->m_sMimeType, '/');
  38. if ($iSeparatorPos > 0)
  39. {
  40. return substr($this->m_sMimeType, 0, $iSeparatorPos);
  41. }
  42. return $this->m_sMimeType;
  43. }
  44. public function GetData()
  45. {
  46. return $this->m_data;
  47. }
  48. public function GetFileName()
  49. {
  50. return $this->m_sFileName;
  51. }
  52. public function GetAsHTML()
  53. {
  54. $data = $this->GetData();
  55. switch ($this->GetMainMimeType())
  56. {
  57. case 'text':
  58. return "<pre>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</pre>\n";
  59. case 'application':
  60. return "binary data for ".$this->GetMimeType().', size: '.strlen($data).' byte(s).';
  61. case 'html':
  62. default:
  63. return "<div>".htmlentities(MyHelpers::beautifulstr($data, 1000, true))."</div>\n";
  64. }
  65. }
  66. }
  67. ?>