blobfield.class.inc.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. namespace Combodo\iTop\Form\Field;
  19. use \utils;
  20. use \Dict;
  21. use \ormDocument;
  22. use \Combodo\iTop\Form\Field\Field;
  23. /**
  24. * Description of BlobField
  25. *
  26. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  27. */
  28. class BlobField extends Field
  29. {
  30. protected $sDownloadUrl;
  31. protected $sDisplayUrl;
  32. public function GetDownloadUrl()
  33. {
  34. return $this->sDownloadUrl;
  35. }
  36. public function GetDisplayUrl()
  37. {
  38. return $this->sDisplayUrl;
  39. }
  40. public function SetDownloadUrl($sDownloadUrl)
  41. {
  42. $this->sDownloadUrl = $sDownloadUrl;
  43. return $this;
  44. }
  45. public function SetDisplayUrl($sDisplayUrl)
  46. {
  47. $this->sDisplayUrl = $sDisplayUrl;
  48. return $this;
  49. }
  50. public function GetCurrentValue()
  51. {
  52. return $this->currentValue->GetFileName();
  53. }
  54. public function GetDisplayValue()
  55. {
  56. if ($this->currentValue->IsEmpty())
  57. {
  58. $sValue = Dict::S('Portal:File:None');
  59. }
  60. else
  61. {
  62. $sFilename = $this->currentValue->GetFileName();
  63. $iSize = utils::BytesToFriendlyFormat(strlen($this->currentValue->GetData()));
  64. $sOpenLink = $this->GetDisplayUrl();
  65. $sDownloadLink = $this->GetDownloadUrl();
  66. $sValue = Dict::Format('Portal:File:DisplayInfo+', $sFilename, $iSize, $sOpenLink, $sDownloadLink);
  67. }
  68. return $sValue;
  69. }
  70. }