BxBaseModProfileFormEntry.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/edit profile form.
  13. */
  14. class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
  15. {
  16. protected $_iAccountProfileId = 0;
  17. protected $_aImageFields = array ();
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. parent::__construct($aInfo, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) {
  23. $sInfo = $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]['info'];
  24. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
  25. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]['db']['pass'] = 'Xss';
  26. $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]['info'] = $sInfo;
  27. }
  28. if (!empty($CNF['FIELD_PICTURE']) && isset($this->aInputs[$CNF['FIELD_PICTURE']])) {
  29. $this->_aImageFields[$CNF['FIELD_PICTURE']] = array (
  30. 'storage_object' => $CNF['OBJECT_STORAGE'],
  31. 'images_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'],
  32. 'uploaders' => $CNF['OBJECT_UPLOADERS_PICTURE'],
  33. );
  34. }
  35. if (!empty($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  36. $this->_aImageFields[$CNF['FIELD_COVER']] = array (
  37. 'storage_object' => $CNF['OBJECT_STORAGE_COVER'],
  38. 'images_transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_COVER_THUMB'],
  39. 'uploaders' => $CNF['OBJECT_UPLOADERS_COVER'],
  40. );
  41. }
  42. foreach ($this->_aImageFields as $sField => $aParams) {
  43. $this->aInputs[$sField]['storage_object'] = $aParams['storage_object'];
  44. $this->aInputs[$sField]['uploaders'] = !empty($this->aInputs[$sField]['value']) ? unserialize($this->aInputs[$sField]['value']) : $aParams['uploaders'];
  45. $this->aInputs[$sField]['images_transcoder'] = $aParams['images_transcoder'];
  46. $this->aInputs[$sField]['storage_private'] = 0;
  47. $this->aInputs[$sField]['multiple'] = false;
  48. $this->aInputs[$sField]['content_id'] = 0;
  49. $this->aInputs[$sField]['ghost_template'] = '';
  50. }
  51. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  52. if ($oAccountProfile)
  53. $this->_iAccountProfileId = $oAccountProfile->id();
  54. }
  55. function initChecker ($aValues = array (), $aSpecificValues = array())
  56. {
  57. $CNF = &$this->_oModule->_oConfig->CNF;
  58. $aContentInfo = isset($CNF['FIELD_ID']) && isset($aValues[$CNF['FIELD_ID']]) ? $this->_oModule->_oDb->getContentInfoById ($aValues[$CNF['FIELD_ID']]) : array();
  59. foreach ($this->_aImageFields as $sField => $aParams) {
  60. if ($aValues && !empty($aValues[$CNF['FIELD_ID']]))
  61. $this->aInputs[$sField]['content_id'] = $aValues[$CNF['FIELD_ID']];
  62. $this->aInputs[$sField]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $this->_getPhotoGhostTmplVars($sField, $aContentInfo));
  63. }
  64. parent::initChecker($aValues, $aSpecificValues);
  65. }
  66. public function insert ($aValsToAdd = array(), $isIgnore = false)
  67. {
  68. $CNF = &$this->_oModule->_oConfig->CNF;
  69. if (isset($CNF['FIELD_PICTURE']))
  70. $aValsToAdd[$CNF['FIELD_PICTURE']] = 0; // we will update this field later, since we don't know content id yet
  71. return parent::insert ($aValsToAdd, $isIgnore);
  72. }
  73. function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  74. {
  75. $CNF = &$this->_oModule->_oConfig->CNF;
  76. foreach ($this->_aImageFields as $sField => $aParams)
  77. $aValsToAdd[$sField] = 0; // we will update this field later
  78. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  79. }
  80. function delete ($iContentId, $aContentInfo = array())
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. $iProfileId = $this->getContentOwnerProfileId($iContentId);
  84. foreach ($this->_aImageFields as $sField => $aParams) {
  85. $oStorage = BxDolStorage::getObjectInstance($aParams['storage_object']);
  86. $aFiles = $oStorage->getGhosts($iProfileId, $iContentId);
  87. foreach ($aFiles as $aFile) {
  88. if (!$oStorage->getFile($aFile['id']))
  89. continue;
  90. $bRet = $oStorage->deleteFile($aFile['id'], $this->_iAccountProfileId);
  91. }
  92. }
  93. return parent::delete($iContentId, $aContentInfo);
  94. }
  95. protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')
  96. {
  97. $oStorage->updateGhostsContentId ($iFileId, $iProfileId, $iContentId);
  98. $this->_oModule->_oDb->updateContentPictureById($iContentId, 0/*$iProfileId*/, $iFileId, $sPictureField);
  99. }
  100. protected function _getPhotoGhostTmplVars($sField, $aContentInfo = array())
  101. {
  102. $CNF = &$this->_oModule->_oConfig->CNF;
  103. return array (
  104. 'name' => $this->aInputs[$sField]['name'],
  105. 'content_id' => $this->aInputs[$sField]['content_id'],
  106. 'bx_if:set_thumb' => array (
  107. 'condition' => false,
  108. 'content' => array (),
  109. ),
  110. );
  111. }
  112. }
  113. /** @} */