1
0

BxCnvFormsEntryHelper.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /**
  28. * @hooks
  29. * @hookdef hook-bx_convos-deleted 'bx_convos', 'deleted' - hook on delete conversation
  30. * - $unit_name - equals `bx_convos`
  31. * - $action - equals `deleted`
  32. * - $object_id - conversation id
  33. * @hook @ref hook-bx_convos-deleted
  34. */
  35. bx_alert($this->_oModule->getName(), 'deleted', $aContentInfo[$CNF['FIELD_ID']]);
  36. return '';
  37. }
  38. public function onDataAddAfter ($iAccountId, $iContentId)
  39. {
  40. if ($s = parent::onDataAddAfter($iAccountId, $iContentId))
  41. return $s;
  42. if (!($aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId)))
  43. return MsgBox(_t('_sys_txt_error_occured'));
  44. $CNF = $this->_oModule->_oConfig->CNF;
  45. // send notification to all collaborators
  46. $oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
  47. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  48. foreach ($aCollaborators as $iCollaborator => $iReadComments) {
  49. if ($iCollaborator == $oProfile->id())
  50. continue;
  51. sendMailTemplate('bx_cnv_new_message', 0, $iCollaborator, array(
  52. 'SenderDisplayName' => $oProfile->getDisplayName(),
  53. 'SenderUrl' => $oProfile->getUrl(),
  54. 'Message' => $aContentInfo[$CNF['FIELD_TEXT']],
  55. 'PageUrl' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  56. 'PageTitle' => strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 100),
  57. ), BX_EMAIL_NOTIFY);
  58. }
  59. return '';
  60. }
  61. protected function _getProfileAndContentData ($iContentId)
  62. {
  63. $CNF = &$this->_oModule->_oConfig->CNF;
  64. list ($oProfile, $aContentInfo) = parent::_getProfileAndContentData($iContentId);
  65. if (!$aContentInfo)
  66. return array($oProfile, $aContentInfo);
  67. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  68. if ($aCollaborators)
  69. $aContentInfo['recipients'] = array_keys($aCollaborators);
  70. return array($oProfile, $aContentInfo);
  71. }
  72. }
  73. /** @} */