BxCnvFormsEntryHelper.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Convos Convos
  7. * @ingroup TridentModules
  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. // send notification to all collaborators
  38. $oProfile = BxDolProfile::getInstance($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_AUTHOR']]);
  39. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ID']]);
  40. foreach ($aCollaborators as $iCollaborator => $iReadComments) {
  41. if ($iCollaborator == $oProfile->id())
  42. continue;
  43. sendMailTemplate('bx_cnv_new_message', 0, $iCollaborator, array(
  44. 'SenderDisplayName' => $oProfile->getDisplayName(),
  45. 'SenderUrl' => $oProfile->getUrl(),
  46. 'Message' => $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_TEXT']],
  47. ), BX_EMAIL_NOTIFY);
  48. }
  49. return '';
  50. }
  51. protected function _getProfileAndContentData ($iContentId)
  52. {
  53. $CNF = &$this->_oModule->_oConfig->CNF;
  54. list ($oProfile, $aContentInfo) = parent::_getProfileAndContentData($iContentId);
  55. if (!$aContentInfo)
  56. return array($oProfile, $aContentInfo);
  57. $aCollaborators = $this->_oModule->_oDb->getCollaborators($aContentInfo[$CNF['FIELD_ID']]);
  58. if ($aCollaborators)
  59. $aContentInfo['recipients'] = array_keys($aCollaborators);
  60. return array($oProfile, $aContentInfo);
  61. }
  62. }
  63. /** @} */