BxCnvFormsEntryHelper.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Convos Convos
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry forms helper functions
  13. */
  14. class BxCnvFormsEntryHelper extends BxBaseModTextFormsEntryHelper
  15. {
  16. public function __construct($oModule)
  17. {
  18. parent::__construct($oModule);
  19. }
  20. public function deleteData ($iContentId, $aContentInfo = false, $oProfile = null, $oForm = null)
  21. {
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. if ($sErrorMsg = $this->_oModule->deleteConvoForever ($iContentId))
  24. return $sErrorMsg;
  25. if ($sResult = $this->onDataDeleteAfter ($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $oProfile))
  26. return $sResult;
  27. // create an alert
  28. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
  29. return '';
  30. }
  31. public function onDataAddAfter ($iAccountId, $iContentId)
  32. {
  33. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  34. return $s;
  35. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  36. return MsgBox(_t('_sys_txt_error_occured'));
  37. $CNF = $this->_oModule->_oConfig->CNF;
  38. // send notification to all collaborators
  39. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  40. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  41. foreach ($aCollaborators as $iCollaborator => $iReadComments) {
  42. if ($iCollaborator == $oProfile->id())
  43. continue;
  44. sendMailTemplate('bx_cnv_new_message', 0, $iCollaborator, array(
  45. 'SenderDisplayName' => $oProfile->getDisplayName(),
  46. 'SenderUrl' => $oProfile->getUrl(),
  47. 'Message' => $aContentInfo[$CNF['FIELD_TEXT']],
  48. 'PageUrl' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  49. 'PageTitle' => strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 100),
  50. ), BX_EMAIL_NOTIFY);
  51. }
  52. return '';
  53. }
  54. protected function _getProfileAndContentData ($iContentId)
  55. {
  56. $CNF = &$this->_oModule->_oConfig->CNF;
  57. list ($oProfile, $aContentInfo) = parent::_getProfileAndContentData($iContentId);
  58. if (!$aContentInfo)
  59. return array($oProfile, $aContentInfo);
  60. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  61. if ($aCollaborators)
  62. $aContentInfo['recipients'] = array_keys($aCollaborators);
  63. return array($oProfile, $aContentInfo);
  64. }
  65. }
  66. /** @} */