1
0

BxBaseModProfileUploaderBadgeCrop.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileUploaderBadgeCrop extends BxTemplUploaderCrop
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct ($aObject, $sStorageObject, $sUniqId, $oTemplate)
  16. {
  17. if(!empty($this->_sModule) && empty($this->_oModule))
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. parent::__construct($aObject, $sStorageObject, $sUniqId, $oTemplate ? $oTemplate : $this->_oModule->_oTemplate);
  20. }
  21. public function deleteGhostsForProfile($iProfileId, $iContentId = false)
  22. {
  23. if (!$iContentId)
  24. return parent::deleteGhostsForProfile($iProfileId, $iContentId);
  25. $CNF = $this->_oModule->_oConfig->CNF;
  26. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  27. $iCount = 0;
  28. $oStorage = BxDolStorage::getObjectInstance($this->_sStorageObject);
  29. $aGhosts = $oStorage->getGhosts($iProfileId, $iContentId, $iContentId ? true : false);
  30. foreach ($aGhosts as $aFile) {
  31. // for cover image delete only unassigned ghosts and currently set covers
  32. if ($aFile['id'] == $aContentInfo[$CNF['FIELD_BADGE']] || !in_array($aFile['id'], [$aContentInfo[$CNF['FIELD_PICTURE']], $aContentInfo[$CNF['FIELD_COVER']]]))
  33. $iCount += $oStorage->deleteFile($aFile['id']);
  34. }
  35. return $iCount;
  36. }
  37. public function getGhosts($iProfileId, $sFormat, $sImagesTranscoder = false, $iContentId = false)
  38. {
  39. $s = parent::getGhosts($iProfileId, $sFormat, $sImagesTranscoder, $iContentId);
  40. if (!$s || !$iContentId) // if we're creating new profile return all ghosts
  41. return $s;
  42. $a = array();
  43. if ($sFormat == 'array')
  44. $a = $s;
  45. else if ($sFormat == 'json')
  46. $a = json_decode($s, true);
  47. if (!$a)
  48. return $s;
  49. // filter out thumbnails
  50. $CNF = $this->_oModule->_oConfig->CNF;
  51. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  52. $aResult = array();
  53. foreach ($a as $aFile) {
  54. // for cover image show only unassigned ghosts and currently set covers
  55. if ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_BADGE']] || !in_array($aFile['file_id'], [$aContentInfo[$CNF['FIELD_PICTURE']], $aContentInfo[$CNF['FIELD_COVER']]]))
  56. $aResult[$aFile['file_id']] = $aFile;
  57. }
  58. if ('array' == $sFormat) {
  59. return $aResult;
  60. }
  61. else if ('json' == $sFormat) {
  62. return json_encode($aResult);
  63. } else { // html format is not suported for this data type
  64. return false;
  65. }
  66. }
  67. protected function isAdmin ($iContentId = 0)
  68. {
  69. return $this->_oModule->_isModerator (false);
  70. }
  71. }
  72. /** @} */