BxSpacesModule.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. 'BrowseTopLevel' => '',
  27. ));
  28. }
  29. public function serviceEntityDelete ($iContentId = 0)
  30. {
  31. $iContentId = $this->_getContent($iContentId, false);
  32. if($iContentId === false)
  33. return false;
  34. $iCount = $this->_oDb->getCountEntriesByParent($iContentId);
  35. if($iCount > 0 && ($sMsg = '_bx_spaces_err_delete_child_presend'))
  36. return !$this->_bIsApi ? MsgBox(_t($sMsg)) : [bx_api_get_msg($sMsg)];
  37. $mixedResult = $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  38. if(!$this->_bIsApi)
  39. return $mixedResult;
  40. $aResult = [];
  41. if(is_a($mixedResult, 'BxTemplFormView'))
  42. $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]]]);
  43. else
  44. $aResult = $mixedResult;
  45. return [
  46. $aResult
  47. ];
  48. }
  49. public function serviceEntityParent ($iContentId = 0, $aParams = [])
  50. {
  51. return $this->_serviceTemplateFuncEx ('entryParent', $iContentId, $aParams);
  52. }
  53. public function serviceEntityChilds ($iContentId = 0, $aParams = [])
  54. {
  55. return $this->_serviceTemplateFuncEx ('entryChilds', $iContentId, $aParams);
  56. }
  57. /**
  58. * @page service Service Calls
  59. * @section bx_spaces Spaces
  60. * @subsection bx_spaces-page_blocks Page Blocks
  61. * @subsubsection bx_spaces-entity_rating entity_rating
  62. *
  63. * @code bx_srv('bx_spaces', 'entity_rating', [...]); @endcode
  64. *
  65. * Get page block with Stars based space's rating.
  66. *
  67. * @param $iContentId (optional) space's ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  68. * @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.
  69. *
  70. * @see BxSpacesModule::serviceEntityRating
  71. */
  72. /**
  73. * @ref bx_spaces-entity_rating "entity_rating"
  74. */
  75. public function serviceEntityRating($iContentId = 0)
  76. {
  77. return $this->_serviceTemplateFunc ('entryRating', $iContentId);
  78. }
  79. public function serviceBrowseTopLevel ($bDisplayEmptyMsg = false)
  80. {
  81. return $this->_serviceBrowse ('top_level', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  82. }
  83. /**
  84. * Get possible recipients for start conversation form
  85. */
  86. public function actionAjaxGetParentSpace ()
  87. {
  88. $sTerm = bx_get('term');
  89. $iContentId = bx_get('id');
  90. $a = $this->getListSpacesForParent($sTerm, $iContentId, 10);
  91. header('Content-Type:text/javascript; charset=utf-8');
  92. echo(json_encode($a));
  93. }
  94. public function getListSpacesForParent ($sTerm, $iContentId, $iLimit)
  95. {
  96. $CNF = &$this->_oConfig->CNF;
  97. if (!isLogged())
  98. return false;
  99. $iLevelsLimit = BX_SPS_LEVELS_LIMIT;
  100. if(getParam($CNF['PARAM_MULTILEVEL_HIERARCHY']) == 'on')
  101. $iLevelsLimit = 0;
  102. $aRv = array();
  103. $aTmp = $this->_oDb->searchByTermForParentSpace(bx_get_logged_profile_id(), $iContentId, $iLevelsLimit, $sTerm, $iLimit);
  104. foreach ($aTmp as $aSpace) {
  105. $oProfile = BxDolProfile::getInstance($aSpace['profile_id']);
  106. $aRv[] = array (
  107. 'label' => $this->serviceProfileName($aSpace['content_id']),
  108. 'value' => $aSpace['profile_id'],
  109. 'url' => $oProfile->getUrl(),
  110. 'thumb' => $oProfile->getThumb(),
  111. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  112. );
  113. }
  114. return $aRv;
  115. }
  116. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  117. {
  118. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  119. }
  120. }
  121. /** @} */