BxCnlAlertsResponse.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. * @defdroup Channels Channels
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCnlAlertsResponse extends BxBaseModGroupsAlertsResponse
  12. {
  13. public function __construct()
  14. {
  15. $this->MODULE = 'bx_channels';
  16. parent::__construct();
  17. }
  18. public function response($oAlert)
  19. {
  20. parent::response($oAlert);
  21. $CNF = $this->_oModule->_oConfig->CNF;
  22. $sMethod = '_process' . bx_gen_method_name($oAlert->sUnit . '_' . $oAlert->sAction);
  23. if(method_exists($this, $sMethod))
  24. return $this->$sMethod($oAlert);
  25. $aProfileModulesAutofollowLabels = array('bx_persons', 'bx_organizations');
  26. if (in_array($oAlert->sUnit, $aProfileModulesAutofollowLabels) && in_array($oAlert->sAction, array('added', 'edited'))) {
  27. $this->_oModule->followLabels($oAlert->sUnit, $oAlert->iObject);
  28. }
  29. if ($oAlert->sUnit == 'meta_keyword' && $oAlert->sAction == 'added') {
  30. if (isset($oAlert->aExtras['meta']) && isset($oAlert->aExtras['object'])) {
  31. /*
  32. * TODO: $oAlert->aExtras['object'] - contains Metatags object name but further it's used as Module name.
  33. * It's working correctly while Metatags object name is equal to Module name.
  34. * This should be changed in Ticket #1596
  35. *
  36. * Also there is a problem that only Content's Author ID is saved, but further it's used to check visibility
  37. * in case of Context. So, it works correctly when Author posts something with tags in his own profile,
  38. * but will work incorrecly when Author posts something with tags in some Context (group, event, etc).
  39. * In this case system will use Author's profile as context instead of the real Context
  40. * in which the content was posted.
  41. */
  42. $this->_oModule->processHashtag($oAlert->aExtras['meta'], $oAlert->aExtras['object'], $oAlert->iObject, $oAlert->iSender);
  43. }
  44. }
  45. if ($oAlert->sUnit == 'meta_keyword' && $oAlert->sAction == 'url'){
  46. if (isset($oAlert->aExtras['keyword'])){
  47. $sName = $oAlert->aExtras['keyword'];
  48. $iCnlId = $this->_oModule->_oDb->getChannelIdByName($sName);
  49. if ($iCnlId > 0) {
  50. $aContentInfo = $this->_oModule->_oDb->getContentInfoById($iCnlId);
  51. if($aContentInfo[$CNF['FIELD_STATUS']] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_ACTIVE)
  52. $oAlert->aExtras['url'] = $this->_oModule->serviceProfileUrl($iCnlId);
  53. }
  54. }
  55. }
  56. if ($oAlert->sUnit == 'meta_keyword' && $oAlert->sAction == 'deleted'){
  57. if (isset($oAlert->aExtras['object']) && isset($oAlert->iObject) && isset($oAlert->iSender)){
  58. $this->_oModule->removeContentFromChannel($oAlert->iObject, $oAlert->aExtras['object']);
  59. }
  60. }
  61. }
  62. protected function _processSystemSaveSetting($oAlert)
  63. {
  64. $CNF = $this->_oModule->_oConfig->CNF;
  65. switch($oAlert->aExtras['option']) {
  66. case $CNF['PARAM_DEFAULT_AUTHOR']:
  67. $bChanged = $oAlert->aExtras['value'] != $oAlert->aExtras['value_prior'];
  68. if($bChanged) {
  69. $oStudioWidget = new BxTemplStudioWidgets($this->MODULE);
  70. if($oStudioWidget)
  71. $oStudioWidget->updateCache();
  72. }
  73. if(empty($oAlert->aExtras['value']) || !$bChanged)
  74. break;
  75. $aSet = array($CNF['FIELD_AUTHOR'] => (int)$oAlert->aExtras['value']);
  76. $this->_oModule->_oDb->updateEntriesBy($aSet, array($CNF['FIELD_AUTHOR'] => (int)$oAlert->aExtras['value_prior']));
  77. $aOperators = BxDolAccountQuery::getInstance()->getOperators();
  78. if(count($aOperators) > 0)
  79. $this->_oModule->_oDb->updateEntriesBy($aSet, array($CNF['FIELD_AUTHOR'] => BxDolProfile::getInstanceByAccount(array_shift($aOperators))->id()));
  80. break;
  81. }
  82. }
  83. }
  84. /** @} */