1
0

BxBaseModTextFormsEntryHelper.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_FILE']))
  57. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, false);
  58. if (isset($CNF['FIELD_POLL']))
  59. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  60. // change profile to 'pending' only if profile is 'active'
  61. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  62. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  63. return '';
  64. }
  65. public function onDataAddAfter ($iAccountId, $iContentId)
  66. {
  67. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  68. return $s;
  69. $CNF = &$this->_oModule->_oConfig->CNF;
  70. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  71. return MsgBox(_t('_sys_txt_error_occured'));
  72. if(($oForm = $this->getObjectFormAdd()) !== false) {
  73. if (isset($CNF['FIELD_VIDEO']))
  74. $oForm->processFiles($CNF['FIELD_VIDEO'], $iContentId, true);
  75. if (isset($CNF['FIELD_FILE']))
  76. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, true);
  77. if (isset($CNF['FIELD_POLL']))
  78. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  79. }
  80. return '';
  81. }
  82. public function onDataDeleteAfter($iContentId, $aContentInfo, $oProfile)
  83. {
  84. $sResult = parent::onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile);
  85. if(!empty($sResult))
  86. return $sResult;
  87. $this->_oModule->_oDb->deletePolls(array('content_id' => $iContentId));
  88. BxDolCategories::getInstance()->delete($this->_oModule->getName(), $iContentId);
  89. return '';
  90. }
  91. }
  92. /** @} */