BxBaseModTextFormsEntryHelper.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. bx_import('BxBaseModGeneralFormsEntryHelper');
  12. bx_import('BxDolProfile');
  13. /**
  14. * Entry forms helper functions
  15. */
  16. class BxBaseModTextFormsEntryHelper extends BxBaseModGeneralFormsEntryHelper
  17. {
  18. public function __construct($oModule)
  19. {
  20. parent::__construct($oModule);
  21. }
  22. /**
  23. * @return main content text
  24. */
  25. public function viewDataText ($iContentId)
  26. {
  27. $CNF = &$this->_oModule->_oConfig->CNF;
  28. // get content data and profile info
  29. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  30. if (!$aContentInfo)
  31. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  32. // check access
  33. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  34. return MsgBox($sMsg);
  35. return $aContentInfo[$CNF['FIELD_TEXT']];
  36. }
  37. /**
  38. * @return main content text
  39. */
  40. public function viewDataEntry ($iContentId)
  41. {
  42. // get content data and profile info
  43. list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
  44. if (!$aContentInfo)
  45. return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
  46. // check access
  47. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
  48. return MsgBox($sMsg);
  49. return $this->_oModule->_oTemplate->entryText($aContentInfo);
  50. }
  51. /**
  52. * @return array of profile object and content info
  53. */
  54. protected function _getProfileAndContentData ($iContentId)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. $aContentInfo = array();
  58. $oProfile = false;
  59. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  60. if (!$aContentInfo)
  61. return array (false, false);
  62. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  63. if (!$oProfile) {
  64. bx_import('BxDolProfileUndefined');
  65. $oProfile = BxDolProfileUndefined::getInstance();
  66. }
  67. return array ($oProfile, $aContentInfo);
  68. }
  69. protected function onDataEditAfter ($iContentId, $aContentInfo, $aTrackTextFieldsChanges, $oProfile)
  70. {
  71. $CNF = &$this->_oModule->_oConfig->CNF;
  72. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  73. return MsgBox(_t('_sys_txt_error_occured'));
  74. // change profile to 'pending' only if profile is 'active'
  75. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  76. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  77. // create an alert
  78. bx_import('BxDolPrivacy');
  79. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']], false, array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]));
  80. return '';
  81. }
  82. protected function onDataAddAfter ($iContentId)
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  86. return MsgBox(_t('_sys_txt_error_occured'));
  87. // alert
  88. bx_import('BxDolPrivacy');
  89. $aParams = isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? array('privacy_view' => $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) : array();
  90. bx_alert($this->_oModule->getName(), 'added', $iContentId, false, $aParams);
  91. return '';
  92. }
  93. }
  94. /** @} */