BxBaseModTextFormsEntryHelper.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. if (isset($CNF['FIELD_VIDEO']))
  59. $oForm->processFiles($CNF['FIELD_VIDEO'], $iContentId, false);
  60. if (isset($CNF['FIELD_FILE']))
  61. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, false);
  62. if (isset($CNF['FIELD_POLL']))
  63. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  64. // change profile to 'pending' only if profile is 'active'
  65. if ($oProfile->isActive() && !empty($aTrackTextFieldsChanges['changed_fields']))
  66. $oProfile->disapprove(BX_PROFILE_ACTION_AUTO);
  67. // alert
  68. $this->_alertAfterEdit($aContentInfo);
  69. return '';
  70. }
  71. public function onDataAddAfter ($iAccountId, $iContentId)
  72. {
  73. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  74. return $s;
  75. $CNF = &$this->_oModule->_oConfig->CNF;
  76. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  77. return MsgBox(_t('_sys_txt_error_occured'));
  78. if(($oForm = $this->getObjectFormAdd()) !== false) {
  79. if (isset($CNF['FIELD_VIDEO']))
  80. $oForm->processFiles($CNF['FIELD_VIDEO'], $iContentId, true);
  81. if (isset($CNF['FIELD_FILE']))
  82. $oForm->processFiles($CNF['FIELD_FILE'], $iContentId, true);
  83. if (isset($CNF['FIELD_POLL']))
  84. $oForm->processPolls($CNF['FIELD_POLL'], $iContentId);
  85. }
  86. // alert
  87. $this->_alertAfterAdd($aContentInfo);
  88. return '';
  89. }
  90. public function onDataDeleteAfter($iContentId, $aContentInfo, $oProfile)
  91. {
  92. $sResult = parent::onDataDeleteAfter ($iContentId, $aContentInfo, $oProfile);
  93. if(!empty($sResult))
  94. return $sResult;
  95. $this->_oModule->_oDb->deletePolls(array('content_id' => $iContentId));
  96. return '';
  97. }
  98. protected function _alertAfterAdd($aContentInfo)
  99. {
  100. $CNF = &$this->_oModule->_oConfig->CNF;
  101. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  102. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  103. $aParams = array('object_author_id' => $iAuthorId);
  104. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  105. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  106. if(!empty($CNF['OBJECT_METATAGS']))
  107. $aParams['timeline_group'] = array(
  108. 'by' => $this->_oModule->_oConfig->getName() . '_' . $iAuthorId . '_' . $iId,
  109. 'field' => 'owner_id'
  110. );
  111. $sAction = 'added';
  112. if(isset($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]) && $aContentInfo[$CNF['FIELD_STATUS']] == 'awaiting')
  113. $sAction = 'scheduled';
  114. bx_alert($this->_oModule->getName(), $sAction, $iId, $iAuthorId, $aParams);
  115. }
  116. protected function _alertAfterEdit($aContentInfo)
  117. {
  118. $CNF = &$this->_oModule->_oConfig->CNF;
  119. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  120. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  121. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  122. bx_alert($this->_oModule->getName(), 'edited', $aContentInfo[$CNF['FIELD_ID']], false, $aParams);
  123. }
  124. }
  125. /** @} */