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 = array();
  42. $oProfile = false;
  43. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  44. if (!$aContentInfo)
  45. return array (false, false);
  46. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  47. if (!$oProfile)
  48. $oProfile = BxDolProfileUndefined::getInstance();
  49. return array ($oProfile, $aContentInfo);
  50. }
  51. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm)
  52. {
  53. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile, $oForm))
  54. return $s;
  55. $CNF = &$this->_oModule->_oConfig->CNF;
  56. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  57. return MsgBox(_t('_sys_txt_error_occured'));
  58. // change profile to 'pending' only if profile is 'active'
  59. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  60. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  61. // alert
  62. $this->_alertAfterEdit($aContentInfo);
  63. return '';
  64. }
  65. public function onDataAddAfter ($iAccountId, $iContentId)
  66. {
  67. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  68. return $s;
  69. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  70. return MsgBox(_t('_sys_txt_error_occured'));
  71. // alert
  72. $this->_alertAfterAdd($aContentInfo);
  73. return '';
  74. }
  75. protected function _alertAfterAdd($aContentInfo)
  76. {
  77. $CNF = &$this->_oModule->_oConfig->CNF;
  78. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  79. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  80. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  81. bx_alert($this->_oModule->getName(), 'added', $aContentInfo[$CNF['FIELD_ID']], false, $aParams);
  82. }
  83. protected function _alertAfterEdit($aContentInfo)
  84. {
  85. $CNF = &$this->_oModule->_oConfig->CNF;
  86. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  87. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  88. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  89. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']], false, $aParams);
  90. }
  91. }
  92. /** @} */