BxBaseModTextFormsEntryHelper.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 BaseText Base classes for text modules
  7. * @ingroup TridentModules
  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 main content text
  37. */
  38. public function viewDataEntry ($iContentId)
  39. {
  40. // get content data and profile info
  41. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  42. if (!$aContentInfo)
  43. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  44. // check access
  45. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  46. return MsgBox($sMsg);
  47. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  48. }
  49. /**
  50. * @return array of profile object and content info
  51. */
  52. protected function _getProfileAndContentData ($iContentId)
  53. {
  54. $CNF = &$this->_oModule->_oConfig->CNF;
  55. $aContentInfo = array();
  56. $oProfile = false;
  57. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  58. if (!$aContentInfo)
  59. return array (false, false);
  60. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  61. if (!$oProfile)
  62. $oProfile = BxDolProfileUndefined::getInstance();
  63. return array ($oProfile, $aContentInfo);
  64. }
  65. public function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  66. {
  67. if ($s = parent::onDataEditAfter($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile))
  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. // change profile to 'pending' only if profile is 'active'
  73. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  74. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  75. // create an alert
  76. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']], false, array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]));
  77. return '';
  78. }
  79. public function onDataAddAfter ($iAccountId, $iContentId)
  80. {
  81. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  82. return $s;
  83. $CNF = &$this->_oModule->_oConfig->CNF;
  84. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  85. return MsgBox(_t('_sys_txt_error_occured'));
  86. // alert
  87. $aParams = isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) : array();
  88. bx_alert($this->_oModule->getName(), 'added', $iContentId, false, $aParams);
  89. return '';
  90. }
  91. }
  92. /** @} */