BxBaseModTextFormsEntryHelper.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. /**
  21. * @return main content text
  22. */
  23. public function viewDataText ($iContentId)
  24. {
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. // get content data and profile info
  27. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  28. if (!$aContentInfo)
  29. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  30. // check access
  31. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  32. return MsgBox($sMsg);
  33. return $aContentInfo[$CNF['FIELD_TEXT']];
  34. }
  35. /**
  36. * @return array of profile object and content info
  37. */
  38. protected function _getProfileAndContentData ($iContentId)
  39. {
  40. $CNF = &$this->_oModule->_oConfig->CNF;
  41. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  42. if(!$aContentInfo)
  43. return array(false, false);
  44. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo[$CNF['FIELD_AUTHOR']]);
  45. return array($oProfile, $aContentInfo);
  46. }
  47. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  48. {
  49. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  50. return $s;
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  53. return MsgBox(_t('_sys_txt_error_occured'));
  54. if (isset($CNF['FIELD_VIDEO']))
  55. $oForm->processFiles($CNF['FIELD_VIDEO'], $iContentId, false);
  56. if (isset($CNF['FIELD_SOUND']))
  57. $oForm->processFiles($CNF['FIELD_SOUND'], $iContentId, false);
  58. if (isset($CNF['FIELD_FILE']))
  59. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, false);
  60. if (isset($CNF['FIELD_POLL']))
  61. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  62. // change profile to 'pending' only if profile is 'active'
  63. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  64. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  65. return '';
  66. }
  67. public function onDataAddAfter ($iAccountId, $iContentId)
  68. {
  69. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  70. return $s;
  71. $CNF = &$this->_oModule->_oConfig->CNF;
  72. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  73. return MsgBox(_t('_sys_txt_error_occured'));
  74. if(($oForm = $this->getObjectFormAdd()) !== false) {
  75. if (isset($CNF['FIELD_VIDEO']))
  76. $oForm->processFiles($CNF['FIELD_VIDEO'], $iContentId, true);
  77. if (isset($CNF['FIELD_SOUND']))
  78. $oForm->processFiles($CNF['FIELD_SOUND'], $iContentId, true);
  79. if (isset($CNF['FIELD_FILE']))
  80. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, true);
  81. if (isset($CNF['FIELD_POLL']))
  82. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  83. }
  84. return '';
  85. }
  86. public function onDataDeleteAfter($iContentId, $aContentInfo, $oProfile)
  87. {
  88. $sResult = parent::onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile);
  89. if(!empty($sResult))
  90. return $sResult;
  91. $this->_oModule->_oDb->deletePolls(array('content_id' => $iContentId));
  92. BxDolCategories::getInstance()->delete($this->_oModule->getName(), $iContentId);
  93. return '';
  94. }
  95. }
  96. /** @} */