BxSpacesModule.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 Spaces Spaces
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Spaces profiles module.
  13. */
  14. define('BX_SPS_LEVELS_LIMIT', 1);
  15. class BxSpacesModule extends BxBaseModGroupsModule
  16. {
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $this->_aSearchableNamesExcept[] = $this->_oConfig->CNF['FIELD_JOIN_CONFIRMATION'];
  21. }
  22. public function serviceGetSafeServices()
  23. {
  24. $a = parent::serviceGetSafeServices();
  25. return array_merge($a, array (
  26. 'AjaxGetParentSpace' => '',
  27. 'BrowseTopLevel' => '',
  28. ));
  29. }
  30. public function serviceEntityDelete ($iContentId = 0)
  31. {
  32. $iContentId = $this->_getContent($iContentId, false);
  33. if($iContentId === false)
  34. return false;
  35. $iCount = $this->_oDb->getCountEntriesByParent($iContentId);
  36. if($iCount > 0 && ($sMsg = '_bx_spaces_err_delete_child_presend'))
  37. return !$this->_bIsApi ? MsgBox(_t($sMsg)) : [bx_api_get_msg($sMsg)];
  38. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  39. if(!$this->_bIsApi)
  40. return $mixedResult;
  41. $aResult = [];
  42. if(is_a($mixedResult, 'BxTemplFormView'))
  43. $aResult = bx_api_get_block('form', $mixedResult->getCodeAPI(), ['ext' => ['name' => $this->getName(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_delete&params[]=' . $iContentId . '&params[]=' . $mixedResult->aParams['display'], 'immutable' => true]]]);
  44. else
  45. $aResult = $mixedResult;
  46. return [
  47. $aResult
  48. ];
  49. }
  50. public function serviceEntityParent ($iContentId = 0, $aParams = [])
  51. {
  52. return $this->_serviceTemplateFuncEx ('entryParent', $iContentId, $aParams);
  53. }
  54. public function serviceEntityChilds ($iContentId = 0, $aParams = [])
  55. {
  56. return $this->_serviceTemplateFuncEx ('entryChilds', $iContentId, $aParams);
  57. }
  58. /**
  59. * @page service Service Calls
  60. * @section bx_spaces Spaces
  61. * @subsection bx_spaces-page_blocks Page Blocks
  62. * @subsubsection bx_spaces-entity_rating entity_rating
  63. *
  64. * @code bx_srv('bx_spaces', 'entity_rating', [...]); @endcode
  65. *
  66. * Get page block with Stars based space's rating.
  67. *
  68. * @param $iContentId (optional) space's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  69. * @return HTML string with block content to display on the site or false if there is no enough input data. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  70. *
  71. * @see BxSpacesModule::serviceEntityRating
  72. */
  73. /**
  74. * @ref bx_spaces-entity_rating "entity_rating"
  75. */
  76. public function serviceEntityRating($iContentId = 0)
  77. {
  78. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  79. }
  80. public function serviceBrowseTopLevel ($bDisplayEmptyMsg = false)
  81. {
  82. return $this->_serviceBrowse ('top_level', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  83. }
  84. /**
  85. * Get possible recipients for start conversation form
  86. */
  87. public function actionAjaxGetParentSpace ()
  88. {
  89. $sTerm = bx_get('term');
  90. $iContentId = bx_get('id');
  91. $a = $this->getListSpacesForParent($sTerm, $iContentId, 10);
  92. header('Content-Type:text/javascript; charset=utf-8');
  93. echo(json_encode($a));
  94. }
  95. public function serviceAjaxGetParentSpace ($iContentId, $mixedParams)
  96. {
  97. if(!$mixedParams)
  98. return [];
  99. $aParams = is_array($mixedParams) ? $mixedParams : json_decode($mixedParams, true);
  100. if(!isset($aParams['term']))
  101. return [];
  102. return $this->getListSpacesForParent($aParams['term'], $iContentId, 10);
  103. }
  104. public function getListSpacesForParent ($sTerm, $iContentId, $iLimit)
  105. {
  106. $CNF = &$this->_oConfig->CNF;
  107. if (!isLogged())
  108. return false;
  109. $iLevelsLimit = BX_SPS_LEVELS_LIMIT;
  110. if(getParam($CNF['PARAM_MULTILEVEL_HIERARCHY']) == 'on')
  111. $iLevelsLimit = 0;
  112. $aRv = array();
  113. $aTmp = $this->_oDb->searchByTermForParentSpace(bx_get_logged_profile_id(), $iContentId, $iLevelsLimit, $sTerm, $iLimit);
  114. foreach ($aTmp as $aSpace) {
  115. $oProfile = BxDolProfile::getInstance($aSpace['profile_id']);
  116. if(!$oProfile)
  117. continue;
  118. if ($this->_bIsApi)
  119. $aRv[] = array_merge(BxDolProfile::getData($oProfile), [
  120. 'label' => $oProfile->getDisplayName()
  121. ]);
  122. else
  123. $aRv[] = array (
  124. 'label' => $this->serviceProfileName($aSpace['content_id']),
  125. 'value' => $aSpace['profile_id'],
  126. 'url' => $oProfile->getUrl(),
  127. 'thumb' => $oProfile->getThumb(),
  128. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  129. );
  130. }
  131. return $aRv;
  132. }
  133. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  134. {
  135. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  136. }
  137. }
  138. /** @} */