BxMessengerProfileMenuSnippetMeta.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. /**
  12. * For API only.
  13. */
  14. class BxMessengerProfileMenuSnippetMeta extends BxBaseModProfileMenuSnippetMeta
  15. {
  16. protected $_oModuleContent;
  17. public function __construct($aObject, $oTemplate = false)
  18. {
  19. $this->_sModule = 'bx_messenger';
  20. parent::__construct($aObject, $oTemplate);
  21. }
  22. protected function _getMenuItemMessage($aItem)
  23. {
  24. $CNF = &$this->_oModule->_oConfig->CNF;
  25. if(bx_is_api()) {
  26. $aProfile = BxDolProfileQuery::getInstance()->getProfileByContentAndType($this->_iContentId, $this->_oModuleContent->getName());
  27. if(empty($aProfile) || !is_array($aProfile))
  28. return [];
  29. $aParticipants = [bx_get_logged_profile_id(), $aProfile['id']];
  30. $aLot = $this->_oModule->_oDb->findLotByParams([
  31. $CNF['FIELD_PARTICIPANTS'] => $aParticipants,
  32. $CNF['FIELD_TYPE'] => BX_IM_TYPE_PRIVATE
  33. ]);
  34. if(empty($aLot) || !is_array($aLot)) {
  35. $aResult = $this->_oModule->saveParticipantsList($aParticipants);
  36. if(!isset($aResult['lot']))
  37. return [];
  38. $aLot = $this->_oModule->_oDb->getLotInfoById($aResult['lot']);
  39. if(empty($aLot) || !is_array($aLot))
  40. return [];
  41. }
  42. return $this->_getMenuItemAPI($aItem, 'text', [
  43. 'title' => _t($aItem['title']),
  44. 'link' => bx_api_get_relative_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']) . '/inbox/' . $aLot['hash']),
  45. 'display_type' => 'button',
  46. 'emulate' => true
  47. ]);
  48. }
  49. return $this->_getMenuItem($aItem);
  50. }
  51. public function setContentModule($sModule = ''){
  52. if ($sModule)
  53. $this->_oModuleContent = BxDolModule::getInstance($sModule);
  54. }
  55. public function setContentId($iContentId)
  56. {
  57. $this->_iContentId = (int)$iContentId;
  58. if(!empty($this->_iContentId)) {
  59. $this->_aContentInfo = $this->_getContentInfo($this->_iContentId);
  60. $this->addMarkers(array(
  61. 'content_id' => $this->_iContentId,
  62. 'profile_id' => $this->_aContentInfo[$this->_oModuleContent->_oConfig->CNF['FIELD_AUTHOR']]
  63. ));
  64. }
  65. }
  66. protected function _getContentInfo($iContentId)
  67. {
  68. return !empty($this->_oModuleContent) && method_exists($this->_oModuleContent->_oDb, 'getContentInfoById') ? $this->_oModuleContent->_oDb->getContentInfoById($iContentId) : array();
  69. }
  70. }
  71. /** @} */